Esempio n. 1
0
def _format_address(dev_type, address):
    if dev_type == 'pci':
        address = validate.normalize_pci_address(**address)
    ret = '_'.join(
        '{}{}'.format(key, value)
        for key, value in sorted(address.items(), key=operator.itemgetter(0)))
    return '{}_{}'.format(dev_type, ret)
Esempio n. 2
0
def _normalize_pci_address(domain, bus, slot, function, **kwargs):
    """
    Wrapper around normalize_pci_address to handle transparently
    the extra fields of the address (e.g. type) which don't need
    normalization.
    """
    kwargs.update(
        **validate.normalize_pci_address(domain, bus, slot, function))
    return kwargs
Esempio n. 3
0
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)}
Esempio n. 4
0
File: hostdev.py Progetto: nirs/vdsm
def _format_address(dev_type, address):
    if dev_type == 'pci':
        address = validate.normalize_pci_address(**address)
    ret = '_'.join(
        '{}{}'.format(key, value) for key, value in sorted(
            address.items(),
            key=operator.itemgetter(0)
        )
    )
    return '{}_{}'.format(dev_type, ret)
Esempio n. 5
0
def _normalize_pci_address(domain, bus, slot, function, **kwargs):
    """
    Wrapper around normalize_pci_address to handle transparently
    the extra fields of the address (e.g. type) which don't need
    normalization.
    """
    kwargs.update(
        **validate.normalize_pci_address(domain, bus, slot, function)
    )
    return kwargs
Esempio n. 6
0
    def getXML(self):
        """
        Create domxml for network interface.

        <interface type="bridge">
            <mac address="aa:bb:dd:dd:aa:bb"/>
            <model type="virtio"/>
            <source bridge="engine"/>
            [<driver name="vhost/qemu" queues="int"/>]
            [<filterref filter='filter name'>
              [<parameter name='parameter name' value='parameter value'>]
             </filterref>]
            [<tune><sndbuf>0</sndbuf></tune>]
            [<link state='up|down'/>]
            [<bandwidth>
              [<inbound average="int" [burst="int"]  [peak="int"]/>]
              [<outbound average="int" [burst="int"]  [peak="int"]/>]
             </bandwidth>]
            [<alias name="ua-2b418ef2-91d8-4479-88b1-98461192a54e/>]
        </interface>

        -- or -- a slightly different SR-IOV network interface
        <interface type='hostdev' managed='no'>
          <driver name='vfio'/>
          <source>
           <address type='pci' domain='0x0000' bus='0x00' slot='0x07'
           function='0x0'/>
          </source>
          <mac address='52:54:00:6d:90:02'/>
          <vlan>
           <tag id=100/>
          </vlan>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x07'
          function='0x0'/>
          <boot order='1'/>
          [<alias name="ua-2b418ef2-91d8-4479-88b1-98461192a54e/>]
         </interface>

         -- In case of an ovs dpdk bridge --

        <interface type="vhostuser">
          <address bus="0x00" domain="0x0000" slot="0x04" type="pci"/>
          <mac address="00:1a:4a:16:01:54"/>
          <model type="virtio"/>
          <source mode="server" path='socket path' type="unix"/>
        </interface>


        """
        devtype = 'vhostuser' if self._is_vhostuser else self.device
        iface = self.createXmlElem('interface', devtype, ['address'])
        iface.appendChildWithArgs('mac', address=self.macAddr)

        if hasattr(self, 'nicModel'):
            iface.appendChildWithArgs('model', type=self.nicModel)

        if self.is_hostdevice:
            # SR-IOV network interface
            iface.setAttrs(managed='no')
            host_address = self._device_params['address']
            source = iface.appendChildWithArgs('source')
            source.appendChildWithArgs(
                'address', type='pci',
                **validate.normalize_pci_address(**host_address)
            )

            if self.vlanId is not None:
                vlan = iface.appendChildWithArgs('vlan')
                vlan.appendChildWithArgs('tag', id=str(self.vlanId))
        else:
            ovs_bridge = supervdsm.getProxy().ovs_bridge(self.network)
            if ovs_bridge:
                if ovs_bridge['dpdk_enabled']:
                    self._source_ovsdpdk_bridge(iface, ovs_bridge['name'])
                else:
                    self._source_ovs_bridge(iface, ovs_bridge['name'])
            else:
                iface.appendChildWithArgs('source', bridge=self.network)

        if self.mtu is not None:
            iface.appendChildWithArgs('mtu', size=str(self.mtu))

        if self.port_isolated is not None:
            iface.appendChildWithArgs('port', isolated=str(self.port_isolated))

        if hasattr(self, 'filter'):
            filter = iface.appendChildWithArgs('filterref', filter=self.filter)
            self._set_parameters_filter(filter)

        if hasattr(self, 'linkActive'):
            iface.appendChildWithArgs('link', state='up'
                                      if conv.tobool(self.linkActive)
                                      else 'down')

        if hasattr(self, 'bootOrder'):
            iface.appendChildWithArgs('boot', order=self.bootOrder)

        if self.driver:
            iface.appendChildWithArgs('driver', **self.driver)
        elif self.is_hostdevice:
            iface.appendChildWithArgs('driver', name='vfio')

        if self.sndbufParam:
            tune = iface.appendChildWithArgs('tune')
            tune.appendChildWithArgs('sndbuf', text=self.sndbufParam)

        if 'inbound' in self.specParams or 'outbound' in self.specParams:
            iface.appendChild(self.get_bandwidth_xml(self.specParams))

        if hasattr(self, 'alias'):
            iface.appendChildWithArgs('alias', name=self.alias)

        return iface
Esempio n. 7
0
 def _verify_addr(self, src):
     self.assertEqual(validate.normalize_pci_address(**src), self.ADDR)
Esempio n. 8
0
 def _verify_addr(self, src):
     self.assertEqual(
         validate.normalize_pci_address(**src),
         self.ADDR
     )