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


Python client.ApiClient方法代码示例

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


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

示例1: get_conn

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def get_conn(self):
        """
        Returns kubernetes api session for use with requests
        """
        connection = self.get_connection(self.conn_id)
        extras = connection.extra_dejson
        if extras.get("extra__kubernetes__in_cluster"):
            self.log.debug("loading kube_config from: in_cluster configuration")
            config.load_incluster_config()
        elif extras.get("extra__kubernetes__kube_config") is None:
            self.log.debug("loading kube_config from: default file")
            config.load_kube_config()
        else:
            with tempfile.NamedTemporaryFile() as temp_config:
                self.log.debug("loading kube_config from: connection kube_config")
                temp_config.write(extras.get("extra__kubernetes__kube_config").encode())
                temp_config.flush()
                config.load_kube_config(temp_config.name)
        return client.ApiClient() 
开发者ID:apache,项目名称:airflow,代码行数:21,代码来源:kubernetes.py

示例2: main

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def main():
    # Configs can be set in Configuration class directly or using helper
    # utility. If no argument provided, the config will be loaded from
    # default location.
    config.load_kube_config()
    apps_v1 = client.AppsV1Api()

    # Uncomment the following lines to enable debug logging
    # c = client.Configuration()
    # c.debug = True
    # apps_v1 = client.AppsV1Api(api_client=client.ApiClient(configuration=c))

    # Create a deployment object with client-python API. The deployment we
    # created is same as the `nginx-deployment.yaml` in the /examples folder.
    deployment = create_deployment_object()

    create_deployment(apps_v1, deployment)

    update_deployment(apps_v1, deployment)

    delete_deployment(apps_v1) 
开发者ID:kubernetes-client,项目名称:python,代码行数:23,代码来源:deployment_crud.py

示例3: test_create_apps_deployment_from_yaml

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def test_create_apps_deployment_from_yaml(self):
        """
        Should be able to create an apps/v1 deployment.
        """
        k8s_client = client.api_client.ApiClient(configuration=self.config)
        utils.create_from_yaml(
            k8s_client, self.path_prefix + "apps-deployment.yaml")
        app_api = client.AppsV1Api(k8s_client)
        dep = app_api.read_namespaced_deployment(name="nginx-app",
                                                 namespace="default")
        self.assertIsNotNone(dep)
        while True:
            try:
                app_api.delete_namespaced_deployment(
                    name="nginx-app", namespace="default",
                    body={})
                break
            except ApiException:
                continue 
开发者ID:kubernetes-client,项目名称:python,代码行数:21,代码来源:test_utils.py

示例4: test_create_general_list_from_yaml

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def test_create_general_list_from_yaml(self):
        """
        Should be able to create a service and a deployment
        from a kind: List yaml file
        """
        k8s_client = client.api_client.ApiClient(configuration=self.config)
        utils.create_from_yaml(
            k8s_client, self.path_prefix + "list.yaml")
        core_api = client.CoreV1Api(k8s_client)
        ext_api = client.AppsV1Api(k8s_client)
        svc = core_api.read_namespaced_service(name="list-service-test",
                                               namespace="default")
        self.assertIsNotNone(svc)
        dep = ext_api.read_namespaced_deployment(name="list-deployment-test",
                                                 namespace="default")
        self.assertIsNotNone(dep)
        core_api.delete_namespaced_service(name="list-service-test",
                                           namespace="default", body={})
        ext_api.delete_namespaced_deployment(name="list-deployment-test",
                                             namespace="default", body={}) 
开发者ID:kubernetes-client,项目名称:python,代码行数:22,代码来源:test_utils.py

示例5: test_create_implicit_service_list_from_yaml_with_conflict

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def test_create_implicit_service_list_from_yaml_with_conflict(self):
        """
        Should be able to create two services from a kind: ServiceList
        json file that implicitly indicates the kind of individual objects
        """
        k8s_client = client.api_client.ApiClient(configuration=self.config)
        with self.assertRaises(utils.FailToCreateError):
            utils.create_from_yaml(
                k8s_client, self.path_prefix + "implicit-svclist.json")
        core_api = client.CoreV1Api(k8s_client)
        svc_3 = core_api.read_namespaced_service(name="mock-3",
                                                 namespace="default")
        self.assertIsNotNone(svc_3)
        svc_4 = core_api.read_namespaced_service(name="mock-4",
                                                 namespace="default")
        self.assertIsNotNone(svc_4)
        core_api.delete_namespaced_service(name="mock-3",
                                           namespace="default", body={})
        core_api.delete_namespaced_service(name="mock-4",
                                           namespace="default", body={})

    # Tests for multi-resource yaml objects 
开发者ID:kubernetes-client,项目名称:python,代码行数:24,代码来源:test_utils.py

示例6: test_create_from_multi_resource_yaml

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def test_create_from_multi_resource_yaml(self):
        """
        Should be able to create a service and a replication controller
        from a multi-resource yaml file
        """
        k8s_client = client.api_client.ApiClient(configuration=self.config)
        utils.create_from_yaml(
            k8s_client, self.path_prefix + "multi-resource.yaml")
        core_api = client.CoreV1Api(k8s_client)
        svc = core_api.read_namespaced_service(name="mock",
                                               namespace="default")
        self.assertIsNotNone(svc)
        ctr = core_api.read_namespaced_replication_controller(
            name="mock", namespace="default")
        self.assertIsNotNone(ctr)
        core_api.delete_namespaced_replication_controller(
            name="mock", namespace="default", body={})
        core_api.delete_namespaced_service(name="mock",
                                           namespace="default", body={}) 
开发者ID:kubernetes-client,项目名称:python,代码行数:21,代码来源:test_utils.py

示例7: test_create_namespaced_apps_deployment_from_yaml

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def test_create_namespaced_apps_deployment_from_yaml(self):
        """
        Should be able to create an apps/v1beta1 deployment
		in a test namespace.
        """
        k8s_client = client.api_client.ApiClient(configuration=self.config)
        utils.create_from_yaml(
            k8s_client, self.path_prefix + "apps-deployment.yaml",
            namespace=self.test_namespace)
        app_api = client.AppsV1Api(k8s_client)
        dep = app_api.read_namespaced_deployment(name="nginx-app",
                                                 namespace=self.test_namespace)
        self.assertIsNotNone(dep)
        app_api.delete_namespaced_deployment(
            name="nginx-app", namespace=self.test_namespace,
            body={}) 
开发者ID:kubernetes-client,项目名称:python,代码行数:18,代码来源:test_utils.py

示例8: _connect

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def _connect(self):
        url = '{proto}://{host}:{port}'.format(proto=self.protocol, host=self.hostname,
                                               port=self.port)

        token = 'Bearer {token}'.format(token=self.token)
        config = ociclient.Configuration()
        config.host = url
        config.verify_ssl = self.verify_ssl
        config.debug = self.debug
        config.api_key['authorization'] = token

        self.ociclient = ociclient
        self.kclient = kubeclient
        self.oapi_client = ociclient.ApiClient(config=config)
        self.kapi_client = kubeclient.ApiClient(config=config)
        self.o_api = ociclient.OapiApi(api_client=self.oapi_client)
        self.k_api = kubeclient.CoreV1Api(api_client=self.kapi_client)
        self.security_api = self.ociclient.SecurityOpenshiftIoV1Api(api_client=self.oapi_client)
        self.batch_api = self.kclient.BatchV1Api(api_client=self.kapi_client)  # for job api 
开发者ID:RedHatQE,项目名称:wrapanapi,代码行数:21,代码来源:rhopenshift.py

示例9: load_kube_credentials

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def load_kube_credentials(config: Dict[str, Any]) -> ApiClient:
    # If a context is specified, attempt to use this first.
    try:
        return new_client_from_config(context=config["context"])
    except KeyError:
        pass

    try:
        credentials = config["credentials"]
    except KeyError:
        raise AuthenticationError("Missing kubernetes context.")

    if credentials["kind"] not in ("gcloud",):
        raise AuthenticationError(f"Unknown kubernetes kind: {credentials['kind']}")

    return load_kube_credentials_gcloud(credentials) 
开发者ID:getsentry,项目名称:freight,代码行数:18,代码来源:pipeline.py

示例10: __init__

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def __init__(self) -> None:
        kube_config.load_kube_config(
            config_file=os.environ.get("KUBECONFIG", KUBE_CONFIG_PATH),
            context=os.environ.get("KUBECONTEXT"),
        )
        models.V1beta1PodDisruptionBudgetStatus.disrupted_pods = property(
            fget=lambda *args, **kwargs: models.V1beta1PodDisruptionBudgetStatus.disrupted_pods(
                *args, **kwargs
            ),
            fset=_set_disrupted_pods,
        )
        self.deployments = kube_client.AppsV1Api()
        self.core = kube_client.CoreV1Api()
        self.policy = kube_client.PolicyV1beta1Api()
        self.apiextensions = kube_client.ApiextensionsV1beta1Api()
        self.custom = kube_client.CustomObjectsApi()
        self.autoscaling = kube_client.AutoscalingV2beta1Api()
        self.request = kube_client.ApiClient().request 
开发者ID:Yelp,项目名称:paasta,代码行数:20,代码来源:kubernetes_tools.py

示例11: check_ingresses

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def check_ingresses():
    status = False

    k8s_v1b1 = client.ExtensionsV1beta1Api(client.ApiClient(client.Configuration()))

    if k8s_v1b1:
        try:
            if ambassador_single_namespace:
                k8s_v1b1.list_namespaced_ingress(ambassador_namespace)
            else:
                k8s_v1b1.list_ingress_for_all_namespaces()
            status = True
        except ApiException as e:
            logger.debug(f'Ingress check got {e.status}')

    return status 
开发者ID:datawire,项目名称:ambassador,代码行数:18,代码来源:kubewatch.py

示例12: _configure_k8s

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def _configure_k8s(self):
    k8s_config_file = os.environ.get('KUBECONFIG')
    if k8s_config_file:
      try:
        logging.info('Loading kubernetes config from the file %s', k8s_config_file)
        config.load_kube_config(config_file=k8s_config_file)
      except Exception as e:
        raise RuntimeError('Can not load kube config from the file %s, error: %s', k8s_config_file, e)
    else:
      try:
        config.load_incluster_config()
        logging.info('Initialized with in-cluster config.')
      except:
        logging.info('Cannot find in-cluster config, trying the local kubernetes config. ')
        try:
          config.load_kube_config()
          logging.info('Found local kubernetes config. Initialized with kube_config.')
        except:
          raise RuntimeError('Forgot to run the gcloud command? Check out the link: \
          https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl for more information')
    self._api_client = k8s_client.ApiClient()
    self._corev1 = k8s_client.CoreV1Api(self._api_client)
    return True 
开发者ID:kubeflow,项目名称:pipelines,代码行数:25,代码来源:_k8s_job_helper.py

示例13: get_api_client

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def get_api_client(self):
        """
        Create Kubernetes API client with configuration from string.

        Returns:
            str: Kubeconfig file path

        """

        # This super-ugly code configuration is causes by wrong design of config-loading
        # functions in https://github.com/kubernetes-client/python
        client_config = type.__call__(client.Configuration)
        kubeconfig = self.cluster.get_kubeconfig()
        if kubeconfig is None:
            raise ValueError("Could not create kubernetes API client: kubeconfig is not found ")
        kcl = KubeConfigLoader(
            config_dict=kubeconfig,
        )

        kcl.load_and_set(client_config)
        if self.cluster.provisioner.engine == 'kqueen.engines.OpenstackKubesprayEngine':
            client_config.assert_hostname = False
        return client.ApiClient(configuration=client_config) 
开发者ID:Mirantis,项目名称:kqueen,代码行数:25,代码来源:kubeapi.py

示例14: client

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def client(request):
    return DynamicClient(ApiClient(), discoverer=request.param) 
开发者ID:openshift,项目名称:openshift-restclient-python,代码行数:4,代码来源:test_discoverer.py

示例15: test_port_attach_to_pod

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import ApiClient [as 别名]
def test_port_attach_to_pod(self, mock_uuid):
        static_uuid = uuid.UUID('cf4a56d2-8101-4217-b027-2af6216feb48')
        mock_uuid.return_value = static_uuid
        pod = PodGenerator(image='airflow-worker:latest', name='base').gen_pod()
        ports = [
            Port('https', 443),
            Port('http', 80)
        ]
        k8s_client = ApiClient()
        result = append_to_pod(pod, ports)
        result = k8s_client.sanitize_for_serialization(result)
        self.assertEqual({
            'apiVersion': 'v1',
            'kind': 'Pod',
            'metadata': {'name': 'base-' + static_uuid.hex},
            'spec': {
                'containers': [{
                    'args': [],
                    'command': [],
                    'env': [],
                    'envFrom': [],
                    'image': 'airflow-worker:latest',
                    'name': 'base',
                    'ports': [{
                        'name': 'https',
                        'containerPort': 443
                    }, {
                        'name': 'http',
                        'containerPort': 80
                    }],
                    'volumeMounts': [],
                }],
                'hostNetwork': False,
                'imagePullSecrets': [],
                'volumes': []
            }
        }, result) 
开发者ID:apache,项目名称:airflow,代码行数:39,代码来源:test_pod.py


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