コード例 #1
0
ファイル: client.py プロジェクト: chuanchang/atomicapp
class Client(object):

    def __init__(self, config, provider):
        '''

        Args:
            config (obj): Object of the configuration data
            provider (str): String value of the provider that is being used

        '''
        self.config = config
        self.provider = provider

        # Choose the type of provider that is being used. Error out if it is not available
        if provider is "kubernetes":
            self.connection = KubeKubernetesClient(config)
            logger.debug("Using Kubernetes Provider KubeClient library")
        else:
            raise KubeClientError("No provider by that name.")

    # Create an object using its respective API
    def create(self, obj, namespace="default"):
        self.connection.create(obj, namespace)

    # Delete an object using its respective API
    def delete(self, obj, namespace="default"):
        self.connection.delete(obj, namespace)

    # Current support: kubernetes only
    def namespaces(self):
        return self.connection.namespaces()
コード例 #2
0
def test_delete(mock_class):
    # Mock the API class
    mock_class.return_value = FakeClient()
    mock_class.kind_to_resource_name.return_value = 'Pod'

    k8s_object = {
        "apiVersion": "v1",
        "kind": "Pod",
        "metadata": {
            "labels": {
                "app": "helloapache"
            },
            "name": "helloapache"
        },
        "spec": {
            "containers": [{
                "image":
                "$image",
                "name":
                "helloapache",
                "ports": [{
                    "containerPort": 80,
                    "hostPort": 80,
                    "protocol": "TCP"
                }]
            }]
        }
    }

    a = KubeKubernetesClient(config)
    a.delete(k8s_object, "foobar")
コード例 #3
0
def test_delete(mock_class):
    # Mock the API class
    mock_class.return_value = FakeClient()
    mock_class.kind_to_resource_name.return_value = 'Pod'

    k8s_object = {"apiVersion": "v1", "kind": "Pod", "metadata": {"labels": {"app": "helloapache"}, "name": "helloapache"}, "spec": {
        "containers": [{"image": "$image", "name": "helloapache", "ports": [{"containerPort": 80, "hostPort": 80, "protocol": "TCP"}]}]}}

    a = KubeKubernetesClient(config)
    a.delete(k8s_object, "foobar")
コード例 #4
0
ファイル: client.py プロジェクト: chuanchang/atomicapp
    def __init__(self, config, provider):
        '''

        Args:
            config (obj): Object of the configuration data
            provider (str): String value of the provider that is being used

        '''
        self.config = config
        self.provider = provider

        # Choose the type of provider that is being used. Error out if it is not available
        if provider is "kubernetes":
            self.connection = KubeKubernetesClient(config)
            logger.debug("Using Kubernetes Provider KubeClient library")
        else:
            raise KubeClientError("No provider by that name.")
コード例 #5
0
ファイル: client.py プロジェクト: projectatomic/atomicapp
    def __init__(self, config, provider):
        '''

        Args:
            config (obj): Object of the configuration data
            provider (str): String value of the provider that is being used

        '''
        self.config = config
        self.provider = provider

        # Choose the type of provider that is being used. Error out if it is not available
        if provider is "kubernetes":
            self.connection = KubeKubernetesClient(config)
            logger.debug("Using Kubernetes Provider KubeClient library")
        elif provider is "openshift":
            self.connection = KubeOpenshiftClient(config)
            logger.debug("Using OpenShift Provider KubeClient library")
        else:
            raise KubeClientError("No provider by that name.")