Exemplo n.º 1
0
def delete_hpa(request, project_id, cluster_id, ns_name, namespace_id, name):
    if request.project.kind == ProjectKind.K8S.value:
        ctx_cluster = CtxCluster.create(token=request.user.token.access_token,
                                        project_id=project_id,
                                        id=cluster_id)
        client = hpa_client.HPA(ctx_cluster)
        try:
            client.delete_ignore_nonexistent(name=name, namespace=ns_name)
        except Exception as error:
            logger.error(
                "delete hpa error, namespace: %s, name: %s, error: %s",
                ns_name, name, error)
            raise hpa_exceptions.DeleteHPAError(_("删除HPA资源失败"))

        # 删除成功则更新状态
        InstanceConfig.objects.filter(
            namespace=namespace_id,
            category=K8sResourceName.K8sHPA.value,
            name=name).update(
                updator=request.user.username,
                oper_type=application_constants.DELETE_INSTANCE,
                deleted_time=timezone.now(),
                is_deleted=True,
                is_bcs_success=True,
            )
    else:
        delete_mesos_hpa(request, project_id, cluster_id, ns_name,
                         namespace_id, name)
Exemplo n.º 2
0
def get_cluster_hpa_list(request,
                         project_id,
                         cluster_id,
                         cluster_env,
                         cluster_name,
                         namespace=None):
    """获取基础hpa列表"""
    access_token = request.user.token.access_token
    project_code = request.project.english_name
    hpa_list = []

    try:
        if request.project.kind == ProjectKind.MESOS.value:
            client = mesos.MesosClient(access_token,
                                       project_id,
                                       cluster_id,
                                       env=cluster_env)
            hpa = client.list_hpa(namespace).get("data") or []
            hpa_list = slz_mesos_hpa_info(hpa, project_code, cluster_name,
                                          cluster_env, cluster_id)
        else:
            ctx_cluster = CtxCluster.create(
                token=request.user.token.access_token,
                project_id=project_id,
                id=cluster_id)
            client = hpa_client.HPA(ctx_cluster)
            formatter = HPAFormatter(cluster_id, project_code, cluster_name,
                                     cluster_env)
            hpa_list = client.list(formatter=formatter)
    except Exception as error:
        logger.error("get hpa list error, %s", error)

    return hpa_list
Exemplo n.º 3
0
 def client(self, project_id, cluster_id):
     try:
         client = hpa_client.HPA(
             ClusterAuth('token', project_id, cluster_id))
     except ResourceNotFoundError:
         pytest.skip('Can not initialize HPA client, skip')
     return client
Exemplo n.º 4
0
    def handler_k8shpa(self, ns, cluster_id, spec):
        """下发HPA配置"""
        cluster_auth = ClusterAuth(self.access_token, self.project_id, cluster_id)
        client = hpa_client.HPA(cluster_auth)

        name = spec["metadata"]["name"]
        spec['apiVersion'] = hpa_client.PREFERRED_API_VERSION

        try:
            result = client.update_or_create(spec, name, ns)
            logger.debug("deploy hpa success, %s", result)
        except Exception as error:
            logger.exception('deploy hpa error, %s', error)
            raise Rollback({})
Exemplo n.º 5
0
 def client(self, project_id, cluster_id):
     client = hpa_client.HPA(ClusterAuth('token', project_id, cluster_id))
     return client