Beispiel #1
0
    def _get_cluster_info(self, data):
        """Get the details of a cluster with a given name in PKS environment.

        System administrator gets the given cluster information regardless of
        who is the owner of the cluster. Other users get info only on
        the cluster they own.

        :param str cluster_name: Name of the cluster
        :return: Details of the cluster.

        :rtype: dict
        """
        cluster_name = data[RequestKey.CLUSTER_NAME]
        # The structure of info returned by list_cluster and get_cluster is
        # identical, hence using list_cluster and filtering by name in memory
        # to retrieve info of the requested cluster.
        cluster_info_list = self._list_clusters(data)
        result = {}
        if self.tenant_client.is_sysadmin() \
                or is_org_admin(self.client_session) \
                or data.get('is_org_admin_search'):
            filtered_cluster_info_list = []
            for cluster_info in cluster_info_list:
                if cluster_info['name'] == cluster_name:
                    filtered_cluster_info_list.append(cluster_info)
            LOGGER.debug(
                f"Filtered list of clusters:{filtered_cluster_info_list}")
            if len(filtered_cluster_info_list) > 1:
                raise PksDuplicateClusterError(
                    requests.codes.bad_request,
                    f"Multiple clusters with name '{cluster_name}' exists.")
            if len(filtered_cluster_info_list) == 0:
                raise PksServerError(requests.codes.not_found,
                                     f"cluster {cluster_name} not found.")
            result = filtered_cluster_info_list[0]
        else:
            qualified_cluster_name = self._append_user_id(cluster_name)
            for cluster_info in cluster_info_list:
                if cluster_info['pks_cluster_name'] == qualified_cluster_name:
                    result = cluster_info
                    break
            if not result:
                raise PksServerError(requests.codes.not_found,
                                     f"cluster {cluster_name} not found.")

        return result
    def get_cluster_info(self, data):
        """Get the details of a cluster with a given name in PKS environment.

        System administrator gets the given cluster information regardless of
        who is the owner of the cluster. Other users get info only on
        the cluster they own.

        :param str cluster_name: Name of the cluster
        :return: Details of the cluster.

        :rtype: dict
        """
        cluster_name = data[RequestKey.CLUSTER_NAME]

        if self.tenant_client.is_sysadmin() \
                or is_org_admin(self.client_session) \
                or data.get('is_org_admin_search'):
            cluster_list = self.list_clusters(data)
            filtered_cluster_list = \
                self._filter_list_by_cluster_name(cluster_list, cluster_name)
            LOGGER.debug(f"filtered Cluster List:{filtered_cluster_list}")
            if len(filtered_cluster_list) > 1:
                raise PksDuplicateClusterError(
                    requests.codes.bad_request,
                    f"Multiple clusters with name '{cluster_name}' exists.")
            if len(filtered_cluster_list) == 0:
                raise PksServerError(requests.codes.not_found,
                                     f"cluster {cluster_name} not found.")
            return filtered_cluster_list[0]

        cluster_info = \
            self._get_cluster_info(self._append_user_id(cluster_name))
        self._restore_original_name(cluster_info)
        if not data.get('is_admin_request'):
            self._filter_pks_properties(cluster_info)

        return cluster_info