# coding=utf8

# Copyright 2018 JDCLOUD.COM
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# NOTE: This class is auto generated by the jdcloud code generator program.

import os
from argparse import RawTextHelpFormatter
from jinja2 import Template
from jdcloud_cli.cement.ext.ext_argparse import expose
from jdcloud_cli.controllers.base_controller import BaseController
from jdcloud_cli.client_factory import ClientFactory
from jdcloud_cli.parameter_builder import collect_user_args, collect_user_headers
from jdcloud_cli.printer import Printer
from jdcloud_cli.skeleton import Skeleton


class KubernetesController(BaseController):
    class Meta:
        label = 'kubernetes'
        help = 'kubernetes 集群'
        description = '''
        kubernetes cli 子命令，kubernetes 集群服务。
        OpenAPI文档地址为：https://docs.jdcloud.com/cn/jcs-for-kubernetes/api/overview
        '''
        stacked_on = 'base'
        stacked_type = 'nested'

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--page-number'], dict(help="""(int) 页码；默认为1 """, dest='pageNumber', type=int, required=False)),
            (['--page-size'], dict(help="""(int) 分页大小；默认为20；取值范围[10, 100] """, dest='pageSize', type=int, required=False)),
            (['--tags'], dict(help="""(array: tagFilter) Tag筛选条件 """, dest='tags',  required=False)),
            (['--filters'], dict(help="""(array: filter) name - 节点组名称，模糊匹配，支持单个; id - 节点组 id，支持多个; clusterId - 根据 clusterId 查询; clusterName - 根据 cluster 名称查询;  """, dest='filters',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查询工作节点组列表 ''',
        description='''
            查询工作节点组列表。

            示例: jdc kubernetes describe-node-groups 
        ''',
    )
    def describe_node_groups(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DescribeNodeGroupsRequest import DescribeNodeGroupsRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DescribeNodeGroupsRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--name'], dict(help="""(string) 名称（同一用户的 cluster 内部唯一） """, dest='name',  required=True)),
            (['--description'], dict(help="""(string) 描述 """, dest='description',  required=False)),
            (['--cluster-id'], dict(help="""(string) 工作节点所属的集群 """, dest='clusterId',  required=True)),
            (['--node-config'], dict(help="""(nodeConfigSpec) 工作节点配置信息 """, dest='nodeConfig',  required=True)),
            (['--azs'], dict(help="""(array: string) 工作节点组的 az，必须为集群az的子集，默认为集群az """, dest='azs',  required=False)),
            (['--initial-node-count'], dict(help="""(int) 工作节点组初始化大小 """, dest='initialNodeCount', type=int, required=True)),
            (['--vpc-id'], dict(help="""(string) 工作节点组初始化大小运行的VPC """, dest='vpcId',  required=True)),
            (['--node-cidr'], dict(help="""(string) 工作节点组的cidr """, dest='nodeCidr',  required=False)),
            (['--auto-repair'], dict(help="""(bool) 是否开启工作节点组的自动修复，默认关闭 """, dest='autoRepair',  required=False)),
            (['--ca-config'], dict(help="""(cAConfigSpec) 自动伸缩配置 """, dest='caConfig',  required=False)),
            (['--node-group-network'], dict(help="""(nodeGroupNetworkSpec) 节点组的网络配置，如果集群的类型customized类型，则必须指定该参数，如果是auto，则不是必须 """, dest='nodeGroupNetwork',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 创建工作节点组<br>; - 要求集群状态为running;  ''',
        description='''
            创建工作节点组<br>; - 要求集群状态为running; 。

            示例: jdc kubernetes create-node-group  --name xxx --cluster-id xxx --node-config {"":""} --initial-node-count 5 --vpc-id xxx
        ''',
    )
    def create_node_group(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.CreateNodeGroupRequest import CreateNodeGroupRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = CreateNodeGroupRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--node-group-id'], dict(help="""(string) 工作节点组 ID """, dest='nodeGroupId',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查询单个工作节点组详情 ''',
        description='''
            查询单个工作节点组详情。

            示例: jdc kubernetes describe-node-group  --node-group-id xxx
        ''',
    )
    def describe_node_group(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DescribeNodeGroupRequest import DescribeNodeGroupRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DescribeNodeGroupRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--node-group-id'], dict(help="""(string) 工作节点组 ID """, dest='nodeGroupId',  required=True)),
            (['--name'], dict(help="""(string) 工作节点组名称 """, dest='name',  required=False)),
            (['--description'], dict(help="""(string) 工作节点组描述 """, dest='description',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 修改工作节点组的 名称 和 描述<br>name 和 description 必须要指定一个 ''',
        description='''
            修改工作节点组的 名称 和 描述<br>name 和 description 必须要指定一个。

            示例: jdc kubernetes modify-node-group  --node-group-id xxx
        ''',
    )
    def modify_node_group(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.ModifyNodeGroupRequest import ModifyNodeGroupRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = ModifyNodeGroupRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--node-group-id'], dict(help="""(string) 工作节点组 ID """, dest='nodeGroupId',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 集群摘除工作节点组并删除工作节点组 ''',
        description='''
            集群摘除工作节点组并删除工作节点组。

            示例: jdc kubernetes delete-node-group  --node-group-id xxx
        ''',
    )
    def delete_node_group(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DeleteNodeGroupRequest import DeleteNodeGroupRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DeleteNodeGroupRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--node-group-id'], dict(help="""(string) 工作节点组 ID """, dest='nodeGroupId',  required=True)),
            (['--expect-count'], dict(help="""(int) 预期目标节点数量 """, dest='expectCount', type=int, required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 调整工作节点组实例数量 ''',
        description='''
            调整工作节点组实例数量。

            示例: jdc kubernetes set-node-group-size  --node-group-id xxx --expect-count 5
        ''',
    )
    def set_node_group_size(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.SetNodeGroupSizeRequest import SetNodeGroupSizeRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = SetNodeGroupSizeRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--node-group-id'], dict(help="""(string) 工作节点组 ID """, dest='nodeGroupId',  required=True)),
            (['--enabled'], dict(help="""(bool) 是否开启自动修复 """, dest='enabled',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 设置工作节点组的自动修复 ''',
        description='''
            设置工作节点组的自动修复。

            示例: jdc kubernetes set-auto-repair  --node-group-id xxx --enabled true
        ''',
    )
    def set_auto_repair(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.SetAutoRepairRequest import SetAutoRepairRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = SetAutoRepairRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--node-group-id'], dict(help="""(string) 工作节点组 ID """, dest='nodeGroupId',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 回滚未升级完的工作节点组 ''',
        description='''
            回滚未升级完的工作节点组。

            示例: jdc kubernetes rollback-node-group-upgrade  --node-group-id xxx
        ''',
    )
    def rollback_node_group_upgrade(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.RollbackNodeGroupUpgradeRequest import RollbackNodeGroupUpgradeRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = RollbackNodeGroupUpgradeRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--node-group-id'], dict(help="""(string) 工作节点组 ID """, dest='nodeGroupId',  required=True)),
            (['--ca-config'], dict(help="""(cAConfigSpec) 自动伸缩配置，其中 enable 必须指定 """, dest='caConfig',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 设置工作节点组自动扩容 ''',
        description='''
            设置工作节点组自动扩容。

            示例: jdc kubernetes set-node-group-ca  --node-group-id xxx --ca-config {"":""}
        ''',
    )
    def set_node_group_ca(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.SetNodeGroupCARequest import SetNodeGroupCARequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = SetNodeGroupCARequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--node-group-id'], dict(help="""(string) 工作节点组 ID """, dest='nodeGroupId',  required=True)),
            (['--instance-ids'], dict(help="""(array: string) 需要从工作节点组中删除的实例; - 不可将一个集群中的实例全部删除;  """, dest='instanceIds',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 从工作节点组中删除指定实例 ''',
        description='''
            从工作节点组中删除指定实例。

            示例: jdc kubernetes delete-node-instances  --node-group-id xxx
        ''',
    )
    def delete_node_instances(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DeleteNodeInstancesRequest import DeleteNodeInstancesRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DeleteNodeInstancesRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) Region ID """, dest='regionId',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查询 kubernetes 集群服务配置信息 ''',
        description='''
            查询 kubernetes 集群服务配置信息。

            示例: jdc kubernetes describe-server-config 
        ''',
    )
    def describe_server_config(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DescribeServerConfigRequest import DescribeServerConfigRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DescribeServerConfigRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) Region ID """, dest='regionId',  required=False)),
            (['--master-version'], dict(help="""(string) 集群的大版本，如 1.12.4-jcs.1 """, dest='masterVersion',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查询版本信息 ''',
        description='''
            查询版本信息。

            示例: jdc kubernetes describe-versions 
        ''',
    )
    def describe_versions(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DescribeVersionsRequest import DescribeVersionsRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DescribeVersionsRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) Region ID """, dest='regionId',  required=False)),
            (['--node-version'], dict(help="""(string) 节点版本 """, dest='nodeVersion',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查询节点版本 ''',
        description='''
            查询节点版本。

            示例: jdc kubernetes describe-node-version  --node-version xxx
        ''',
    )
    def describe_node_version(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DescribeNodeVersionRequest import DescribeNodeVersionRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DescribeNodeVersionRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) Region ID """, dest='regionId',  required=False)),
            (['--cluster-id'], dict(help="""(string) 集群 ID """, dest='clusterId',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查询可升级的控制节点版本 ''',
        description='''
            查询可升级的控制节点版本。

            示例: jdc kubernetes describe-upgradable-master-versions  --cluster-id xxx
        ''',
    )
    def describe_upgradable_master_versions(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DescribeUpgradableMasterVersionsRequest import DescribeUpgradableMasterVersionsRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DescribeUpgradableMasterVersionsRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) Region ID """, dest='regionId',  required=False)),
            (['--cluster-id'], dict(help="""(string) 集群 ID """, dest='clusterId',  required=True)),
            (['--node-group-ids'], dict(help="""(array: string) 节点组 id """, dest='nodeGroupIds',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查询可升级的节点版本 ''',
        description='''
            查询可升级的节点版本。

            示例: jdc kubernetes describe-upgradable-node-versions  --cluster-id xxx
        ''',
    )
    def describe_upgradable_node_versions(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DescribeUpgradableNodeVersionsRequest import DescribeUpgradableNodeVersionsRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DescribeUpgradableNodeVersionsRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) Region ID """, dest='regionId',  required=False)),
            (['--filters'], dict(help="""(array: filter) resourceTypes - 资源类型，暂时只支持[kubernetes];  """, dest='filters',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查询 kubernetes 集群配额 ''',
        description='''
            查询 kubernetes 集群配额。

            示例: jdc kubernetes describe-quotas 
        ''',
    )
    def describe_quotas(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DescribeQuotasRequest import DescribeQuotasRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DescribeQuotasRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--page-number'], dict(help="""(int) 页码；默认为1 """, dest='pageNumber', type=int, required=False)),
            (['--page-size'], dict(help="""(int) 分页大小；默认为20；取值范围[10, 100] """, dest='pageSize', type=int, required=False)),
            (['--filters'], dict(help="""(array: filter) name - 集群名称，模糊匹配，仅支持单个   ; id - id，支持多个   ;  """, dest='filters',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查询集群列表 ''',
        description='''
            查询集群列表。

            示例: jdc kubernetes describe-clusters 
        ''',
    )
    def describe_clusters(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DescribeClustersRequest import DescribeClustersRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DescribeClustersRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--name'], dict(help="""(string) 名称（同一用户的 cluster 允许重名） """, dest='name',  required=True)),
            (['--description'], dict(help="""(string) 描述 """, dest='description',  required=False)),
            (['--basic-auth'], dict(help="""(bool) 默认开启 basicAuth与clientCertificate最少选择一个 """, dest='basicAuth',  required=False)),
            (['--client-certificate'], dict(help="""(bool) 默认开启 clientCertificate """, dest='clientCertificate',  required=False)),
            (['--version'], dict(help="""(string) kubernetes的版本 """, dest='version',  required=False)),
            (['--azs'], dict(help="""(array: string) 集群所在的az """, dest='azs',  required=False)),
            (['--node-group'], dict(help="""(nodeGroupSpec) 集群节点组 """, dest='nodeGroup',  required=True)),
            (['--master-cidr'], dict(help="""(string) k8s的master的cidr """, dest='masterCidr',  required=True)),
            (['--access-key'], dict(help="""(string) 用户的AccessKey，插件调用open-api时的认证凭证 """, dest='accessKey',  required=True)),
            (['--secret-key'], dict(help="""(string) 用户的SecretKey，插件调用open-api时的认证凭证 """, dest='secretKey',  required=True)),
            (['--user-metrics'], dict(help="""(bool) deprecated 在addonsConfig中同时指定，将被addonsConfig的设置覆盖 <br>是否启用用户自定义监控 """, dest='userMetrics',  required=False)),
            (['--addons-config'], dict(help="""(array: addonConfigSpec) 集群组件配置 """, dest='addonsConfig',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' - 创建集群; - 证书;   - 关于kubernetes的证书，默认生成，不需要用户传入。; - nodegroup;   - cluster必须与nodeGroup进行绑定;   - cluster支持多nodegroup;   - 状态;     - pending,reconciling,deleting状态不可以操作更新接口;     - running，running_with_error状态可以操作nodegroup所有接口;     - error状态只可以查询，删除;     - delete状态的cluster在十五分钟内可以查询，十五分钟后无法查询到; - 状态限制;   - pending,reconciling,deleting状态不可以操作更新接口;   - running状态可以操作cluster所有接口;   - error状态只可以查询，删除;   - delete状态的cluster在十五分钟内可以查询，十五分钟后无法查询到;  ''',
        description='''
            - 创建集群; - 证书;   - 关于kubernetes的证书，默认生成，不需要用户传入。; - nodegroup;   - cluster必须与nodeGroup进行绑定;   - cluster支持多nodegroup;   - 状态;     - pending,reconciling,deleting状态不可以操作更新接口;     - running，running_with_error状态可以操作nodegroup所有接口;     - error状态只可以查询，删除;     - delete状态的cluster在十五分钟内可以查询，十五分钟后无法查询到; - 状态限制;   - pending,reconciling,deleting状态不可以操作更新接口;   - running状态可以操作cluster所有接口;   - error状态只可以查询，删除;   - delete状态的cluster在十五分钟内可以查询，十五分钟后无法查询到; 。

            示例: jdc kubernetes create-cluster  --name xxx --node-group {"":""} --master-cidr xxx --access-key xxx --secret-key xxx
        ''',
    )
    def create_cluster(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.CreateClusterRequest import CreateClusterRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = CreateClusterRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--cluster-id'], dict(help="""(string) 集群 ID """, dest='clusterId',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查询单个集群详情。 ''',
        description='''
            查询单个集群详情。。

            示例: jdc kubernetes describe-cluster  --cluster-id xxx
        ''',
    )
    def describe_cluster(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DescribeClusterRequest import DescribeClusterRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DescribeClusterRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--cluster-id'], dict(help="""(string) 集群 ID """, dest='clusterId',  required=True)),
            (['--name'], dict(help="""(string) 集群名称 """, dest='name',  required=False)),
            (['--description'], dict(help="""(string) 集群描述 """, dest='description',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 修改集群的 名称 和 描述。<br>集群 name 和 description 必须要指定一个 ''',
        description='''
            修改集群的 名称 和 描述。<br>集群 name 和 description 必须要指定一个。

            示例: jdc kubernetes modify-cluster  --cluster-id xxx
        ''',
    )
    def modify_cluster(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.ModifyClusterRequest import ModifyClusterRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = ModifyClusterRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--cluster-id'], dict(help="""(string) 集群 ID """, dest='clusterId',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 删除集群，以及集群的所有node节点，网络，云盘等所有资源。 ''',
        description='''
            删除集群，以及集群的所有node节点，网络，云盘等所有资源。。

            示例: jdc kubernetes delete-cluster  --cluster-id xxx
        ''',
    )
    def delete_cluster(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DeleteClusterRequest import DeleteClusterRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DeleteClusterRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--cluster-id'], dict(help="""(string) 集群 ID """, dest='clusterId',  required=True)),
            (['--enabled'], dict(help="""(bool) 是否开启自定义监控 """, dest='enabled',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' Deprecated 建议使用 setAddons 接口 <br>设置用户自定义监控状态 ''',
        description='''
            Deprecated 建议使用 setAddons 接口 <br>设置用户自定义监控状态。

            示例: jdc kubernetes set-user-metrics  --cluster-id xxx
        ''',
    )
    def set_user_metrics(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.SetUserMetricsRequest import SetUserMetricsRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = SetUserMetricsRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--cluster-id'], dict(help="""(string) 集群 ID """, dest='clusterId',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 终止升级 ''',
        description='''
            终止升级。

            示例: jdc kubernetes abort-upgrade  --cluster-id xxx
        ''',
    )
    def abort_upgrade(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.AbortUpgradeRequest import AbortUpgradeRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = AbortUpgradeRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--cluster-id'], dict(help="""(string) 集群 ID """, dest='clusterId',  required=True)),
            (['--node-group-ids'], dict(help="""(array: string) 节点组 ID """, dest='nodeGroupIds',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查询集群操作进度 ''',
        description='''
            查询集群操作进度。

            示例: jdc kubernetes describe-progress  --cluster-id xxx
        ''',
    )
    def describe_progress(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DescribeProgressRequest import DescribeProgressRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DescribeProgressRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--cluster-id'], dict(help="""(string) 集群 ID """, dest='clusterId',  required=True)),
            (['--auto-upgrade'], dict(help="""(bool) 开启或者关闭集群自动升级，开启时必须指定 maintenancePolicy """, dest='autoUpgrade',  required=True)),
            (['--maintenance-window'], dict(help="""(maintenanceWindowSpec) 开启集群自动升级, 必须配置集群维护策略 """, dest='maintenanceWindow',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 设置自动升级 ''',
        description='''
            设置自动升级。

            示例: jdc kubernetes set-auto-upgrade  --cluster-id xxx --auto-upgrade true
        ''',
    )
    def set_auto_upgrade(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.SetAutoUpgradeRequest import SetAutoUpgradeRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = SetAutoUpgradeRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--cluster-id'], dict(help="""(string) 集群 ID """, dest='clusterId',  required=True)),
            (['--scope'], dict(help="""(string) 升级范围 """, dest='scope',  required=True)),
            (['--node-group-ids'], dict(help="""(array: string) 节点组 id """, dest='nodeGroupIds',  required=False)),
            (['--version'], dict(help="""(string) 指定升级到的版本 """, dest='version',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 触发升级 ''',
        description='''
            触发升级。

            示例: jdc kubernetes upgrade-cluster  --cluster-id xxx --scope xxx --version xxx
        ''',
    )
    def upgrade_cluster(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.UpgradeClusterRequest import UpgradeClusterRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = UpgradeClusterRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId',  required=False)),
            (['--cluster-id'], dict(help="""(string) 集群 ID """, dest='clusterId',  required=True)),
            (['--addons-config'], dict(help="""(array: addonConfigSpec) 需要设置的集群组件配置 """, dest='addonsConfig',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 设置集群组件 ''',
        description='''
            设置集群组件。

            示例: jdc kubernetes set-addons  --cluster-id xxx --addons-config [{"":""}]
        ''',
    )
    def set_addons(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.SetAddonsRequest import SetAddonsRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = SetAddonsRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--api'], dict(help="""(string) api name """, choices=['describe-node-groups','create-node-group','describe-node-group','modify-node-group','delete-node-group','set-node-group-size','set-auto-repair','rollback-node-group-upgrade','set-node-group-ca','delete-node-instances','describe-server-config','describe-versions','describe-node-version','describe-upgradable-master-versions','describe-upgradable-node-versions','describe-quotas','describe-clusters','create-cluster','describe-cluster','modify-cluster','delete-cluster','set-user-metrics','abort-upgrade','describe-progress','set-auto-upgrade','upgrade-cluster','set-addons',], required=True)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 生成单个API接口的json骨架空字符串 ''',
        description='''
            生成单个API接口的json骨架空字符串。

            示例: jdc nc generate-skeleton --api describeContainer ''',
    )
    def generate_skeleton(self):
        skeleton = Skeleton('kubernetes', self.app.pargs.api)
        skeleton.show()

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域 ID """, dest='regionId', choices=['cn-north-1', 'cn-east-1', 'cn-east-2', 'cn-south-1'], required=False)),
            (['--cluster-id'], dict(help="""(string) 集群 ID """, dest='clusterId', required=True)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 获取密钥凭证 ''',
        description='''
            获取密钥凭证。

            示例: jdc kubernetes get-credential --cluster-id xxx
        ''',
    )
    def get_credential(self):
        client_factory = ClientFactory('kubernetes')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.kubernetes.apis.DescribeClusterRequest import DescribeClusterRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DescribeClusterRequest(params_dict, headers)
            resp = client.send(req)
            if resp.error is not None:
                Printer.print_result(resp)
            else:
                current_dir = os.path.dirname(os.path.abspath(__file__))
                with open('%s/../../resources/kubernetes/config.jinja' % current_dir) as f:
                    content = f.read()

                template = Template(content)
                result = template.render(self._build_credential_data(resp.result['cluster']))
                self._write_credential_file(result)
                Printer.print_text('Generate cluster credential successfully.')

        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    def _build_credential_data(self, cluster):
        masterAuth = cluster['masterAuth']
        return {
            'certificate_authority_data': masterAuth['clusterCaCertificate'],
            'server': 'https://%s:%s' % (cluster['endpoint'], cluster['endpointPort']),
            'username': masterAuth['user'],
            'password': masterAuth['password'],
            'client_certificate_data': masterAuth['clientCertificate'],
            'client_key_data': masterAuth['clientKey'],
            'context_name': 'cert-authentication@kubernetes' if cluster['clientCertificate'] else 'basic-authentication@kubernetes'
        }

    def _write_credential_file(self, content):
        home = os.getenv('HOME')
        kube_dir = '%s/.kube' % home
        if not os.path.exists(kube_dir):
            os.mkdir(kube_dir)

        with open('%s/config' % kube_dir, 'w') as f:
            f.write(content)
