def identifier_to_node_uuid(cls, rest_client, node_id_name_or_ip): # These will raise appropriate exceptions on failure, so it's safe to # assume that otherwise accessing the 'uuid' key is safe. if CurieUtil.is_ipv4_address(node_id_name_or_ip): return rest_client.hosts_get(host_ip=node_id_name_or_ip)["uuid"] elif CurieUtil.is_uuid(node_id_name_or_ip): try: return rest_client.hosts_get( host_id=node_id_name_or_ip)["uuid"] except Exception: log.debug("Failed to lookup node via UUID '%s'", node_id_name_or_ip) # The provided node identifier is not an IPv4 address or a UUID. It may # be either an unresolved hostname or a Prism name. Try Prism name first # to avoid potential overhead in name resolution. try: return rest_client.hosts_get(host_name=node_id_name_or_ip)["uuid"] except Exception: log.debug("Failed to lookup node via Prism name '%s'", node_id_name_or_ip) try: ip = CurieUtil.resolve_hostname(node_id_name_or_ip) except Exception: raise CurieException( CurieError.kInvalidParameter, "Unable to resolve IP address for '%s'" % node_id_name_or_ip) # Allow this to raise it's own exception on failure, as there are no # further methods to which we can fall back. return rest_client.hosts_get(host_ip=ip)["uuid"]
def __init__(self, cluster, node_id, node_index): super(VsphereNode, self).__init__(cluster, node_id, node_index) # vCenter node IDs are either IPv4 addresses or hostnames. if CurieUtil.is_ipv4_address(node_id): self._node_ip = node_id else: self._node_ip = CurieUtil.resolve_hostname(node_id)
def __init__(self, cluster, node_id, node_index, node_properties): super(HyperVNode, self).__init__(cluster, node_id, node_index) self.power_state = node_properties["power_state"] self.__fqdn = node_properties["fqdn"] self.__overall_state = node_properties["overall_state"] ips = node_properties["ips"] if not ips: raise CurieException("Received empty node ip list in response") # vCenter node IDs are either IPv4 addresses or hostnames. if CurieUtil.is_ipv4_address(ips[0]): self._node_ip = ips[0] else: self._node_ip = CurieUtil.resolve_hostname(ips[0])