当前位置: 首页>>代码示例>>Python>>正文


Python client.AutoscalingV1Api方法代码示例

本文整理汇总了Python中kubernetes.client.AutoscalingV1Api方法的典型用法代码示例。如果您正苦于以下问题:Python client.AutoscalingV1Api方法的具体用法?Python client.AutoscalingV1Api怎么用?Python client.AutoscalingV1Api使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kubernetes.client的用法示例。


在下文中一共展示了client.AutoscalingV1Api方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: modify_k8s_hpa

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AutoscalingV1Api [as 别名]
def modify_k8s_hpa():
    infos = None
    status = None
    try:
        Infos = request.get_json()
        api_instance = client.AutoscalingV1Api()
        if request.method == 'POST':
            try:
                api_instance.patch_namespaced_horizontal_pod_autoscaler(name=Infos['name'], namespace=namespace,
                                                                          body=client.V1HorizontalPodAutoscaler(
                                                                              spec=client.V1HorizontalPodAutoscalerSpec(
                                                                                  max_replicas=int(Infos['max_update']),
                                                                                  target_cpu_utilization_percentage=int(Infos['cpu_update'].replace('%','')),
                                                                                  scale_target_ref=client.V1CrossVersionObjectReference(
                                                                                      kind='Deployment',
                                                                                      name=Infos['target_ref']))))
            except Exception as e:
                logging.error(e)
                infos = '修改参数失败!'
            else:
                status = 'ok'
                infos = '修改参数成功!'
        if request.method == 'DELETE':
            try:
                api_instance.delete_namespaced_horizontal_pod_autoscaler(name=Infos['name'], namespace=namespace,body=client.V1DeleteOptions())
            except Exception as e:
                logging.error(e)
                infos = '删除%s失败!' %Infos['name']
            else:
                status = 'ok'
                infos = '删除%s成功!' %Infos['name']
    except Exception as e:
        logging.error(e)
    finally:
        return jsonify({'status':status,'infos':infos}) 
开发者ID:wylok,项目名称:sparrow,代码行数:37,代码来源:k8s_manage.py

示例2: __init__

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AutoscalingV1Api [as 别名]
def __init__(self):
        self.logger = logging.getLogger(__name__)
        try:
            config_file = os.path.expanduser(kubeconfig_filepath)
            config.load_kube_config(config_file=config_file)
        except:
            self.logger.warning("unable to load kube-config")

        self.v1 = client.CoreV1Api()
        self.v1Beta1 = client.AppsV1beta1Api()
        self.extensionsV1Beta1 = client.ExtensionsV1beta1Api()
        self.autoscalingV1Api = client.AutoscalingV1Api()
        self.rbacApi = client.RbacAuthorizationV1beta1Api()
        self.batchV1Api = client.BatchV1Api()
        self.batchV2Api = client.BatchV2alpha1Api() 
开发者ID:cloudnativelabs,项目名称:kube-shell,代码行数:17,代码来源:client.py

示例3: get_scaling_api_client

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AutoscalingV1Api [as 别名]
def get_scaling_api_client(self, auth):
        k8s_client = self.get_k8s_client(auth_plugin=auth)
        return client.AutoscalingV1Api(api_client=k8s_client) 
开发者ID:openstack,项目名称:tacker,代码行数:5,代码来源:kubernetes_utils.py

示例4: hpa_apply

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AutoscalingV1Api [as 别名]
def hpa_apply():
    try:
        reload(MyForm)
        form = MyForm.FormK8sHpa()
        if form.submit.data:
            context = form.contexts.data
            deployment = form.deployment.data
            max_replica = form.max_replica.data
            min_replica = form.min_replica.data
            cpu_value = form.cpu_value.data
            if max_replica and min_replica and cpu_value:
                exist_hpa = []
                config.load_kube_config(config_file,context)
                api_instance = client.AutoscalingV1Api()
                try:
                    ret = api_instance.list_horizontal_pod_autoscaler_for_all_namespaces()
                    for i in ret.items:
                        exist_hpa.append(i.spec.scale_target_ref.name)
                    if deployment in exist_hpa:
                        #配置已存在进行更新
                        api_instance.patch_namespaced_horizontal_pod_autoscaler(
                            name='%s-hpa'%deployment, namespace=namespace,
                            body=client.V1HorizontalPodAutoscaler(
                            spec=client.V1HorizontalPodAutoscalerSpec(
                                max_replicas=int(max_replica),
                                min_replicas=int(min_replica),
                                target_cpu_utilization_percentage=int(cpu_value),
                                scale_target_ref=client.V1CrossVersionObjectReference(
                                    api_version='extensions/v1beta1',
                                    kind='Deployment',
                                    name=deployment))
                            ))
                    else:
                        # 配置不存在进行创建
                        api_instance.create_namespaced_horizontal_pod_autoscaler(
                            namespace=namespace,
                            body=client.V1HorizontalPodAutoscaler(
                                metadata=client.V1ObjectMeta(
                                    name='%s-hpa'%deployment,
                                    namespace=namespace),
                            spec=client.V1HorizontalPodAutoscalerSpec(
                                max_replicas=int(max_replica),
                                min_replicas=int(min_replica),
                                target_cpu_utilization_percentage=int(cpu_value),
                                scale_target_ref=client.V1CrossVersionObjectReference(
                                    api_version='extensions/v1beta1',
                                    kind='Deployment',
                                    name=deployment))
                            ))
                    return redirect(url_for('k8s.hpa'))
                except Exception as e:
                    logging.error(e)
    except Exception as e:
        logging.error(e)
        return redirect(url_for('error'))
    return render_template('k8s_hpa.html', form=form) 
开发者ID:wylok,项目名称:sparrow,代码行数:58,代码来源:k8s_deploy.py


注:本文中的kubernetes.client.AutoscalingV1Api方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。