Example #1
0
def delete_hpa(request, project_id, cluster_id, ns_name, namespace_id, name):
    # 共享集群 HPA 不允许删除
    if get_cluster_type(cluster_id) == ClusterType.SHARED:
        raise DeleteResourceError(_("共享集群 HPA 不支持删除"))

    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 DeleteResourceError(_("删除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,
        )
Example #2
0
 def hpa_client(self, project_id, cluster_id):
     try:
         return hpa_client.HPA(
             CtxCluster.create(token='token',
                               project_id=project_id,
                               id=cluster_id))
     except ResourceNotFoundError:
         pytest.skip('Can not initialize HPA client, skip')
Example #3
0
def get_cluster_hpa_list(request, project_id, cluster_id, namespace=None):
    """获取基础hpa列表"""
    # 共享集群 HPA 不展示
    if get_cluster_type(cluster_id) == ClusterType.SHARED:
        return []

    project_code = request.project.english_name
    hpa_list = []

    try:
        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)
        hpa_list = client.list(formatter=formatter, namespace=namespace)
    except Exception as error:
        logger.error("get hpa list error, %s", error)

    return hpa_list