Пример #1
0
    def versions(self, request, project_id):
        resp = paas_cc.get_cluster_versions(
            request.user.token.access_token,
            kind=cluster_constants.ClusterType[request.project.kind])
        if resp.get('code') != ErrorCode.NoError:
            data = []
        data = [info['version'] for info in resp.get('data') or []]

        return response.Response(data)
Пример #2
0
def get_cluster_versions(access_token, kind="", ver_id="", env=""):
    resp = paas_cc.get_cluster_versions(access_token, kind=kind, ver_id=ver_id, env=env)
    if resp.get('code') != ErrorCode.NoError:
        raise error_codes.APIError(f"get cluster version, {resp.get('message')}")
    data = resp.get("data") or []
    version_list = []
    # 以ID排序,稳定版本排在前面
    data.sort(key=lambda info: info["id"])
    for info in data:
        configure = json.loads(info.get("configure") or "{}")
        version_list.append(
            {"version_id": info["version"], "version_name": configure.get("version_name") or info["version"]}
        )
    return version_list