|
| 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 |
0 commit comments