Ejemplo n.º 1
0
    def _find_domain_by_mac_address(self, mac_address):
        for domain in self.conn.listAllDomains():
            if mac_address in domain.XMLDesc():
                return domain

        raise error.PowerManagementError(
            'Domain with MAC address %s not found!' % mac_address)
Ejemplo n.º 2
0
    def _find_bmc_by_host(self, host):
        if host.mac in self.mac_to_bmc:
            return self.mac_to_bmc[host.mac]
        if host.fqdn in self.fqdn_to_bmc:
            return self.fqdn_to_bmc[host.fqdn]

        raise error.PowerManagementError(
            'BMC for {!r} not found!'.format(host))
Ejemplo n.º 3
0
    def _find_domain_by_host(self, host):
        for domain in self.conn.listAllDomains():
            if host.libvirt_name and host.libvirt_name == domain.name():
                return domain
            if host.mac and host.mac in domain.XMLDesc():
                return domain

        raise error.PowerManagementError(
            'Domain not found for host %s.' % host)
Ejemplo n.º 4
0
def run(target, mac_addresses_list):
    tw = ThreadsWrapper(target)
    for mac_address in mac_addresses_list:
        tw.start_thread(mac_address=mac_address)
    tw.join_threads()

    if tw.errors:
        raise error.PowerManagementError(
            'There are some errors when working the driver. '
            'Please, check logs for more details.')
Ejemplo n.º 5
0
 def _map_hosts_to_driver(self, hosts):
     driver_host_pairs = []
     for host in hosts:
         for power_driver in self.power_drivers:
             if power_driver.supports(host):
                 driver_host_pairs.append((power_driver, host))
                 break
         else:
             raise error.PowerManagementError(
                 "No supported driver found for host {}".format(host))
     return driver_host_pairs
Ejemplo n.º 6
0
 def _run_command(self, cmd, hosts, **kwargs):
     driver_host_pairs = self._map_hosts_to_driver(hosts)
     tw = utils.ThreadsWrapper()
     for driver, host in driver_host_pairs:
         kwargs['host'] = host
         fn = getattr(driver, cmd)
         tw.start_thread(fn, **kwargs)
     tw.join_threads()
     if tw.errors:
         raise error.PowerManagementError(
             'There are some errors when working the driver. '
             'Please, check logs for more details.')
Ejemplo n.º 7
0
    def _run_set_power_cmd(self, host, cmd, expected_state=None):
        bmc = self._find_bmc_by_host(host)
        try:
            ipmicmd = ipmi_command.Command(bmc=bmc['address'],
                                           userid=bmc['username'],
                                           password=bmc['password'])
            ret = ipmicmd.set_power(cmd, wait=True)
        except pyghmi_exception.IpmiException:
            msg = 'IPMI cmd {!r} failed on bmc {!r}, {!r}'.format(
                cmd, bmc['address'], host)
            LOG.error(msg, exc_info=True)
            raise

        LOG.debug('IPMI response: {}'.format(ret))
        if ret.get('powerstate') != expected_state or 'error' in ret:
            msg = ('Failed to change power state to {!r} on bmc {!r}, '
                   '{!r}'.format(expected_state, bmc['address'], host))
            raise error.PowerManagementError(msg)
Ejemplo n.º 8
0
    def _find_bmc_by_mac_address(self, mac_address):
        if mac_address not in self.mac_to_bmc:
            raise error.PowerManagementError('BMC for Node(%s) not found!' %
                                             mac_address)

        return self.mac_to_bmc[mac_address]