Beispiel #1
0
    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)
Beispiel #2
0
    def _get_vf_data(self, 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(k.strip())
            m1 = PciAddress(value.strip())
            if m.bus == m1.bus:
                vf_data.update({"vf_pci": str(v)})
                break

        return vf_data
Beispiel #3
0
    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)
Beispiel #4
0
    def add_sriov_interfaces(cls, vm_pci, vf_pci, vf_mac, xml):
        """Add a SR-IOV 'interface' XML node in 'devices' node

        <devices>
           <interface type='hostdev' managed='yes'>
             <source>
               <address type='pci' domain='0x0000' bus='0x00' slot='0x03'
                function='0x0'/>
             </source>
             <mac address='52:54:00:6d:90:02'>
             <address type='pci' domain='0x0000' bus='0x02' slot='0x04'
              function='0x1'/>
           </interface>
           ...
         </devices>

        Reference: https://access.redhat.com/documentation/en-us/
            red_hat_enterprise_linux/6/html/
            virtualization_host_configuration_and_guest_installation_guide/
            sect-virtualization_host_configuration_and_guest_installation_guide
            -sr_iov-how_sr_iov_libvirt_works
        """

        root = ET.parse(xml)
        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', vf_mac)

        source = ET.SubElement(interface, 'source')
        addr = ET.SubElement(source, 'address')
        pci_address = PciAddress(vf_pci.strip())
        cls._add_interface_address(addr, pci_address)

        pci_vm_address = PciAddress(vm_pci.strip())
        cls._add_interface_address(interface, pci_vm_address)

        root.write(xml)
Beispiel #5
0
 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))
Beispiel #6
0
    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(vf['vpci'].strip())
        # Generate the vpci for the interfaces
        slot = index + idx + 10
        vf['vpci'] = \
            "{}:{}:{:02x}.{}".format(vpci.domain, vpci.bus, slot, vpci.function)
        self.connection.execute("ifconfig %s up" % vf['interface'])
        self.connection.execute(vf_spoofchk.format(vf['interface']))
        return model.Libvirt.add_sriov_interfaces(
            vf['vpci'], vf['vf_pci']['vf_pci'], vf['mac'], str(cfg))
Beispiel #7
0
    def add_ovs_interface(cls, vpath, port_num, vpci, vports_mac, xml_str,
                          queues):
        """Add a DPDK OVS 'interface' XML node in 'devices' node

        <devices>
            <interface type='vhostuser'>
                <mac address='00:00:00:00:00:01'/>
                <source type='unix' path='/usr/local/var/run/openvswitch/
                 dpdkvhostuser0' mode='client'/>
                <model type='virtio'/>
                <driver queues='4'>
                    <host mrg_rxbuf='off'/>
                </driver>
                <address type='pci' domain='0x0000' bus='0x00' slot='0x03'
                 function='0x0'/>
            </interface>
            ...
        </devices>

        Reference: http://docs.openvswitch.org/en/latest/topics/dpdk/
                   vhost-user/
        """

        vhost_path = ('{0}/var/run/openvswitch/dpdkvhostuser{1}'.
                      format(vpath, port_num))
        root = ET.fromstring(xml_str)
        pci_address = PciAddress(vpci.strip())
        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)
        source.set('mode', 'client')

        model = ET.SubElement(interface, 'model')
        model.set('type', 'virtio')

        driver = ET.SubElement(interface, 'driver')
        driver.set('queues', str(queues))

        host = ET.SubElement(driver, 'host')
        host.set('mrg_rxbuf', 'off')

        cls._add_interface_address(interface, pci_address)

        return ET.tostring(root)
Beispiel #8
0
 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)
Beispiel #9
0
 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)