本文整理汇总了Python中kubernetes.client.Configuration方法的典型用法代码示例。如果您正苦于以下问题:Python client.Configuration方法的具体用法?Python client.Configuration怎么用?Python client.Configuration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kubernetes.client
的用法示例。
在下文中一共展示了client.Configuration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [as 别名]
def __init__(self, k8s_config=None, k8s_namespace=None, label_selector=None):
from kubernetes import config, client
from gevent.threadpool import ThreadPool
if k8s_config is not None:
self._k8s_config = k8s_config
elif os.environ.get('KUBE_API_ADDRESS'):
self._k8s_config = client.Configuration()
self._k8s_config.host = os.environ['KUBE_API_ADDRESS']
else:
self._k8s_config = config.load_incluster_config()
self._k8s_namespace = k8s_namespace or os.environ.get('MARS_K8S_POD_NAMESPACE') or 'default'
self._label_selector = label_selector
self._client = client.CoreV1Api(client.ApiClient(self._k8s_config))
self._pool = ThreadPool(1)
self._pod_to_ep = None
示例2: delete_node
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [as 别名]
def delete_node(node_name):
"""
Deletes a kubernetes node from the cluster
"""
try:
config.load_incluster_config()
except config.ConfigException:
try:
config.load_kube_config()
except config.ConfigException:
raise Exception("Could not configure kubernetes python client")
configuration = client.Configuration()
# create an instance of the API class
k8s_api = client.CoreV1Api(client.ApiClient(configuration))
logger.info("Deleting k8s node {}...".format(node_name))
try:
if not app_config['DRY_RUN']:
k8s_api.delete_node(node_name)
else:
k8s_api.delete_node(node_name, dry_run="true")
logger.info("Node deleted")
except ApiException as e:
logger.info("Exception when calling CoreV1Api->delete_node: {}".format(e))
示例3: k8s_client_configuration
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [as 别名]
def k8s_client_configuration(self):
for parameter, value in {
KEY_K8S_MASTER_URI: self._k8s_master_uri(),
KEY_K8S_TOKEN: self._k8s_token()
}.items():
if value:
continue
raise RuntimeError(
'{0} parameter is not set. Please, provide {0} via CLI, config or env.'.format(parameter))
configuration = client.Configuration()
configuration.host = self._k8s_master_uri()
if self._k8s_ca_base64():
configuration.ssl_ca_cert = write_file_tmp(b64decode(self._k8s_ca_base64()).encode('utf-8'))
configuration.api_key = {"authorization": "Bearer " + self._k8s_token()}
configuration.debug = self._k8s_handle_debug()
return configuration
示例4: main
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [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)
示例5: print_join_token
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [as 别名]
def print_join_token():
import os
from api.api_client import running_in_docker_container
from kubernetes.client import Configuration
master_ip = Configuration().host.split(':')[1][2:]
master_port = Configuration().host.split(':')[2]
ca_cert = '/etc/kubernetes/pki/ca.crt'
if not os.path.exists(ca_cert):
ca_cert = '/etc/kubernetes/ca.crt'
if running_in_docker_container():
ca_cert = '/tmp' + ca_cert
join_token_path = os.path.dirname(os.path.realpath(__file__)) + '/engine/join_token.sh'
tokens = engine.utils.list_boostrap_tokens_decoded()
if not tokens:
print("No bootstrap tokens exist")
else:
for token in tokens:
command = 'sh ' + join_token_path + ' ' + ' '.join([master_ip, master_port, ca_cert, token])
print('\nExecute: %s' % command)
os.system(command)
示例6: test_k8s_core_client_from_config
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [as 别名]
def test_k8s_core_client_from_config():
with pytest.raises(ConfigException) as err:
k8s.client_from_config(None)
# Client from in-cluster configuration should throws error if it's not
# executed within pod in Kubernetes cluster.
assert err is not None
# If we use valid configuration for Kubernetes client, it should be
# created.
config = k8sclient.Configuration()
config.host = "https://somenonexistedlocation.com:443"
client = k8s.client_from_config(config)
with pytest.raises(MaxRetryError) as err:
# It should when we will use it to call Kubernetes API.
client.list_node()
assert err is not None
示例7: __init__
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [as 别名]
def __init__(self, context, cluster):
self.ca_file = None
self.cert_file = None
self.key_file = None
if cluster.magnum_cert_ref:
(self.ca_file, self.key_file,
self.cert_file) = create_client_files(cluster, context)
config = k8s_config.Configuration()
config.host = cluster.api_address
config.ssl_ca_cert = self.ca_file.name
config.cert_file = self.cert_file.name
config.key_file = self.key_file.name
# build a connection with Kubernetes master
client = ApiClient(configuration=config)
super(K8sAPI, self).__init__(client)
示例8: check_ingresses
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [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
示例9: main
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [as 别名]
def main():
Token = "eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tZGhobWMiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiOThkMDcwZWItODc1Yy0xMWU5LWE1MzgtMDAwYzI5N2I0ZmU3Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.XDFpez2E84R_zlopt_uEHPvVGUtSavypyix6UcYJO3J4imHdJy7MEkfV-wltBA1H8x0TT2AW64rLlXaRJ8OkFWJ0myedfKdjnf7i0oLQ8j-7lw6rT3A0e2pKmpnOaBQfgzRm83-t2I5MMp3Iu9VNUiAbqQpjql4AKwRuJEEGCs99tKStUxzIsJKusmUHh9KAK4BAxySn9h16T2URZ7czLP4mty2crYWNV4KwSwFPthGhFPsl8mnet_hiV5k4me5a8frmXytOy64MmGW8w3TBgiM-7hBYSxt84QGGnyi84LU0EFgtLwBWEOTZeUKKQ6IkoAprMmNcSxX8WUJFlx_uJg"
APISERVER = 'https://192.168.100.111:6443'
configuration = client.Configuration()
configuration.host = APISERVER
configuration.verify_ssl = False
configuration.api_key = {"authorization": "Bearer " + Token}
client.Configuration.set_default(configuration)
v1 = client.CoreV1Api()
ret = v1.list_pod_for_all_namespaces(watch=False)
ret1 = v1.read_namespaced_pod("nginx-58bdcbcd-z8v2s","default")
print(ret1)
# for i in ret.items:
# print("%s\t%s\t%s" %
# (i.status.pod_ip, i.metadata.namespace, i.metadata.name))
示例10: get_k8s_client
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [as 别名]
def get_k8s_client(self, auth_plugin):
config = client.Configuration()
config.host = auth_plugin['auth_url']
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
示例11: __init__
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [as 别名]
def __init__(
self,
namespace: str = None,
k8s_config: Configuration = None,
in_cluster: bool = None,
):
if in_cluster is None:
in_cluster = settings.CLIENT_CONFIG.in_cluster
if not namespace:
namespace = settings.CLIENT_CONFIG.namespace
self.namespace = namespace
self.in_cluster = in_cluster
self.k8s_config = k8s_config
self._k8s_manager = None
示例12: test_refresh_token
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [as 别名]
def test_refresh_token(self):
loader = self.get_test_loader()
config = Configuration()
loader.load_and_set(config)
self.assertEqual('bearer ' + _TEST_TOKEN,
config.get_api_key_with_prefix('authorization'))
self.assertEqual('bearer ' + _TEST_TOKEN, loader.token)
self.assertIsNotNone(loader.token_expires_at)
old_token = loader.token
old_token_expires_at = loader.token_expires_at
loader._token_filename = self._create_file_with_temp_content(
_TEST_NEW_TOKEN)
self.assertEqual('bearer ' + _TEST_TOKEN,
config.get_api_key_with_prefix('authorization'))
loader.token_expires_at = datetime.datetime.now()
self.assertEqual('bearer ' + _TEST_NEW_TOKEN,
config.get_api_key_with_prefix('authorization'))
self.assertEqual('bearer ' + _TEST_NEW_TOKEN, loader.token)
self.assertGreater(loader.token_expires_at, old_token_expires_at)
示例13: get_api_client
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [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)
示例14: get_core_api
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [as 别名]
def get_core_api():
"""
Create instance of Core V1 API of kubernetes:
https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md
:return: instance of client
"""
global core_api
if core_api is None:
config.load_kube_config()
if API_KEY is not None:
# Configure API key authorization: BearerToken
configuration = client.Configuration()
configuration.api_key['authorization'] = API_KEY
configuration.api_key_prefix['authorization'] = 'Bearer'
core_api = client.CoreV1Api(client.ApiClient(configuration))
else:
core_api = client.CoreV1Api()
return core_api
示例15: get_apps_api
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import Configuration [as 别名]
def get_apps_api():
"""
Create instance of Apps V1 API of kubernetes:
https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/AppsV1Api.md
:return: instance of client
"""
global apps_api
if apps_api is None:
config.load_kube_config()
if API_KEY is not None:
# Configure API key authorization: BearerToken
configuration = client.Configuration()
configuration.api_key['authorization'] = API_KEY
configuration.api_key_prefix['authorization'] = 'Bearer'
apps_api = client.AppsV1Api(client.ApiClient(configuration))
else:
apps_api = client.AppsV1Api()
return apps_api