Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 42d4a60

Browse files
committed
Add VirtualControll module
1 parent 2252794 commit 42d4a60

5 files changed

Lines changed: 136 additions & 2 deletions

File tree

tests/xmlconfig-xml/boot-many-devices.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
<source file='/default-pool/testvol1.img'/>
3939
<target dev='sdb' bus='scsi'/>
4040
</disk>
41+
<controller type='ide' index='3'/>
42+
<controller type='virtio-serial' index='0' ports='32' vectors='17'/>
4143
<interface type='network'>
4244
<source network='default'/>
4345
<mac address='11:22:33:44:55:66'/>

tests/xmlconfig.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from virtinst import VirtualHostDeviceUSB, VirtualHostDevicePCI
2727
from virtinst import VirtualCharDevice
2828
from virtinst import VirtualVideoDevice
29+
from virtinst import VirtualController
2930
import tests
3031

3132
conn = tests.open_testdriver()
@@ -629,6 +630,15 @@ def testManyDevices(self):
629630
bus="scsi", driverName="qemu")
630631
g.disks.append(d3)
631632

633+
# Controller devices
634+
c1 = VirtualController.get_class_for_type(VirtualController.CONTROLLER_TYPE_IDE)(g.conn)
635+
c1.index = "3"
636+
c2 = VirtualController.get_class_for_type(VirtualController.CONTROLLER_TYPE_VIRTIOSERIAL)(g.conn)
637+
c2.ports = "32"
638+
c2.vectors = "17"
639+
g.add_device(c1)
640+
g.add_device(c2)
641+
632642
# Network devices
633643
net1 = get_virtual_network()
634644
net1.model = "e1000"

virtinst/VirtualController.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#
2+
# Copyright 2010 Red Hat, Inc.
3+
# Cole Robinson <crobinso@redhat.com>
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation; either version 2 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program; if not, write to the Free Software
17+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18+
# MA 02110-1301 USA.
19+
20+
import VirtualDevice
21+
#from virtinst import _virtinst as _
22+
23+
class VirtualController(VirtualDevice.VirtualDevice):
24+
25+
_virtual_device_type = VirtualDevice.VirtualDevice.VIRTUAL_DEV_CONTROLLER
26+
27+
CONTROLLER_TYPE_IDE = "ide"
28+
CONTROLLER_TYPE_FDC = "fdc"
29+
CONTROLLER_TYPE_SCSI = "scsi"
30+
CONTROLLER_TYPE_SATA = "sata"
31+
CONTROLLER_TYPE_VIRTIOSERIAL = "virtio-serial"
32+
CONTROLLER_TYPES = [CONTROLLER_TYPE_IDE, CONTROLLER_TYPE_FDC,
33+
CONTROLLER_TYPE_SCSI, CONTROLLER_TYPE_SATA,
34+
CONTROLLER_TYPE_VIRTIOSERIAL ]
35+
36+
@staticmethod
37+
def get_class_for_type(ctype):
38+
if ctype not in VirtualController.CONTROLLER_TYPES:
39+
raise ValueError("Unknown controller type '%s'" % ctype)
40+
41+
if ctype == VirtualController.CONTROLLER_TYPE_IDE:
42+
return VirtualControllerIDE
43+
elif ctype == VirtualController.CONTROLLER_TYPE_FDC:
44+
return VirtualControllerFDC
45+
elif ctype == VirtualController.CONTROLLER_TYPE_SCSI:
46+
return VirtualControllerSCSI
47+
elif ctype == VirtualController.CONTROLLER_TYPE_SATA:
48+
return VirtualControllerSATA
49+
elif ctype == VirtualController.CONTROLLER_TYPE_VIRTIOSERIAL:
50+
return VirtualControllerVirtioSerial
51+
52+
_controller_type = None
53+
54+
def __init__(self, conn):
55+
VirtualDevice.VirtualDevice.__init__(self, conn)
56+
57+
self._index = 0
58+
59+
def get_type(self):
60+
return self._controller_type
61+
type = property(get_type)
62+
63+
def get_index(self):
64+
return self._index
65+
def set_index(self, val):
66+
self._index = int(val)
67+
index = property(get_index, set_index)
68+
69+
def _extra_config(self):
70+
return ""
71+
72+
def get_xml_config(self):
73+
extra = self._extra_config()
74+
75+
xml = " <controller type='%s' index='%s'" % (self.type, self.index)
76+
xml += extra
77+
xml += "/>"
78+
79+
return xml
80+
81+
82+
class VirtualControllerIDE(VirtualController):
83+
_controller_type = VirtualController.CONTROLLER_TYPE_IDE
84+
85+
class VirtualControllerFDC(VirtualController):
86+
_controller_type = VirtualController.CONTROLLER_TYPE_FDC
87+
88+
class VirtualControllerSCSI(VirtualController):
89+
_controller_type = VirtualController.CONTROLLER_TYPE_SCSI
90+
91+
class VirtualControllerSATA(VirtualController):
92+
_controller_type = VirtualController.CONTROLLER_TYPE_SATA
93+
94+
class VirtualControllerVirtioSerial(VirtualController):
95+
_controller_type = VirtualController.CONTROLLER_TYPE_VIRTIOSERIAL
96+
_ports = 0
97+
_vectors = 0
98+
99+
def get_vectors(self):
100+
return self._vectors
101+
def set_vectors(self, val):
102+
self._vectors = val
103+
vectors = property(get_vectors, set_vectors)
104+
105+
def get_ports(self):
106+
return self._ports
107+
def set_ports(self, val):
108+
self._ports = val
109+
ports = property(get_ports, set_ports)
110+
111+
def _extra_config(self):
112+
xml = ""
113+
if self.ports != None:
114+
xml += " ports='%s'" % self.ports
115+
if self.vectors != None:
116+
xml += " vectors='%s'" % self.vectors
117+
118+
return xml

virtinst/VirtualDevice.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ class VirtualDevice(object):
4040
VIRTUAL_DEV_PARALLEL = "parallel"
4141
VIRTUAL_DEV_CONSOLE = "console"
4242
VIRTUAL_DEV_VIDEO = "video"
43+
VIRTUAL_DEV_CONTROLLER = "controller"
4344

4445
# Ordering in this list is important: it will be the order the
4546
# Guest class outputs XML. So changing this may upset the test suite
46-
virtual_device_types = [VIRTUAL_DEV_DISK, VIRTUAL_DEV_NET,
47+
virtual_device_types = [VIRTUAL_DEV_DISK, VIRTUAL_DEV_CONTROLLER,
48+
VIRTUAL_DEV_NET,
4749
VIRTUAL_DEV_INPUT, VIRTUAL_DEV_GRAPHICS,
4850
VIRTUAL_DEV_SERIAL, VIRTUAL_DEV_PARALLEL,
4951
VIRTUAL_DEV_CONSOLE, VIRTUAL_DEV_AUDIO,

virtinst/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def _virtinst(msg):
4141
VirtualHostDevicePCI)
4242
from VirtualCharDevice import VirtualCharDevice
4343
from VirtualVideoDevice import VirtualVideoDevice
44+
from VirtualController import VirtualController
4445
from FullVirtGuest import FullVirtGuest
4546
from ParaVirtGuest import ParaVirtGuest
4647
from DistroInstaller import DistroInstaller
@@ -65,4 +66,5 @@ def _virtinst(msg):
6566
"Storage", "Interface",
6667
"User", "util", "support", "VirtualDevice", "Clock", "Seclabel",
6768
"VirtualHostDevice", "VirtualHostDeviceUSB", "VirtualVideoDevice",
68-
"VirtualHostDevicePCI", "VirtualCharDevice", "VirtualInputDevice"]
69+
"VirtualHostDevicePCI", "VirtualCharDevice", "VirtualInputDevice",
70+
"VirtualController"]

0 commit comments

Comments
 (0)