示例#1
0
    def get_cluster_config(self, data):
        """Get the configuration of the cluster with the given name in PKS.

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

        :return: Configuration of the cluster.

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

        if self.tenant_client.is_sysadmin() or \
                is_org_admin(self.client_session):
            cluster_info = self._get_cluster_info(data)
            qualified_cluster_name = cluster_info['pks_cluster_name']
        else:
            qualified_cluster_name = self._append_user_id(cluster_name)

        self._check_cluster_isolation(cluster_name, qualified_cluster_name)

        cluster_api = ClusterApi(api_client=self.client)

        LOGGER.debug(f"Sending request to PKS: {self.pks_host_uri} to get"
                     f" kubectl configuration of cluster with name: "
                     f"{qualified_cluster_name}")
        config = cluster_api.create_user(cluster_name=qualified_cluster_name)
        LOGGER.debug(f"Received response from PKS: {self.pks_host_uri} on "
                     f"cluster: {qualified_cluster_name} with details: "
                     f"{config}")
        cluster_config = yaml.safe_dump(config, default_flow_style=False)

        return self.filter_traces_of_user_context(cluster_config)
    def _get_cluster_config(self, cluster_name):
        """Get the configuration of the cluster with the given name in PKS.

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

        :rtype: str
        """
        cluster_api = ClusterApi(api_client=self.pks_client)

        LOGGER.debug(f"Sending request to PKS: {self.pks_host_uri} to get"
                     f" detailed configuration of cluster with name: "
                     f"{cluster_name}")
        config = cluster_api.create_user(cluster_name=cluster_name)

        LOGGER.debug(f"Received response from PKS: {self.pks_host_uri} on "
                     f"cluster: {cluster_name} with details: {config}")
        cluster_config = yaml.safe_dump(config, default_flow_style=False)
        return cluster_config
    def get_cluster_config(self, **kwargs):
        """Get the configuration of the cluster with the given name in PKS.

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

        :return: Configuration of the cluster.

        :rtype: str
        """
        data = kwargs[KwargKey.DATA]
        cluster_name = data[RequestKey.CLUSTER_NAME]

        qualified_cluster_name = self._append_user_id(cluster_name)
        if (self.context.client.is_sysadmin()
                or self.context.user.has_org_admin_rights):
            cluster_info = self._get_cluster_info(data)
            qualified_cluster_name = cluster_info['pks_cluster_name']

        self._check_cluster_isolation(cluster_name, qualified_cluster_name)

        cluster_api = ClusterApi(api_client=self.pks_client)

        self.pks_wire_logger.debug(
            f"Sending request to PKS: {self.pks_host_uri} to get"  # noqa: E501
            f" kubectl configuration of cluster with name: "  # noqa: E501
            f"{qualified_cluster_name}")
        config = cluster_api.create_user(cluster_name=qualified_cluster_name)
        self.pks_wire_logger.debug(
            f"Received response from PKS: {self.pks_host_uri} on "  # noqa: E501
            f"cluster: {qualified_cluster_name} with details: "  # noqa: E501
            f"{config}")
        cluster_config = yaml.safe_dump(config, default_flow_style=False)

        return self.filter_traces_of_user_context(cluster_config)