How to use the kubernetes.client.api_client.ApiClient function in kubernetes

To help you get started, we’ve selected a few kubernetes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kubernetes-client / python / kubernetes / e2e_test / test_utils.py View on Github external
def test_create_namespace_list_from_yaml(self):
        """
        Should be able to create two namespaces
        from a kind: NamespaceList yaml file
        """
        k8s_client = client.api_client.ApiClient(configuration=self.config)
        utils.create_from_yaml(
            k8s_client, self.path_prefix + "namespace-list.yaml")
        core_api = client.CoreV1Api(k8s_client)
        nmsp_1 = core_api.read_namespace(name="mock-1")
        self.assertIsNotNone(nmsp_1)
        nmsp_2 = core_api.read_namespace(name="mock-2")
        self.assertIsNotNone(nmsp_2)
        core_api.delete_namespace(name="mock-1", body={})
        core_api.delete_namespace(name="mock-2", body={})
github kubernetes-client / python / kubernetes / e2e_test / test_utils.py View on Github external
def test_create_service_from_yaml(self):
        """
        Should be able to create a service.
        """
        k8s_client = client.api_client.ApiClient(configuration=self.config)
        utils.create_from_yaml(
            k8s_client, self.path_prefix + "core-service.yaml")
        core_api = client.CoreV1Api(k8s_client)
        svc = core_api.read_namespaced_service(name="my-service",
                                               namespace="default")
        self.assertIsNotNone(svc)
        core_api.delete_namespaced_service(
            name="my-service", namespace="default",
            body={})
github kubernetes-client / python / kubernetes / e2e_test / test_utils.py View on Github external
def test_create_pod_from_yaml(self):
        """
        Should be able to create a pod.
        """
        k8s_client = client.api_client.ApiClient(configuration=self.config)
        utils.create_from_yaml(
            k8s_client, self.path_prefix + "core-pod.yaml")
        core_api = client.CoreV1Api(k8s_client)
        pod = core_api.read_namespaced_pod(name="myapp-pod",
                                           namespace="default")
        self.assertIsNotNone(pod)
        core_api.delete_namespaced_pod(
            name="myapp-pod", namespace="default",
            body={})
github openstack / tacker / tacker / common / container / kubernetes_utils.py View on Github external
if ('username' in auth_plugin) and ('password' in auth_plugin)\
                and (auth_plugin['password'] is not None):
            config.username = auth_plugin['username']
            config.password = auth_plugin['password']
            basic_token = config.get_basic_auth_token()
            config.api_key['authorization'] = basic_token
        if 'bearer_token' in auth_plugin:
            config.api_key_prefix['authorization'] = 'Bearer'
            config.api_key['authorization'] = auth_plugin['bearer_token']
        ca_cert_file = auth_plugin.get('ca_cert_file')
        if ca_cert_file is not None:
            config.ssl_ca_cert = ca_cert_file
            config.verify_ssl = True
        else:
            config.verify_ssl = False
        k8s_client = api_client.ApiClient(configuration=config)
        return k8s_client
github openstack / rally-openstack / rally_openstack / scenarios / magnum / utils.py View on Github external
ca_certs = cluster_uuid + "_ca.crt"
            ca_certs = os.path.join(dir, ca_certs)
        if hasattr(k8s_config, "ConfigurationObject"):
            # k8sclient < 4.0.0
            config = k8s_config.ConfigurationObject()
        else:
            config = k8s_config.Configuration()
        config.host = cluster.api_address
        config.ssl_ca_cert = ca_certs
        config.cert_file = cert_file
        config.key_file = key_file
        if hasattr(k8s_config, "ConfigurationObject"):
            # k8sclient < 4.0.0
            client = api_client.ApiClient(config=config)
        else:
            client = api_client.ApiClient(config)

        return core_v1_api.CoreV1Api(client)
github kubernetes-client / python / kubernetes / client / apis / apiextensions_v1beta1_api.py View on Github external
def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client
github xrally / xrally-kubernetes / xrally_kubernetes / service.py View on Github external
if self._spec.get("api_key"):
            config.api_key = {"authorization": self._spec["api_key"]}
            if self._spec.get("api_key_prefix"):
                config.api_key_prefix = {
                    "authorization": self._spec["api_key_prefix"]}
        else:
            config.cert_file = self._spec["client-certificate"]
            config.key_file = self._spec["client-key"]
            if self._spec.get("tls_insecure", False):
                config.verify_ssl = False

        config.assert_hostname = False
        if self._k8s_client_version == 3:
            api = api_client.ApiClient(config=config)
        else:
            api = api_client.ApiClient(configuration=config)

        self.api = api
        self.v1_client = core_v1_api.CoreV1Api(api)
        self.v1_batch = batch_v1_api.BatchV1Api(api)
        self.v1_apps = apps_v1_api.AppsV1Api(api)
        self.v1_storage = storage_v1_api.StorageV1Api(api)
github kubernetes-client / python / kubernetes / client / api / auditregistration_api.py View on Github external
def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client
github openstack / rally / rally / plugins / openstack / scenarios / magnum / utils.py View on Github external
key_file = cluster_uuid + ".key"
            key_file = os.path.join(dir, key_file)
            cert_file = cluster_uuid + ".crt"
            cert_file = os.path.join(dir, cert_file)
            ca_certs = cluster_uuid + "_ca.crt"
            ca_certs = os.path.join(dir, ca_certs)
        if hasattr(k8s_config, "ConfigurationObject"):
            # k8sclient < 4.0.0
            config = k8s_config.ConfigurationObject()
        else:
            config = k8s_config.Configuration()
        config.host = cluster.api_address
        config.ssl_ca_cert = ca_certs
        config.cert_file = cert_file
        config.key_file = key_file
        client = api_client.ApiClient(config=config)
        return core_v1_api.CoreV1Api(client)