def _display_network(self): listen = vmxml.find_first(self._dom, 'listen') if listen.attrib.get('type') == 'network': xml_display_network = listen.attrib.get('network') if xml_display_network: return libvirtnetwork.netname_l2o(xml_display_network) return None
def _make_spec_params(dev, meta): spec_params = { 'copyPasteEnable': _is_feature_flag_enabled( dev, 'clipboard', 'copypaste' ), 'fileTransferEnable': _is_feature_flag_enabled( dev, 'filetransfer', 'enable' ), } key_map = dev.attrib.get('keymap') if key_map: spec_params['keyMap'] = key_map # we need some overrides to undo legacy defaults display_network = meta.get('display_network') if display_network: spec_params['displayNetwork'] = display_network listen = vmxml.find_first(dev, 'listen') if listen.attrib.get('type') == 'network': xml_display_network = listen.attrib.get('network') if xml_display_network: spec_params['displayNetwork'] = libvirtnetwork.netname_l2o( xml_display_network ) elif listen.attrib.get('type') == 'address': spec_params['displayIp'] = listen.attrib.get('address', '0') return spec_params
def update_device_info(cls, vm, device_conf): for x in vm.domain.get_device_elements('interface'): devType = vmxml.attr(x, 'type') mac = vmxml.find_attr(x, 'mac', 'address') alias = core.find_device_alias(x) xdrivers = vmxml.find_first(x, 'driver', None) if xdrivers is not None: driver = core.parse_device_attrs( xdrivers, ('name', 'queues',) ) else: driver = {} if devType == 'hostdev': name = alias model = 'passthrough' else: name = vmxml.find_attr(x, 'target', 'dev') model = vmxml.find_attr(x, 'model', 'type') if model == 'virtio': # Reverse action of the conversion in __init__. model = 'pv' network = None try: if vmxml.find_attr(x, 'link', 'state') == 'down': linkActive = False else: linkActive = True except IndexError: linkActive = True source = vmxml.find_first(x, 'source', None) if source is not None: network = vmxml.attr(source, 'bridge') if not network: network = libvirtnetwork.netname_l2o( vmxml.attr(source, 'network')) address = core.find_device_guest_address(x) for nic in device_conf: if nic.macAddr.lower() == mac.lower(): nic.name = name nic.alias = alias nic.address = address nic.linkActive = linkActive if driver: # If a driver was reported, pass it back to libvirt. # Engine (vm's conf) is not interested in this value. nic.driver.update(driver) # Update vm's conf with address for known nic devices knownDev = False for dev in vm.conf['devices']: if (dev['type'] == hwclass.NIC and dev['macAddr'].lower() == mac.lower()): dev['address'] = address dev['alias'] = alias dev['name'] = name dev['linkActive'] = linkActive knownDev = True # Add unknown nic device to vm's conf if not knownDev: nicDev = {'type': hwclass.NIC, 'device': devType, 'macAddr': mac, 'nicModel': model, 'address': address, 'alias': alias, 'name': name, 'linkActive': linkActive} if network: nicDev['network'] = network vm.conf['devices'].append(nicDev)
def update_device_info(cls, vm, device_conf): for x in vm.domain.get_device_elements('interface'): devType = vmxml.attr(x, 'type') mac = vmxml.find_attr(x, 'mac', 'address') alias = core.find_device_alias(x) xdrivers = vmxml.find_first(x, 'driver', None) driver = ({ 'name': vmxml.attr(xdrivers, 'name'), 'queues': vmxml.attr(xdrivers, 'queues') } if xdrivers is not None else {}) if devType == 'hostdev': name = alias model = 'passthrough' else: name = vmxml.find_attr(x, 'target', 'dev') model = vmxml.find_attr(x, 'model', 'type') network = None try: if vmxml.find_attr(x, 'link', 'state') == 'down': linkActive = False else: linkActive = True except IndexError: linkActive = True source = vmxml.find_first(x, 'source', None) if source is not None: network = vmxml.attr(source, 'bridge') if not network: network = libvirtnetwork.netname_l2o( vmxml.attr(source, 'network')) # Get nic address address = {} # TODO: fix vmxml.device_address and its users to have this code. for child in vmxml.children(x, 'address'): address = dict((k.strip(), v.strip()) for k, v in vmxml.attributes(child).items()) break for nic in device_conf: if nic.macAddr.lower() == mac.lower(): nic.name = name nic.alias = alias nic.address = address nic.linkActive = linkActive if driver: # If a driver was reported, pass it back to libvirt. # Engine (vm's conf) is not interested in this value. nic.driver = driver # Update vm's conf with address for known nic devices knownDev = False for dev in vm.conf['devices']: if (dev['type'] == hwclass.NIC and dev['macAddr'].lower() == mac.lower()): dev['address'] = address dev['alias'] = alias dev['name'] = name dev['linkActive'] = linkActive knownDev = True # Add unknown nic device to vm's conf if not knownDev: nicDev = { 'type': hwclass.NIC, 'device': devType, 'macAddr': mac, 'nicModel': model, 'address': address, 'alias': alias, 'name': name, 'linkActive': linkActive } if network: nicDev['network'] = network vm.conf['devices'].append(nicDev)