Exemplo n.º 1
0
    def get_cluster_info(self,
                         cluster_name,
                         cluster_id=None,
                         org=None,
                         vdc=None,
                         **kwargs):
        """Get cluster information using DEF API.

        :param str cluster_name: name of the cluster
        :param str vdc: name of vdc
        :param str org: name of org
        :param kwargs: *filter (dict): keys,values for DEF API query filter

        :return: cluster information
        :rtype: str
        :raises ClusterNotFoundError, CseDuplicateClusterError
        """
        # TODO(Display Owner information): Owner information needs to be
        # displayed
        if cluster_id:
            return self.get_cluster_info_by_id(cluster_id, org=org)
        cluster, _, is_native_cluster = \
            self._get_tkg_native_clusters_by_name(cluster_name,
                                                  org=org, vdc=vdc)
        if is_native_cluster:
            cluster_info = cluster.entity.to_dict()
        else:
            # TKG cluster represents the defined_entity.entity
            cluster_info = client_utils.swagger_object_to_dict(cluster)
        logger.CLIENT_LOGGER.debug(
            f"Received defined entity of cluster {cluster_name} : {cluster_info}"
        )  # noqa: E501
        return yaml.dump(cluster_info)
    def get_cluster_info_by_id(self, cluster_id, org=None, **kwargs):
        """Get TKG-S cluster information using cluster ID.

        :param str cluster_id:
        :param str org:
        :return: cluster information in yaml format
        :rtype: string
        """
        try:
            self.set_tenant_org_context(org_name=org)
            tkg_entity, _ = self.get_tkg_s_cluster(cluster_id)
            cluster_info = client_utils.swagger_object_to_dict(tkg_entity)
            logger.CLIENT_LOGGER.debug(
                f"Retrieved TKG-S entity for ID {cluster_id}: {cluster_info}"
            )  # noqa: E501
            return yaml.dump(cluster_info)
        except tkg_s_rest.ApiException as e:
            logger.CLIENT_LOGGER.debug(e)
            msg = cli_constants.TKG_RESPONSE_MESSAGES_BY_STATUS_CODE.get(
                e.status, f"{e.reason}")  # noqa: E501
            logger.CLIENT_LOGGER.error(msg)
            raise Exception(msg)
        except Exception as e:
            logger.CLIENT_LOGGER.error(
                f"Error getting TKG-S cluster information: {e}")  # noqa: E501
            raise
    def get_cluster_info(self,
                         cluster_name,
                         cluster_id=None,
                         org=None,
                         vdc=None,
                         **kwargs):
        """Get cluster information of a TKG cluster API.

        :param str cluster_name: name of the cluster
        :param str vdc: name of vdc
        :param str org: name of org

        :return: cluster information
        :rtype: str
        :raises ClusterNotFoundError
        """
        if cluster_id:
            return self.get_cluster_info_by_id(cluster_id, org=org)
        try:
            tkg_entities, _ = \
                self.get_tkg_clusters_by_name(cluster_name, vdc=vdc, org=org)
            cluster_entity_dict = client_utils.swagger_object_to_dict(
                tkg_entities[0])  # noqa: E501
            logger.CLIENT_LOGGER.debug(
                f"Received defined entity of cluster {cluster_name} : {cluster_entity_dict}"
            )  # noqa: E501
            return yaml.dump(cluster_entity_dict)
        except tkg_rest.ApiException as e:
            msg = cli_constants.TKG_RESPONSE_MESSAGES_BY_STATUS_CODE.get(
                e.status, f"{e.reason}")  # noqa: E501
            logger.CLIENT_LOGGER.error(msg)
            raise Exception(msg)
        except Exception as e:
            logger.CLIENT_LOGGER.error(f"Error deleting cluster: {e}")
            raise