Exemplo n.º 1
0
def set_irq_affinity(set_bitmap, irqs, cpulist):
    """Set irq affinity to the specified cpulist for list of irqs.

    :param set_bitmap: True: set bitmap file, False: set list file
    :param irqs: irq list
    :param cpulist: cpu list
    """
    _irqs = set()

    if set_bitmap:
        filename = 'smp_affinity'
    else:
        filename = 'smp_affinity_list'

    for irq in irqs:
        irq_aff_path = "%s/%s/%s" % (COMPUTE_IRQ, irq, filename)
        try:
            with open(irq_aff_path, 'w') as f:
                f.write(cpulist)
                LOG.info("PCI IRQ %s pinned to CPUS: %s" % (irq, cpulist))
            _irqs.update([irq])
        except Exception as e:
            LOG.warning("Failed to write pci affine file:%(F)s, irq:%(I)s, "
                        "error=%(E)s" % {
                            "F": filename,
                            "I": irq,
                            "E": e
                        })
    return _irqs
Exemplo n.º 2
0
    def get_instances(self, filters):
        instances = set()
        try:
            nova = self.get_nova()
            filters['host'] = self._hostname
            servers = nova.servers.list(detailed=True, search_opts=filters)
            flavors = nova.flavors.list()

            for server in servers:
                for flavor in flavors:
                    if flavor.id == server.flavor["id"]:
                        extra_spec = flavor.get_keys()
                        if 'hw:cpu_policy' in extra_spec \
                                and extra_spec['hw:cpu_policy'] == 'dedicated':
                            inst = instance.instance(server.id, server.name,
                                                     extra_spec)
                            instances.update([inst])
            # get numa topology and pci info from libvirt
            if len(instances) > 0:
                for inst in instances:
                    domain = guest.get_guest_domain_by_uuid(
                        self._conn, inst.uuid)
                    inst.update(domain)
        except Exception as e:
            LOG.warning("Failed to get instances info! error=%s" % e)

        return instances
Exemplo n.º 3
0
    def get_instance(self, uuid):
        try:
            nova = self.get_nova()
            server = nova.servers.get(uuid)
            flavor_info = nova.flavors.get(server.flavor["id"])
            hostname = server.__dict__['OS-EXT-SRV-ATTR:host']
        except Exception as e:
            LOG.warning("Could not get instance=%s from Nova! error=%s" %
                        (uuid, e))
            return None

        LOG.debug('GET VM:%s in node:%s' % (server.name, hostname))

        if hostname == self._hostname:
            inst = instance.instance(uuid, server.name, flavor_info.get_keys())
            # get numa topology and pci info from libvirt
            try:
                domain = guest.get_guest_domain_by_uuid(self._conn, uuid)
                if domain:
                    inst.update(domain)
            except Exception as e:
                LOG.warning("Failed to access libvirt! error=%s" % e)
            return inst
        else:
            LOG.debug('The VM is not in current host!')
            return None
Exemplo n.º 4
0
def get_guest_domain_by_uuid(conn, uuid):
    try:
        dom = conn.lookupByUUIDString(uuid)
    except Exception as e:
        LOG.warning("Failed to get domain for uuid=%s! error=%s" % (uuid, e))
        return None
    domain = get_guest_domain_info(dom)
    return domain
Exemplo n.º 5
0
 def get_nova(self):
     try:
         sess = session.Session(auth=self._auth, verify=self._cacert)
         nova = client.Client('2.1', session=sess)
         return nova
     except Exception as e:
         LOG.warning("Failed to connect to nova!")
         raise Exception("could not connect nova!")
Exemplo n.º 6
0
        def _wait_for_msi_irqs(self, inst):
            """Check if each pci device has the expected number of msi irqs."""
            _prev = self._msi_irq_count.copy()
            addrs = set()

            for pci_dev in inst.pci_devices:
                addr = pci_dev.address
                addrs.update([addr])
                try:
                    irqs, msi_irqs = pci_utils.get_irqs_by_pci_address(addr)
                except Exception as e:
                    msi_irqs = set()
                    LOG.error(
                        '_wait_for_msi_irqs: pci_addr=%(A)s, error=%(E)s' % {
                            'A': addr,
                            'E': e
                        })
                self._msi_irq_count[addr] = len(msi_irqs)
                self._msi_irq_elapsed[
                    addr] += CONF.parameters.msi_irq_check_interval
                if _prev[addr] == self._msi_irq_count[addr]:
                    self._msi_irq_since[
                        addr] += CONF.parameters.msi_irq_check_interval
                else:
                    self._msi_irq_since[addr] = 0

            # Done when msi irq counts have not changed for some time
            if all((self._msi_irq_count[k] > 0) and (
                    self._msi_irq_since[k] >= CONF.parameters.msi_irq_since)
                   for k in addrs):
                raise loopingcall.LoopingCallDone()

            # Abort due to timeout
            if all(self._msi_irq_elapsed[k] >= CONF.parameters.msi_irq_timeout
                   for k in addrs):
                msg = ("reached %(timeout)s seconds timeout, waiting for "
                       "msi irqs of pci_addrs: %(addrs)s") % {
                           'timeout': CONF.parameters.msi_irq_timeout,
                           'addrs': list(addrs)
                       }
                LOG.warning(msg)
                raise loopingcall.LoopingCallDone()