2013-03-18 01:06:52 +04:00
#
2013-10-28 00:59:46 +04:00
# Copyright 2009, 2013 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 . nodedev import NodeDevice
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 VirtualHostDevice ( VirtualDevice ) :
2013-07-16 17:14:37 +04:00
virtual_device_type = VirtualDevice . VIRTUAL_DEV_HOSTDEV
2013-03-18 01:06:52 +04:00
2013-09-28 02:06:39 +04:00
def set_from_nodedev ( self , nodedev , use_full_usb = None ) :
2013-03-18 01:06:52 +04:00
"""
2013-09-28 02:06:39 +04:00
@use_full_usb : If set , and nodedev is USB , specify both
vendor and product . Used if user requests bus / add on virt - install
command line , or if virt - manager detects a dup USB device
and we need to differentiate
2013-03-18 01:06:52 +04:00
"""
2013-09-28 02:06:39 +04:00
if ( use_full_usb is None and
nodedev . addr_type == nodedev . HOSTDEV_ADDR_TYPE_USB_BUSADDR ) :
use_full_usb = True
2013-03-18 01:06:52 +04:00
2013-09-23 02:13:24 +04:00
if nodedev . device_type == NodeDevice . CAPABILITY_TYPE_PCI :
2013-07-16 01:45:43 +04:00
self . type = " pci "
self . domain = nodedev . domain
2013-03-18 01:06:52 +04:00
self . bus = nodedev . bus
2013-07-16 01:45:43 +04:00
self . slot = nodedev . slot
self . function = nodedev . function
2013-03-18 01:06:52 +04:00
2013-09-23 02:13:24 +04:00
elif nodedev . device_type == NodeDevice . CAPABILITY_TYPE_USBDEV :
2013-07-16 01:45:43 +04:00
self . type = " usb "
self . vendor = nodedev . vendor_id
self . product = nodedev . product_id
2013-03-18 01:06:52 +04:00
2013-09-28 02:06:39 +04:00
if use_full_usb :
2013-07-16 01:45:43 +04:00
self . bus = nodedev . bus
self . device = nodedev . device
2013-09-28 02:06:39 +04:00
elif nodedev . device_type == nodedev . CAPABILITY_TYPE_NET :
parentnode = nodedev . lookupNodeName ( self . conn , nodedev . parent )
self . set_from_nodedev ( parentnode , use_full_usb = use_full_usb )
2013-07-16 01:45:43 +04:00
else :
raise ValueError ( " Unknown node device type %s " % nodedev )
2013-03-18 01:06:52 +04:00
2013-07-16 01:45:43 +04:00
_XML_PROP_ORDER = [ " mode " , " type " , " managed " , " vendor " , " product " ,
" domain " , " bus " , " slot " , " function " ]
2013-03-18 01:06:52 +04:00
2013-09-19 21:27:30 +04:00
mode = XMLProperty ( " ./@mode " , default_cb = lambda s : " subsystem " )
type = XMLProperty ( " ./@type " )
2013-03-18 01:06:52 +04:00
2013-07-16 01:45:43 +04:00
def _get_default_managed ( self ) :
return self . conn . is_xen ( ) and " no " or " yes "
2013-09-19 21:27:30 +04:00
managed = XMLProperty ( " ./@managed " , is_yesno = True ,
2013-07-16 21:04:24 +04:00
default_cb = _get_default_managed )
2013-03-18 01:06:52 +04:00
2013-09-19 21:27:30 +04:00
vendor = XMLProperty ( " ./source/vendor/@id " )
product = XMLProperty ( " ./source/product/@id " )
2013-03-18 01:06:52 +04:00
2013-09-19 21:27:30 +04:00
device = XMLProperty ( " ./source/address/@device " )
bus = XMLProperty ( " ./source/address/@bus " )
2013-03-18 01:06:52 +04:00
2013-07-16 01:45:43 +04:00
def _get_default_domain ( self ) :
if self . type == " pci " :
return " 0x0 "
return None
2013-09-19 21:27:30 +04:00
domain = XMLProperty ( " ./source/address/@domain " ,
2013-07-16 01:45:43 +04:00
default_cb = _get_default_domain )
2013-09-19 21:27:30 +04:00
function = XMLProperty ( " ./source/address/@function " )
slot = XMLProperty ( " ./source/address/@slot " )
2013-07-24 16:46:55 +04:00
2014-01-15 03:09:21 +04:00
driver_name = XMLProperty ( " ./driver/@name " )
2014-02-10 23:24:22 +04:00
rom_bar = XMLProperty ( " ./rom/@bar " , is_onoff = True )
2014-01-15 03:09:21 +04:00
2013-07-24 16:46:55 +04:00
VirtualHostDevice . register_type ( )