Exemplo n.º 1
0
    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"]
Exemplo n.º 2
0
 def wait_for_vms_accessible(vms, timeout_secs):
     """
 Wait until all the specified VMs are accessible to run guest OS commands.
 Raises CurieTestException if this takes longer than 'timeout_secs'.
 """
     t1 = time.time()
     t2 = -1
     for xx, vm in enumerate(vms):
         log.info("Waiting for VM %d/%d (%s) to become accessible", xx + 1,
                  len(vms), vm.vm_name())
         if t2 >= 0:
             wait_for_timeout_secs = timeout_secs - (t2 - t1)
         else:
             wait_for_timeout_secs = timeout_secs
         if wait_for_timeout_secs < 0:
             error_msg = "Timeout waiting for VMs to become accessible"
             raise CurieTestException(error_msg)
         if vm.vm_ip() is None:
             error_msg = "IP address not set on Vm object %s" % vm.vm_name()
             raise CurieTestException(error_msg)
         if not CurieUtil.is_ipv4_address(vm.vm_ip()):
             error_msg = "Non-IPv4 address %s on VM %s" % (vm.vm_ip(),
                                                           vm.vm_name())
             raise CurieTestException(error_msg)
         msg = "waiting for VM %s (%s) to become accessible" % \
           (vm.vm_name(), vm.vm_ip())
         if not CurieUtil.wait_for(vm.is_accessible, msg,
                                   wait_for_timeout_secs):
             error_msg = "Timeout waiting for VMs to become accessible"
             raise CurieTestException(error_msg)
         log.info("VM %d/%d (%s) is accessible", xx + 1, len(vms),
                  vm.vm_name())
         t2 = time.time()
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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])
Exemplo n.º 5
0
  def _update_cluster_version_info_vcenter(cluster_pb):
    """
    See 'DiscoveryUtil.update_cluster_version_info' for info.
    """
    mgmt_info = cluster_pb.cluster_management_server_info.vcenter_info
    hyp_info = cluster_pb.cluster_hypervisor_info.esx_info

    with VsphereVcenter.from_proto(mgmt_info) as vcenter:
      vim_dc = vcenter.lookup_datacenter(mgmt_info.vcenter_datacenter_name)
      vim_cluster = vcenter.lookup_cluster(vim_dc,
                                           mgmt_info.vcenter_cluster_name)
      if vim_cluster is None:
        raise CurieException(CurieError.kInvalidParameter,
                              "Cluster not found in specified vCenter")

      esx_version_pairs = vcenter.get_esx_versions(vim_cluster)
      hyp_info.version.extend(pair[0] for pair in esx_version_pairs)
      hyp_info.build.extend(pair[1] for pair in esx_version_pairs)

      mgmt_info.vcenter_version, mgmt_info.vcenter_build = \
          vcenter.get_vcenter_version_info()

      if cluster_pb.cluster_software_info.HasField("nutanix_info"):
        cvms = [vim_vm for vim_vm in vcenter.lookup_vms(vim_cluster)
                if vcenter.vim_vm_is_nutanix_cvm(vim_vm)]
        if not cvms:
          raise CurieException(
            CurieError.kInvalidParameter,
            "Unable to locate any CVMs on cluster. Is this a Nutanix cluster?")
        for cvm in cvms:
          ip = get_optional_vim_attr(cvm.guest, "ipAddress")
          if ip and CurieUtil.is_ipv4_address(ip):
            break
        else:
          raise CurieException(
            CurieError.kInvalidParameter,
            "Unable to locate any CVMs with IPv4 addresses on cluster")

        software_info = cluster_pb.cluster_software_info.nutanix_info
        cli = NutanixRestApiClient(
          ip,
          software_info.decrypt_field("prism_user"),
          software_info.decrypt_field("prism_password"))
        DiscoveryUtil._update_cluster_version_info_nos(cli, cluster_pb)