def add_sriov_interfaces(cls, vm_pci, vf_pci, vfmac, xml): root = ET.parse(xml) pci_address = PciAddress.parse_address(vf_pci.strip(), multi_line=True) device = root.find('devices') interface = ET.SubElement(device, 'interface') interface.set('managed', 'yes') interface.set('type', 'hostdev') mac = ET.SubElement(interface, 'mac') mac.set('address', vfmac) source = ET.SubElement(interface, 'source') addr = ET.SubElement(source, "address") addr.set('domain', "0x0") addr.set('bus', "{0}".format(pci_address.bus)) addr.set('function', "{0}".format(pci_address.function)) addr.set('slot', "0x{0}".format(pci_address.slot)) addr.set('type', "pci") pci_vm_address = PciAddress.parse_address(vm_pci.strip(), multi_line=True) cls.add_interface_address(interface, pci_vm_address) root.write(xml)
def get_vf_data(self, key, value, vfmac, pfif): vf_data = { "mac": vfmac, "pf_if": pfif } vfs = StandaloneContextHelper.get_virtual_devices(self.connection, value) for k, v in vfs.items(): m = PciAddress.parse_address(k.strip(), multi_line=True) m1 = PciAddress.parse_address(value.strip(), multi_line=True) if m.bus == m1.bus: vf_data.update({"vf_pci": str(v)}) break return vf_data
def add_ovs_interface(cls, vpath, port_num, vpci, vports_mac, xml): vhost_path = '{0}/var/run/openvswitch/dpdkvhostuser{1}' root = ET.parse(xml) pci_address = PciAddress.parse_address(vpci.strip(), multi_line=True) device = root.find('devices') interface = ET.SubElement(device, 'interface') interface.set('type', 'vhostuser') mac = ET.SubElement(interface, 'mac') mac.set('address', vports_mac) source = ET.SubElement(interface, 'source') source.set('type', 'unix') source.set('path', vhost_path.format(vpath, port_num)) source.set('mode', 'client') model = ET.SubElement(interface, 'model') model.set('type', 'virtio') driver = ET.SubElement(interface, 'driver') driver.set('queues', '4') host = ET.SubElement(driver, 'host') host.set('mrg_rxbuf', 'off') cls.add_interface_address(interface, pci_address) root.write(xml)
def _enable_interfaces(self, index, vfs, cfg): vpath = self.ovs_properties.get("vpath", "/usr/local") vf = self.networks[vfs[0]] port_num = vf.get('port_num', 0) vpci = PciAddress.parse_address(vf['vpci'].strip(), multi_line=True) # Generate the vpci for the interfaces slot = index + port_num + 10 vf['vpci'] = \ "{}:{}:{:02x}.{}".format(vpci.domain, vpci.bus, slot, vpci.function) Libvirt.add_ovs_interface(vpath, port_num, vf['vpci'], vf['mac'], str(cfg))
def _enable_interfaces(self, index, idx, vfs, cfg): vf_spoofchk = "ip link set {0} vf 0 spoofchk off" vf = self.networks[vfs[0]] vpci = PciAddress.parse_address(vf['vpci'].strip(), multi_line=True) # Generate the vpci for the interfaces slot = index + idx + 10 vf['vpci'] = \ "{}:{}:{:02x}.{}".format(vpci.domain, vpci.bus, slot, vpci.function) Libvirt.add_sriov_interfaces( vf['vpci'], vf['vf_pci']['vf_pci'], vf['mac'], str(cfg)) self.connection.execute("ifconfig %s up" % vf['interface']) self.connection.execute(vf_spoofchk.format(vf['interface']))
def test_add_sriov_interfaces(self, mock_et, mock_add_interface_address): pci_address = PciAddress.parse_address("0000:00:04.0", multi_line=True) result = Libvirt.add_sriov_interfaces("0000:00:05.0", "0000:00:04.0", "00:00:00:00:00:01", "xml") self.assertIsNone(result)
def test_add_interface_address(self, mock_et): pci_address = PciAddress.parse_address("0000:00:04.0", multi_line=True) result = Libvirt.add_interface_address("<interface/>", pci_address) self.assertIsNotNone(result)