2013-03-18 01:06:52 +04:00
#
2014-02-12 13:39:32 +04:00
# Copyright 2010, 2013, 2014 Red Hat, Inc.
2013-03-18 01:06:52 +04:00
# Cole Robinson <crobinso@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
2013-10-28 00:59:47 +04:00
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
2013-03-18 01:06:52 +04:00
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
2014-09-12 23:59:22 +04:00
from . device import VirtualDevice
from . xmlbuilder import XMLProperty
2013-03-18 01:06:52 +04:00
2013-04-13 22:34:52 +04:00
2013-04-11 03:48:07 +04:00
class VirtualController ( VirtualDevice ) :
2013-07-16 17:14:37 +04:00
virtual_device_type = VirtualDevice . VIRTUAL_DEV_CONTROLLER
2013-03-18 01:06:52 +04:00
2013-07-16 05:52:18 +04:00
TYPE_IDE = " ide "
TYPE_FDC = " fdc "
TYPE_SCSI = " scsi "
TYPE_SATA = " sata "
TYPE_VIRTIOSERIAL = " virtio-serial "
TYPE_USB = " usb "
TYPE_PCI = " pci "
TYPE_CCID = " ccid "
TYPES = [ TYPE_IDE , TYPE_FDC ,
TYPE_SCSI , TYPE_SATA ,
TYPE_VIRTIOSERIAL , TYPE_USB ,
TYPE_PCI , TYPE_CCID ]
2013-03-18 01:06:52 +04:00
@staticmethod
def pretty_type ( ctype ) :
pretty_mappings = {
2013-07-16 05:52:18 +04:00
VirtualController . TYPE_IDE : " IDE " ,
2015-09-23 23:28:46 +03:00
VirtualController . TYPE_FDC : _ ( " Floppy " ) ,
2013-07-16 05:52:18 +04:00
VirtualController . TYPE_SCSI : " SCSI " ,
VirtualController . TYPE_SATA : " SATA " ,
2014-02-12 13:39:32 +04:00
VirtualController . TYPE_VIRTIOSERIAL : " VirtIO Serial " ,
2013-07-16 05:52:18 +04:00
VirtualController . TYPE_USB : " USB " ,
VirtualController . TYPE_PCI : " PCI " ,
VirtualController . TYPE_CCID : " CCID " ,
2013-04-13 22:34:52 +04:00
}
2013-03-18 01:06:52 +04:00
if ctype not in pretty_mappings :
return ctype
return pretty_mappings [ ctype ]
2013-07-18 01:58:24 +04:00
@staticmethod
def get_usb2_controllers ( conn ) :
ret = [ ]
ctrl = VirtualController ( conn )
ctrl . type = " usb "
ctrl . model = " ich9-ehci1 "
ret . append ( ctrl )
ctrl = VirtualController ( conn )
ctrl . type = " usb "
ctrl . model = " ich9-uhci1 "
ctrl . master_startport = 0
ret . append ( ctrl )
ctrl = VirtualController ( conn )
ctrl . type = " usb "
ctrl . model = " ich9-uhci2 "
ctrl . master_startport = 2
ret . append ( ctrl )
ctrl = VirtualController ( conn )
ctrl . type = " usb "
ctrl . model = " ich9-uhci3 "
ctrl . master_startport = 4
ret . append ( ctrl )
return ret
_XML_PROP_ORDER = [ " type " , " index " , " model " , " master_startport " ]
2013-03-18 01:06:52 +04:00
2013-09-19 21:27:30 +04:00
type = XMLProperty ( " ./@type " )
model = XMLProperty ( " ./@model " )
vectors = XMLProperty ( " ./@vectors " , is_int = True )
ports = XMLProperty ( " ./@ports " , is_int = True )
master_startport = XMLProperty ( " ./master/@startport " , is_int = True )
2013-03-18 01:06:52 +04:00
2013-09-19 21:27:30 +04:00
index = XMLProperty ( " ./@index " , is_int = True , default_cb = lambda s : 0 )
2013-07-24 16:46:55 +04:00
2015-04-05 03:01:03 +03:00
def pretty_desc ( self ) :
ret = self . pretty_type ( self . type )
if self . type == " scsi " :
if self . model == " virtio-scsi " :
ret = " Virtio " + ret
elif self . address . type == " spapr-vio " :
ret = " sPAPR " + ret
return ret
2013-07-24 16:46:55 +04:00
VirtualController . register_type ( )