def get_ironic_node(ironic_client, ip_mac_service_tag): node = None if ":" in ip_mac_service_tag: # Assume we're looking for the MAC address of the provisioning NIC try: port = ironic_client.port.get_by_address(ip_mac_service_tag) except NotFound: pass else: node = ironic_client.node.get(port.node_uuid) elif "." in ip_mac_service_tag: # Assume we're looking for the IP address of the iDRAC for n in ironic_client.node.list(detail=True): drac_ip, _ = CredentialHelper.get_drac_ip_and_user(n) if drac_ip == ip_mac_service_tag: node = n break else: # Assume we're looking for the service tag for n in ironic_client.node.list(detail=True): if n.properties["service_tag"] == ip_mac_service_tag: node = n break return node
def validate_node_placement(): logger.info("Validating node placement...") # For each role/flavor, node indices must start at 0 and increase by 1 ironic = IronicHelper.get_ironic_client() flavor_to_indices = {} for node in ironic.node.list(detail=True): # Skip nodes that are in maintenance mode if node.maintenance: continue # Get the value of the "node" capability node_capability = None capabilities = node.properties["capabilities"] for capability in capabilities.split(","): (key, val) = capability.split(":") if key == "node": node_capability = val # If the node capability was not set then error out if not node_capability: ip, _ = CredentialHelper.get_drac_ip_and_user(node) raise ValueError("Error: Node {} has not been assigned a node " "placement index. Run assign_role for this " "node and specify a role with the " "<role>-<index> format".format(ip)) hyphen = node_capability.rfind("-") flavor = node_capability[0:hyphen] index = node_capability[hyphen + 1:] # Build up a dict that maps a flavor name to a sequence of placment # indices if flavor not in flavor_to_indices: flavor_to_indices[flavor] = [] flavor_to_indices[flavor].append(int(index)) # Validate that the sequence starts at zero and is coherent error_msg = '' for flavor in flavor_to_indices.keys(): flavor_to_indices[flavor].sort() seq = flavor_to_indices[flavor] if seq[0] != 0: error_msg += "Error: There must be a node with flavor \"{}\" " \ "that has node placement index 0. Current nodes placement " \ "indices are {}\n".format(flavor, str(seq)) if not is_coherent(seq): error_msg += "Error: Nodes that have been assigned the \"{}\" " \ "flavor do not have node placement indices that increase by " \ "1. Current node indices are {}\n".format(flavor, str(seq)) # If any errors were detected then bail if error_msg: raise ValueError(error_msg)