def _init_address_fields(self, pci_addr): if self.is_physical_function: (self.domain, self.bus, self.slot, self.func) = pci_utils.get_pci_address_fields(pci_addr) return dbs, sep, func = pci_addr.partition('.') if func: fstr = func.strip() if fstr != ANY: try: f = get_value(fstr) except SyntaxError: raise exception.PciDeviceWrongAddressFormat( address=pci_addr) if f > MAX_FUNC: raise exception.PciDeviceInvalidAddressField( address=pci_addr, field="function") self.func = "%1x" % f if dbs: dbs_fields = dbs.split(':') if len(dbs_fields) > 3: raise exception.PciDeviceWrongAddressFormat(address=pci_addr) # If we got a partial address like ":00.", we need to to turn this # into a domain of ANY, a bus of ANY, and a slot of 00. This code # allows the address bus and/or domain to be left off dbs_all = [ANY for x in range(3 - len(dbs_fields))] dbs_all.extend(dbs_fields) dbs_checked = [s.strip() or ANY for s in dbs_all] self.domain, self.bus, self.slot = dbs_checked get_pci_dev_info(self, 'domain', MAX_DOMAIN, '%04x') get_pci_dev_info(self, 'bus', MAX_BUS, '%02x') get_pci_dev_info(self, 'slot', MAX_SLOT, '%02x') self._check_physical_function()
def match(self, pci_addr, pci_phys_addr): # Assume this is called given pci_add and pci_phys_addr from libvirt, # no attempt is made to verify pci_addr is a VF of pci_phys_addr if self.is_physical_function: if not pci_phys_addr: return False domain, bus, slot, func = ( pci_utils.get_pci_address_fields(pci_phys_addr)) return (self.domain == domain and self.bus == bus and self.slot == slot and self.func == func) else: domain, bus, slot, func = ( pci_utils.get_pci_address_fields(pci_addr)) conditions = [ self.domain in (ANY, domain), self.bus in (ANY, bus), self.slot in (ANY, slot), self.func in (ANY, func) ] return all(conditions)
def format_dom(self): dev = super(LibvirtConfigGuestInterface, self).format_dom() dev.set("type", self.net_type) if self.net_type == "hostdev": dev.set("managed", "yes") dev.append(etree.Element("mac", address=self.mac_addr)) if self.model: dev.append(etree.Element("model", type=self.model)) if self.driver_name: driver_elem = etree.Element("driver", name=self.driver_name) dev.append(driver_elem) #multi_nic if self.vif_profile_queues or self.vif_profile_vringbuf: if not self.driver_name: driver_elem = etree.Element("driver", name="vhost") dev.append(driver_elem) if self.vif_profile_queues: driver_elem.set("queues", str(self.vif_profile_queues)) if self.vif_profile_vringbuf: driver_elem.set("vringbuf", str(self.vif_profile_vringbuf)) if self.net_type == "ethernet": if self.script is not None: dev.append(etree.Element("script", path=self.script)) elif self.net_type == "direct": dev.append(etree.Element("source", dev=self.source_dev, mode=self.source_mode)) elif self.net_type == "vhostuser": dev.append(etree.Element("source", type="unix", path=self.source_path, mode=self.source_mode)) elif self.net_type == "hostdev": source_elem = etree.Element("source") domain, bus, slot, func = \ pci_utils.get_pci_address_fields(self.source_dev) addr_elem = etree.Element("address", type='pci') addr_elem.set("domain", "0x%s" % (domain)) addr_elem.set("bus", "0x%s" % (bus)) addr_elem.set("slot", "0x%s" % (slot)) addr_elem.set("function", "0x%s" % (func)) source_elem.append(addr_elem) dev.append(source_elem) else: dev.append(etree.Element("source", bridge=self.source_dev)) if self.vlan and self.net_type in ("direct", "hostdev","bridge"): vlan_elem = etree.Element("vlan") tag_elem = etree.Element("tag", id=self.vlan) vlan_elem.append(tag_elem) dev.append(vlan_elem) if self.target_dev is not None: dev.append(etree.Element("target", dev=self.target_dev)) if self.vporttype is not None: vport = etree.Element("virtualport", type=self.vporttype) for p in self.vportparams: param = etree.Element("parameters") param.set(p['key'], p['value']) vport.append(param) dev.append(vport) if self.filtername is not None: filter = etree.Element("filterref", filter=self.filtername) for p in self.filterparams: filter.append(etree.Element("parameter", name=p['key'], value=p['value'])) dev.append(filter) if self.vif_inbound_average or self.vif_outbound_average: bandwidth = etree.Element("bandwidth") if self.vif_inbound_average is not None: vif_inbound = etree.Element("inbound", average=str(self.vif_inbound_average)) if self.vif_inbound_peak is not None: vif_inbound.set("peak", str(self.vif_inbound_peak)) if self.vif_inbound_burst is not None: vif_inbound.set("burst", str(self.vif_inbound_burst)) bandwidth.append(vif_inbound) if self.vif_outbound_average is not None: vif_outbound = etree.Element("outbound", average=str(self.vif_outbound_average)) if self.vif_outbound_peak is not None: vif_outbound.set("peak", str(self.vif_outbound_peak)) if self.vif_outbound_burst is not None: vif_outbound.set("burst", str(self.vif_outbound_burst)) bandwidth.append(vif_outbound) dev.append(bandwidth) #this if added by huawei for network order if self.pci_slot is not None: dev.append(etree.Element("address", type = "pci", domain = "0x0000", bus = "0x00", slot = "0x%x" % self.pci_slot, function = "0x0")) return dev
def format_dom(self): dev = super(LibvirtConfigGuestInterface, self).format_dom() dev.set("type", self.net_type) if self.net_type == "hostdev": dev.set("managed", "yes") dev.append(etree.Element("mac", address=self.mac_addr)) if self.model: dev.append(etree.Element("model", type=self.model)) if self.driver_name: driver_elem = etree.Element("driver", name=self.driver_name) dev.append(driver_elem) # multi_nic if self.vif_profile_queues or self.vif_profile_vringbuf: if not self.driver_name: driver_elem = etree.Element("driver", name="vhost") dev.append(driver_elem) if self.vif_profile_queues: driver_elem.set("queues", str(self.vif_profile_queues)) if self.vif_profile_vringbuf: driver_elem.set("vringbuf", str(self.vif_profile_vringbuf)) if self.net_type == "ethernet": if self.script is not None: dev.append(etree.Element("script", path=self.script)) elif self.net_type == "direct": dev.append(etree.Element("source", dev=self.source_dev, mode=self.source_mode)) elif self.net_type == "vhostuser": dev.append(etree.Element("source", type="unix", path=self.source_path, mode=self.source_mode)) elif self.net_type == "hostdev": source_elem = etree.Element("source") domain, bus, slot, func = pci_utils.get_pci_address_fields(self.source_dev) addr_elem = etree.Element("address", type="pci") addr_elem.set("domain", "0x%s" % (domain)) addr_elem.set("bus", "0x%s" % (bus)) addr_elem.set("slot", "0x%s" % (slot)) addr_elem.set("function", "0x%s" % (func)) source_elem.append(addr_elem) dev.append(source_elem) else: dev.append(etree.Element("source", bridge=self.source_dev)) if self.vlan and self.net_type in ("direct", "hostdev", "bridge"): vlan_elem = etree.Element("vlan") tag_elem = etree.Element("tag", id=self.vlan) vlan_elem.append(tag_elem) dev.append(vlan_elem) if self.target_dev is not None: dev.append(etree.Element("target", dev=self.target_dev)) if self.vporttype is not None: vport = etree.Element("virtualport", type=self.vporttype) for p in self.vportparams: param = etree.Element("parameters") param.set(p["key"], p["value"]) vport.append(param) dev.append(vport) if self.filtername is not None: filter = etree.Element("filterref", filter=self.filtername) for p in self.filterparams: filter.append(etree.Element("parameter", name=p["key"], value=p["value"])) dev.append(filter) if self.vif_inbound_average or self.vif_outbound_average: bandwidth = etree.Element("bandwidth") if self.vif_inbound_average is not None: vif_inbound = etree.Element("inbound", average=str(self.vif_inbound_average)) if self.vif_inbound_peak is not None: vif_inbound.set("peak", str(self.vif_inbound_peak)) if self.vif_inbound_burst is not None: vif_inbound.set("burst", str(self.vif_inbound_burst)) bandwidth.append(vif_inbound) if self.vif_outbound_average is not None: vif_outbound = etree.Element("outbound", average=str(self.vif_outbound_average)) if self.vif_outbound_peak is not None: vif_outbound.set("peak", str(self.vif_outbound_peak)) if self.vif_outbound_burst is not None: vif_outbound.set("burst", str(self.vif_outbound_burst)) bandwidth.append(vif_outbound) dev.append(bandwidth) # this if added by huawei for network order if self.pci_slot is not None: dev.append( etree.Element( "address", type="pci", domain="0x0000", bus="0x00", slot="0x%x" % self.pci_slot, function="0x0" ) ) return dev