Exemple #1
0
    def list(self, dict_output=False, field_selector=""):
        """
        Return list of nodes objects/dictionaries
        :param dict_output: to get the elements of the list dictionaries
        instead of objects
        :type dict_output: bool
        :param field_selector: to filter the list to specific nodes
        :type field_selector: str
        :return: list of nodes
        :rtype: list
        """
        nodes_list = self.client_core.list_node().items
        logger.info("Got nodes")

        if field_selector:
            nodes_list = field_filter(obj_list=nodes_list,
                                      field_selector=field_selector)

        # convert the list to list of dicts if required
        if dict_output:
            nodes_list = [
                convert_obj_to_dict(namespace) for namespace in nodes_list
            ]
        else:
            for node in nodes_list:
                node.metadata.resource_version = ''

        return nodes_list
Exemple #2
0
    def list(self,
             namespace=DEFAULT_NAMESPACE,
             all_namespaces=False,
             dict_output=False,
             field_selector=""):
        """
        Return list of deployments objects/dictionaries
        :param namespace: the namespace of the deployment
        (default value is 'default')
        :type namespace: str
        :param all_namespaces: to get the list from all the namespaces
        :type all_namespaces: bool
        :param dict_output: to get the elements of the list dictionaries
        instead of objects
        :type dict_output: bool
        :param field_selector: to filter the list to specific deployments
        :type field_selector: str
        :return: list of deployments
        :rtype: list
        """
        if all_namespaces:
            deployments_list = self.client_app.list_deployment_for_all_namespaces(
            ).items
            logger.info("Got the deployments list from all the namespaces")
        else:
            deployments_list = self.client_app.list_namespaced_deployment(
                namespace=namespace).items
            logger.info(f"Got the deployments list from {namespace} namespace")

        if field_selector:
            deployments_list = field_filter(obj_list=deployments_list,
                                            field_selector=field_selector)

        # convert the list to list of dicts if required
        if dict_output:
            deployments_list = [
                convert_obj_to_dict(deployment)
                for deployment in deployments_list
            ]
        else:
            for deployment in deployments_list:
                deployment.metadata.resource_version = ''

        return deployments_list
Exemple #3
0
 def get(self, name, namespace=DEFAULT_NAMESPACE, dict_output=False):
     """
     Return deployment obj or dictionary
     :param name: deployment name
     :type name: str
     :param namespace: the namespace of the deployment
     (default value is 'default')
     :type namespace: str
     :param dict_output: to return dictionary instead of obj
     :type dict_output: bool
     :return: the deployment obj/dictionary
     :rtype: Union[V1Deployment,dictionary]
     """
     deployment = self.client_app.read_namespaced_deployment(
         name=name, namespace=namespace)
     logger.info(f"Got deployment {name} from {namespace} namespace")
     # convert the obj to dict if required
     if dict_output:
         deployment = convert_obj_to_dict(deployment)
     else:
         deployment.metadata.resource_version = ''
     return deployment
Exemple #4
0
 def get(self, name, namespace=DEFAULT_NAMESPACE, dict_output=False):
     """
     Return secret obj or dictionary
     :param name: secret name
     :type name: str
     :param namespace: the namespace of the secret
     (default value is 'default')
     :type namespace: str
     :param dict_output: to return dictionary instead of obj
     :type dict_output: bool
     :return: the pod obj/dictionary
     :rtype: Union[V1Secret,dictionary]
     """
     secret = self.client_core.read_namespaced_secret(name=name,
                                                      namespace=namespace)
     logger.info(f"Got {name} secret from namespace {namespace}")
     # convert the obj to dict if required
     if dict_output:
         secret = convert_obj_to_dict(secret)
     else:
         secret.metadata.resource_version = ''
     return secret
Exemple #5
0
    def get(self, name, namespace=DEFAULT_NAMESPACE, dict_output=False):
        """
        Return pod obj or dictionary
        :param name: pod name
        :type name: str
        :param namespace: the namespace of the pod (default value is 'default')
        :type namespace: str
        :param dict_output: to return dictionary instead of obj
        :type dict_output: bool
        :return: the pod obj/dictionary
        :rtype: Union[V1Pod,dictionary]
        """
        pod = self.client_core.read_namespaced_pod(name=name,
                                                   namespace=namespace)
        logger.info(f"Got pod {name} from {namespace} namespace")

        # convert the obj to dict if required
        if dict_output:
            pod = convert_obj_to_dict(pod)
        else:
            pod.metadata.resource_version = ''

        return pod