def _with_retries(): matched_name = None cmd_to_exec = "%s %s" % (driver_info['cmd_set']['base_cmd'], driver_info['cmd_set']['list_all']) full_node_list = _ssh_execute(ssh_obj, cmd_to_exec) LOG.debug("Retrieved Node List: %s", repr(full_node_list)) # for each node check Mac Addresses for node in full_node_list: if not node: continue LOG.debug("Checking Node: %s's Mac address.", node) cmd_to_exec = "%s %s" % (driver_info['cmd_set']['base_cmd'], driver_info['cmd_set']['get_node_macs']) cmd_to_exec = cmd_to_exec.replace('{_NodeName_}', node) hosts_node_mac_list = _ssh_execute(ssh_obj, cmd_to_exec) for host_mac in hosts_node_mac_list: if not host_mac: continue for node_mac in driver_info['macs']: if (driver_utils.normalize_mac(host_mac) in driver_utils.normalize_mac(node_mac)): LOG.debug("Found Mac address: %s", node_mac) matched_name = node break if matched_name: break if matched_name: break return matched_name
def _with_retries(): matched_name = None cmd_to_exec = "%s %s" % (driver_info['cmd_set']['base_cmd'], driver_info['cmd_set']['list_all']) full_node_list = _ssh_execute(ssh_obj, cmd_to_exec) LOG.debug("Retrieved Node List: %s" % repr(full_node_list)) # for each node check Mac Addresses for node in full_node_list: if not node: continue LOG.debug("Checking Node: %s's Mac address." % node) cmd_to_exec = "%s %s" % (driver_info['cmd_set']['base_cmd'], driver_info['cmd_set']['get_node_macs']) cmd_to_exec = cmd_to_exec.replace('{_NodeName_}', node) hosts_node_mac_list = _ssh_execute(ssh_obj, cmd_to_exec) for host_mac in hosts_node_mac_list: if not host_mac: continue for node_mac in driver_info['macs']: if (driver_utils.normalize_mac(host_mac) in driver_utils.normalize_mac(node_mac)): LOG.debug("Found Mac address: %s" % node_mac) matched_name = node break if matched_name: break if matched_name: break return matched_name
def _get_domain_by_macs(task): """Get the domain the host uses to reference the node. :param task: a TaskManager instance containing the node to act on :returns: the libvirt domain object. :raises: NodeNotFound if could not find a VM corresponding to any of the provided MACs. :raises: InvalidParameterValue if any connection parameters are incorrect or if failed to connect to the Libvirt uri. :raises: LibvirtError if failed to connect to the Libvirt uri. """ driver_info = _parse_driver_info(task.node) conn = _get_libvirt_connection(driver_info) macs = driver_utils.get_node_mac_addresses(task) node_macs = {driver_utils.normalize_mac(mac) for mac in macs} full_node_list = conn.listAllDomains() for domain in full_node_list: LOG.debug("Checking Domain: %s's Mac address", domain.name()) parsed = ET.fromstring(domain.XMLDesc()) domain_macs = { driver_utils.normalize_mac(el.attrib['address']) for el in parsed.iter('mac') } found_macs = domain_macs & node_macs # this is intersection of sets if found_macs: LOG.debug("Found MAC addresses: %s " "for node: %s", found_macs, driver_info['uuid']) return domain raise ir_exc.NodeNotFound( _("Can't find domain with specified MACs: %(macs)s " "for node %(node)s") % { 'macs': domain_macs, 'node': driver_info['uuid'] })
def _get_domain_by_macs(task): """Get the domain the host uses to reference the node. :param task: a TaskManager instance containing the node to act on :returns: the libvirt domain object. :raises: NodeNotFound if could not find a VM corresponding to any of the provided MACs. :raises: InvalidParameterValue if any connection parameters are incorrect or if failed to connect to the Libvirt uri. :raises: LibvirtError if failed to connect to the Libvirt uri. """ driver_info = _parse_driver_info(task.node) conn = _get_libvirt_connection(driver_info) macs = driver_utils.get_node_mac_addresses(task) node_macs = {driver_utils.normalize_mac(mac) for mac in macs} full_node_list = conn.listAllDomains() for domain in full_node_list: LOG.debug("Checking Domain: %s's Mac address", domain.name()) parsed = ET.fromstring(domain.XMLDesc()) domain_macs = {driver_utils.normalize_mac( el.attrib['address']) for el in parsed.iter('mac')} found_macs = domain_macs & node_macs # this is intersection of sets if found_macs: LOG.debug("Found MAC addresses: %s " "for node: %s", found_macs, driver_info['uuid']) return domain raise ir_exc.NodeNotFound( _("Can't find domain with specified MACs: %(macs)s " "for node %(node)s") % {'macs': domain_macs, 'node': driver_info['uuid']})
def test_normalize_mac_unicode(self): mac_raw = u"0A:1B-2C-3D:4F" mac_clean = driver_utils.normalize_mac(mac_raw) self.assertEqual("0a1b2c3d4f", mac_clean)