def virt(self): from kubernetes import config import kubevirt cl = config.kube_config._get_kube_config_loader_for_yaml_file(self.path) cl.load_and_set(kubevirt.configuration) return kubevirt.DefaultApi()
def __configure_by_params(self): """ Return API client from configuration file """ auth_args = AUTH_ARG_SPEC.keys() core_configuration = Configuration() for key, value in iteritems(self.params): if key in auth_args and value is not None: if key == 'api_key': setattr( sdk.configuration, key, {'authorization': "Bearer {0}".format(value)}) setattr( core_configuration, key, {'authorization': "Bearer {0}".format(value)}) else: setattr(sdk.configuration, key, value) setattr(core_configuration, key, value) if not self.params.get('verify_ssl'): sdk.configuration.verify_ssl = False core_configuration.verify_ssl = False kube_config.load_kube_config(client_configuration=sdk.configuration) Configuration.set_default(core_configuration) return sdk.DefaultApi(), core_client.CoreV1Api()
def __create_kubevirt_client(self, config_file, verify_ssl, context): sdk.configuration.verify_ssl = verify_ssl kube_config.load_kube_config( config_file=config_file, context=context, client_configuration=sdk.configuration ) return sdk.DefaultApi()
def virt(self): try: from kubernetes import config import kubevirt except ImportError: self.logger.warning( "The kubevirt-python or the kubernetes-python package is missing" ) self.stop() cl = config.kube_config._get_kube_config_loader_for_yaml_file( self.path) cl.load_and_set(kubevirt.configuration) return kubevirt.DefaultApi()
def __configure_by_file(self): """ Return API client from configuration file """ if not self.params.get('kubeconfig'): config_file = os.path.expanduser( kube_config.KUBE_CONFIG_DEFAULT_LOCATION) else: config_file = self.params.get('kubeconfig') try: if not self.params.get('verify_ssl'): sdk.configuration.verify_ssl = False kube_config.load_kube_config( config_file=config_file, context=self.params.get('context'), client_configuration=sdk.configuration) return sdk.DefaultApi() except (IOError, ConfigException): raise
def get_client(kubeconfig=None): """ This function loads kubeconfig and return kubevirt.DefaultApi() object. Args: kubeconfig (str): Path to kubeconfig Returns: kubevirt.DefaultApi: Instance of KubeVirt client """ tokenHandle = open("/var/run/secrets/kubernetes.io/serviceaccount/token", "r") tokenData = tokenHandle.read() kubevirt.configuration.api_key['authorization'] = tokenData kubevirt.configuration.api_key_prefix['authorization'] = 'Bearer' kubevirt.configuration.host = "https://kubernetes.default.svc" kubevirt.configuration.ssl_ca_cert = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" return kubevirt.DefaultApi()
def get_client(kubeconfig=None): """ This function loads kubeconfig and return kubevirt.DefaultApi() object. Args: kubeconfig (str): Path to kubeconfig Returns: kubevirt.DefaultApi: Instance of KubeVirt client """ if kubeconfig is None: kubeconfig = os.environ.get("KUBECONFIG") if kubeconfig is None: kubeconfig = os.path.expanduser("~/.kube/config") cl = config.kube_config._get_kube_config_loader_for_yaml_file(kubeconfig) cl.load_and_set(kubevirt.configuration) return kubevirt.DefaultApi()
def __init__(self, *args, **kwargs): self.kubernetes_client = client # self.kubeconfig = os.path.expanduser("~/.kube/config") self.kubeconfig = os.path.expanduser("/root/config") config.load_kube_config(config_file=self.kubeconfig) kube_config_loader = config.kube_config._get_kube_config_loader_for_yaml_file( self.kubeconfig) kube_config_loader.load_and_set(kubevirt.configuration) self.core_v1 = self.kubernetes_client.CoreV1Api() self.app_v1 = self.kubernetes_client.AppsV1Api() self.api_crd = self.kubernetes_client.CustomObjectsApi() self.ApiException = ApiException self.service_instance = None self.watch = watch.Watch() self.lock = threading.Lock() self.rbac_authorization_v1 = self.kubernetes_client.RbacAuthorizationV1Api( ) self.auto_scaling_v1 = self.kubernetes_client.AutoscalingV1Api() self.kubevirt_client = kubevirt self.kubevirt_api = kubevirt.DefaultApi() self.deployment_status = DeploymentStatus() self.pod_status = PodStatus() self.virtual_machine_status = VirtualMachineStatus() self.virtual_machine_replica_set = VirtualMachineReplicaSetStatus()