コード例 #1
0
ファイル: client.py プロジェクト: virtualshuric/kubetest
    def get_events(self, fields=None, labels=None, all_namespaces=False):
        """Get the latest Events that occurred in the cluster.

        Args:
            fields (dict[str, str]): A dictionary of fields used to restrict
                the returned collection of Events to only those which match
                these field selectors. By default, no restricting is done.
            labels (dict[str, str]): A dictionary of labels used to restrict
                the returned collection of Events to only those which match
                these label selectors. By default, no restricting is done.
            all_namespaces (bool): If True, get the events across all
                namespaces.

        Returns:
            dict[str, objects.Event]: A dictionary where the key is the Event
            name and the value is the Event itself.
        """
        selectors = utils.selector_kwargs(fields, labels)

        if all_namespaces:
            event_list = client.CoreV1Api().list_event_for_all_namespaces(
                **selectors
            )
        else:
            event_list = client.CoreV1Api().list_namespaced_event(
                namespace=self.namespace,
                **selectors
            )

        events = {}
        for obj in event_list.items:
            event = objects.Event(obj)
            events[event.name] = event

        return events
コード例 #2
0
    def get_nodes(
            fields: Dict[str, str] = None,
            labels: Dict[str, str] = None,
    ) -> Dict[str, objects.Node]:
        """Get the Nodes that make up the cluster.

        Args:
            fields: A dictionary of fields used to restrict the returned collection
                of Nodes to only those which match these field selectors. By
                default, no restricting is done.
            labels: A dictionary of labels used to restrict the returned collection
                of Nodes to only those which match these label selectors. By
                default, no restricting is done.

        Returns:
            A dictionary where the key is the Node name and the value is the
            Node itself.
        """
        selectors = utils.selector_kwargs(fields, labels)

        results = client.CoreV1Api().list_node(
            **selectors,
        )

        nodes = {}
        for obj in results.items:
            node = objects.Node(obj)
            nodes[node.name] = node

        return nodes
コード例 #3
0
ファイル: client.py プロジェクト: qvicksilver/kubetest
    def get_namespaces(
        self,
        fields: Dict[str, str] = None,
        labels: Dict[str, str] = None,
    ) -> Dict[str, objects.Namespace]:
        """Get Namespaces from the cluster.

        Args:
            fields: A dictionary of fields used to restrict the returned collection
                of Namespaces to only those which match these field selectors. By
                default, no restricting is done.
            labels: A dictionary of labels used to restrict the returned collection
                of Namespaces to only those which match these label selectors. By
                default, no restricting is done.

        Returns:
            A dictionary where the key is the Namespace name and the value is the
            Namespace itself.
        """
        selectors = utils.selector_kwargs(fields, labels)

        results = objects.Namespace.preferred_client().list_namespace(
            **selectors, )

        namespaces = {}
        for obj in results.items:
            namespace = objects.Namespace(obj)
            namespaces[namespace.name] = namespace

        return namespaces
コード例 #4
0
ファイル: client.py プロジェクト: virtualshuric/kubetest
    def get_pods(self, namespace=None, fields=None, labels=None):
        """Get Pods from the cluster.

        Args:
            namespace (str): The namespace to get the Pods from. If not
                specified, it will use the auto-generated test case namespace
                by default.
            fields (dict[str, str]): A dictionary of fields used to restrict
                the returned collection of Pods to only those which match
                these field selectors. By default, no restricting is done.
            labels (dict[str, str]): A dictionary of labels used to restrict
                the returned collection of Pods to only those which match
                these label selectors. By default, no restricting is done.

        Returns:
            dict[str, objects.Pod]: A dictionary where the key is the Pod
            name and the value is the Pod itself.
        """
        if namespace is None:
            namespace = self.namespace

        selectors = utils.selector_kwargs(fields, labels)

        pod_list = client.CoreV1Api().list_namespaced_pod(
            namespace=namespace,
            **selectors,
        )

        pods = {}
        for obj in pod_list.items:
            pod = objects.Pod(obj)
            pods[pod.name] = pod

        return pods
コード例 #5
0
ファイル: client.py プロジェクト: virtualshuric/kubetest
    def get_services(self, namespace=None, fields=None, labels=None):
        """Get Services under the test case namespace.

        Args:
            namespace (str): The namespace to get the Services from. If not
                specified, it will use the auto-generated test case namespace
                by default.
            fields (dict[str, str]): A dictionary of fields used to restrict
                the returned collection of Services to only those which match
                these field selectors. By default, no restricting is done.
            labels (dict[str, str]): A dictionary of labels used to restrict
                the returned collection of Services to only those which match
                these label selectors. By default, no restricting is done.

        Returns:
            dict[str, objects.Service]: A dictionary where the key is the
            Service name and the value is the Service itself.
        """
        if namespace is None:
            namespace = self.namespace

        selectors = utils.selector_kwargs(fields, labels)

        service_list = client.CoreV1Api().list_namespaced_service(
            namespace=namespace,
            **selectors,
        )

        services = {}
        for obj in service_list.items:
            service = objects.Service(obj)
            services[service.name] = service

        return services
コード例 #6
0
ファイル: client.py プロジェクト: virtualshuric/kubetest
    def get_configmaps(self, namespace=None, fields=None, labels=None):
        """Get ConfigMaps from the cluster.

        Args:
            namespace (str): The namespace to get the ConfigMaps from. If not
                specified, it will use the auto-generated test case namespace
                by default.
            fields (dict[str, str]): A dictionary of fields used to restrict
                the returned collection of ConfigMaps to only those which match
                these field selectors. By default, no restricting is done.
            labels (dict[str, str]): A dictionary of labels used to restrict
                the returned collection of ConfigMaps to only those which match
                these label selectors. By default, no restricting is done.

        Returns:
            dict[str, objects.ConfigMap]: A dictionary where the key is the
            ConfigMap name and the value is the ConfigMap itself.
        """
        if namespace is None:
            namespace = self.namespace

        selectors = utils.selector_kwargs(fields, labels)

        configmap_list = client.CoreV1Api().list_namespaced_config_map(
            namespace=namespace,
            **selectors,
        )

        configmaps = {}
        for obj in configmap_list.items:
            cm = objects.ConfigMap(obj)
            configmaps[cm.name] = cm

        return configmaps
コード例 #7
0
ファイル: client.py プロジェクト: virtualshuric/kubetest
    def get_endpoints(self, namespace=None, fields=None, labels=None):
        """Get Endpoints from the cluster.

        Args:
            namespace (str): The namespace to get the Endpoints from. If not
                specified, it will use the auto-generated test case namespace
                by default.
            fields (dict[str, str]): A dictionary of fields used to restrict
                the returned collection of Endpoints to only those which match
                these field selectors. By default, no restricting is done.
            labels (dict[str, str]): A dictionary of labels used to restrict
                the returned collection of Endpoints to only those which match
                these label selectors. By default, no restricting is done.

        Returns:
            dict[str, objects.Endpoints]: A dictionary where the key is
            the Endpoint name and the value is the Endpoint itself.
        """
        if namespace is None:
            namespace = self.namespace

        selectors = utils.selector_kwargs(fields, labels)

        endpoints_list = client.CoreV1Api().list_namespaced_endpoints(
            namespace=namespace,
            **selectors,
        )

        endpoints = {}
        for obj in endpoints_list.items:
            endpoint = objects.Endpoints(obj)
            endpoints[endpoint.name] = endpoint

        return endpoints
コード例 #8
0
ファイル: client.py プロジェクト: virtualshuric/kubetest
    def get_daemonsets(self, namespace=None, fields=None, labels=None):
        """Get DaemonSets from the cluster.

        Args:
            namespace (str): The namespace to get the DaemonSets from. If not
                specified, it will use the auto-generated test case namespace
                by default.
            fields (dict[str, str]): A dictionary of fields used to restrict
                the returned collection of DaemonSets to only those which
                match these field selectors. By default, no restricting is done.
            labels (dict[str, str]): A dictionary of labels used to restrict
                the returned collection of DaemonSets to only those which
                match these label selectors. By default, no restricting is done.

        Returns:
            dict[str, objects.DaemonSet]: A dictionary where the key is
            the DaemonSet name and the value is the DaemonSet itself.
        """
        if namespace is None:
            namespace = self.namespace

        selectors = utils.selector_kwargs(fields, labels)

        daemonset_list = client.AppsV1Api().list_namespaced_daemon_set(
            namespace=namespace,
            **selectors,
        )

        daemonsets = {}
        for obj in daemonset_list.items:
            daemonset = objects.DaemonSet(obj)
            daemonsets[daemonset.name] = daemonset

        return daemonsets
コード例 #9
0
ファイル: client.py プロジェクト: topiaruss/kubetest
    def get_namespaces(self, fields=None, labels=None):
        """Get Namespaces from the cluster.

        Args:
            fields (dict[str, str]): A dictionary of fields used to restrict
                the returned collection of Namespaces to only those which match
                these field selectors. By default, no restricting is done.
            labels (dict[str, str]): A dictionary of labels used to restrict
                the returned collection of Namespaces to only those which match
                these label selectors. By default, no restricting is done.

        Returns:
            dict[str, objects.Namespace]: A dictionary where the key is
            the Namespace name and the value is the Nameself itself.
        """
        selectors = utils.selector_kwargs(fields, labels)

        namespace_list = client.CoreV1Api().list_namespace(**selectors, )

        namespaces = {}
        for obj in namespace_list.items:
            namespace = objects.Namespace(obj)
            namespaces[namespace.name] = namespace

        return namespaces
コード例 #10
0
ファイル: client.py プロジェクト: qvicksilver/kubetest
    def get_persistentvolumeclaims(
        self,
        namespace: str = None,
        fields: Dict[str, str] = None,
        labels: Dict[str, str] = None,
    ) -> Dict[str, objects.PersistentVolumeClaim]:
        """Get PersistentVolumeClaims from the cluster.

        Args:
            namespace: The namespace to get the PersistentVolumeClaim from. If not
                specified, it will use the auto-generated test case namespace
                by default.
            fields: A dictionary of fields used to restrict the returned collection
                of PersistentVolumeClaim to only those which match these field
                selectors. By default, no restricting is done.
            labels: A dictionary of labels used to restrict the returned collection
                of PersistentVolumeClaim to only those which match these label
                selectors. By default, no restricting is done.

        Returns:
            A dictionary where the key is the PersistentVolumeClaim name and the
            value is the PersistentVolumeClaim itself.
        """
        if namespace is None:
            namespace = self.namespace

        selectors = utils.selector_kwargs(fields, labels)

        c = objects.PersistentVolumeClaim.preferred_client()
        results = c.list_namespaced_persistent_volume_claim(
            namespace=namespace,
            **selectors,
        )

        persistentvolumeclaims = {}
        for obj in results.items:
            persistentvolumeclaim = objects.PersistentVolumeClaim(obj)
            persistentvolumeclaims[
                persistentvolumeclaim.name] = persistentvolumeclaim

        return persistentvolumeclaims
コード例 #11
0
ファイル: client.py プロジェクト: rfaircloth-splunk/kubetest
    def get_serviceaccounts(
        self,
        namespace: str = None,
        fields: Dict[str, str] = None,
        labels: Dict[str, str] = None,
    ) -> Dict[str, objects.ServiceAccount]:
        """Get ServiceAccounts from the cluster.

        Args:
            namespace: The namespace to get the ServiceAccount from. If not specified,
                it will use the auto-generated test case namespace by default.
            fields: A dictionary of fields used to restrict the returned collection
                of ServiceAccount to only those which match these field selectors. By
                default, no restricting is done.
            labels: A dictionary of labels used to restrict the returned collection
                of ServiceAccount to only those which match these label selectors. By
                default, no restricting is done.

        Returns:
            A dictionary where the key is the ServiceAccount name and the value is the
            ServiceAccount itself.
        """
        if namespace is None:
            namespace = self.namespace

        selectors = utils.selector_kwargs(fields, labels)

        results = (
            objects.ServiceAccount.preferred_client().list_namespaced_service_account(
                namespace=namespace,
                **selectors,
            )
        )

        serviceaccount = {}
        for obj in results.items:
            cm = objects.ServiceAccount(obj)
            serviceaccount[cm.name] = cm

        return serviceaccount
コード例 #12
0
ファイル: client.py プロジェクト: qvicksilver/kubetest
    def get_replicasets(
        self,
        namespace: str = None,
        fields: Dict[str, str] = None,
        labels: Dict[str, str] = None,
    ) -> Dict[str, objects.ReplicaSet]:
        """Get ReplicaSets from the cluster.

        Args:
            namespace: The namespace to get the ReplicaSets from. If not specified,
                it will use the auto-generated test case namespace by default.
            fields: A dictionary of fields used to restrict the returned collection
                of ReplicaSets to only those which match these field selectors. By
                default, no restricting is done.
            labels: A dictionary of labels used to restrict the returned collection
                of ReplicaSets to only those which match these label selectors. By
                default, no restricting is done.

        Returns:
            A dictionary where the key is the ReplicaSet name and the value is the
            ReplicaSet itself.
        """
        if namespace is None:
            namespace = self.namespace

        selectors = utils.selector_kwargs(fields, labels)

        results = objects.ReplicaSet.preferred_client(
        ).list_namespaced_replica_set(
            namespace=namespace,
            **selectors,
        )

        replicasets = {}
        for obj in results.items:
            rs = objects.ReplicaSet(obj)
            replicasets[replicasets.name] = rs

        return replicasets
コード例 #13
0
    def get_deployments(
            self,
            namespace: str = None,
            fields: Dict[str, str] = None,
            labels: Dict[str, str] = None,
    ) -> Dict[str, objects.Deployment]:
        """Get Deployments from the cluster.

        Args:
            namespace: The namespace to get the Deployments from. If not specified,
                it will use the auto-generated test case namespace by default.
            fields: A dictionary of fields used to restrict the returned collection
                of Deployments to only those which match these field selectors. By
                default, no restricting is done.
            labels: A dictionary of labels used to restrict the returned collection
                of Deployments to only those which match these label selectors. By
                default, no restricting is done.

        Returns:
            A dictionary where the key is the Deployment name and the value is the
            Deployment itself.
        """
        if namespace is None:
            namespace = self.namespace

        selectors = utils.selector_kwargs(fields, labels)

        results = client.AppsV1Api().list_namespaced_deployment(
            namespace=namespace,
            **selectors,
        )

        deployments = {}
        for obj in results.items:
            deployment = objects.Deployment(obj)
            deployments[deployment.name] = deployment

        return deployments
コード例 #14
0
    def get_ingresses(self, namespace=None, fields=None, labels=None):
        """Get Ingresses from the cluster.

        Args:
            namespace (str): The namespace to get the Ingress from. If not
                specified, it will use the auto-generated test case namespace
                by default.
            fields (dict[str, str]): A dictionary of fields used to restrict
                the returned collection of Ingress to only those which match
                these field selectors. By default, no restricting is done.
            labels (dict[str, str]): A dictionary of labels used to restrict
                the returned collection of Ingress to only those which match
                these label selectors. By default, no restricting is done.

        Returns:
            dict[str, objects.Ingress]: A dictionary where the key is
            the Ingress name and the value is the Ingress
            itself.
        """
        if namespace is None:
            namespace = self.namespace

        selectors = utils.selector_kwargs(fields, labels)

        ingress_list = client.CoreV1Api().\
            list_namespaced_ingress(
            namespace=namespace,
            **selectors,
        )

        ingresses = {}
        for obj in ingress_list.items:
            ingress = objects.Ingress(obj)
            ingresses[ingress.name] = ingress

        return ingresses