Ejemplo n.º 1
0
def cache_api_host(access_token, project_id, cluster_id, env):
    """cached api host
    cache performance, importance, cluster id shoud be unique
    参数在实例化MesosClient时检查
    """
    if cluster_id:
        cluster = paas_cc.get_cluster(access_token, project_id, cluster_id)
        if cluster.get('code') != 0:
            raise exceptions.ComponentError(cluster.get('message'))
        environment = cluster['data']['environment']
        stag = settings.BCS_API_ENV[environment]
    else:
        stag = env

    return f"{BCS_API_PRE_URL}/{stag}"
Ejemplo n.º 2
0
    def do(self) -> str:
        """通过 PaaS-CC 服务查询查询集群环境名称,然后找到其对应的 API 网关环境名称

        :raises ComponentError: 从 PaaS-CC 返回了错误响应
        """
        # Cache
        if hasattr(self, '_api_env_name'):
            return self._api_env_name

        cluster_resp = self.cluster.comps.paas_cc.get_cluster(self.cluster.project_id, self.cluster.id)
        # TODO: 封装异常,不使用模糊的 ComponentError
        if cluster_resp.get('code') != ErrorCode.NoError:
            raise exceptions.ComponentError(cluster_resp.get('message'))

        environment = cluster_resp['data']['environment']
        self._api_env_name = settings.BCS_API_ENV[environment]
        return self._api_env_name