def update_from_xml(cls, vm, device_conf, device_xml): alias = core.find_device_alias(device_xml) address = vmxml.device_address(device_xml) source = vmxml.find_first(device_xml, 'source') device = pci_address_to_name(**vmxml.device_address(source)) # We can assume the device name to be correct since we're # inspecting source element. For the address, we may look at # both addresses and determine the correct one. if pci_address_to_name(**address) == device: address = vmxml.device_address(device_xml, 1) known_device = False for dev in device_conf: if dev.device == device: dev.alias = alias dev.address = address known_device = True for dev in vm.conf['devices']: if dev['device'] == device: dev['alias'] = alias dev['address'] = address if not known_device: device = pci_address_to_name(**vmxml.device_address(source)) hostdevice = { 'type': hwclass.HOSTDEV, 'device': device, 'alias': alias, 'address': address, } vm.conf['devices'].append(hostdevice)
def _get_hostdev_params(dev): src_dev = vmxml.find_first(dev, 'source') src_addr = vmxml.device_address(src_dev) src_addr_type = src_addr.pop('type', None) if src_addr_type != 'pci': raise UnsupportedAddress(src_addr_type) addr = validate.normalize_pci_address(**src_addr) return {'hostdev': pci_address_to_name(**addr)}