virtinst: throw error when --host-device can't specify unique device

When there are mutiple USB devices with identical vendorId and
productId, with --host-device <vendorId:productId>, virt-install
fails to specify one.
Currently the virt-install add the first node device with
these vendorId and productId.
This fix will throw out an error when argument to --host-device
can't specify unique node device.

For example:
virt-install ${other args} \
             --host-device <vendorId:productId>
ERROR    15e1:2007 corresponds to multiple node devices
This commit is contained in:
Guannan Ren 2013-04-24 18:05:08 +08:00 committed by Cole Robinson
parent b15e51e73b
commit 0802cb1add
2 changed files with 17 additions and 6 deletions

View File

@ -640,7 +640,8 @@ vinst.add_invalid("redirdev", "--redirdev usb,type=tcp,server=:399") # Missing
vinst.add_category("hostdev", "--noautoconsole --nographics --nodisks --pxe")
vinst.add_valid("hostdev", "--host-device usb_device_781_5151_2004453082054CA1BEEE") # Host dev by libvirt name
vinst.add_valid("hostdev", "--host-device 001.003 --host-device 15:0.1 --host-device 2:15:0.2 --host-device 0:15:0.3 --host-device 0x0781:0x5151 --host-device 1d6b:2") # Many hostdev parsing types
vinst.add_valid("hostdev", "--host-device 001.003 --host-device 15:0.1 --host-device 2:15:0.2 --host-device 0:15:0.3 --host-device 0x0781:0x5151") # Many hostdev parsing types
vinst.add_invalid("hostdev", "--host-device 1d6b:2") # multiple USB devices with identical vendorId and productId
vinst.add_invalid("hostdev", "--host-device pci_8086_2850_scsi_host_scsi_host") # Unsupported hostdev type
vinst.add_invalid("hostdev", "--host-device foobarhostdev") # Unknown hostdev
vinst.add_invalid("hostdev", "--host-device 300:400") # Parseable hostdev, but unknown digits

View File

@ -527,14 +527,24 @@ def devAddressToNodedev(conn, addrstr):
cmp_func, devtype = ret
# Iterate over node devices and compare
count = 0
nodedev = None
nodenames = conn.listDevices(devtype, 0)
for name in nodenames:
nodedev = _lookupNodeName(conn, name)
if cmp_func(nodedev):
return nodedev
tmpnode = _lookupNodeName(conn, name)
if cmp_func(tmpnode):
nodedev = tmpnode
count += 1
raise ValueError(_("Did not find a matching node device for '%s'") %
addrstr)
if count == 1:
return nodedev
elif count > 1:
raise ValueError(_("%s corresponds to multiple node devices") %
addrstr)
elif count < 1:
raise ValueError(_("Did not find a matching node device for '%s'") %
addrstr)
def parse(xml):