コード例 #1
0
    async def test_create_deployment(self):
        client = api_client.ApiClient(configuration=self.config)
        api = extensions_v1beta1_api.ExtensionsV1beta1Api(client)
        name = 'nginx-deployment-' + str(uuid.uuid4())
        deployment = '''apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: %s
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
'''
        resp = await api.create_namespaced_deployment(
            body=yaml.load(deployment % name),
            namespace="default")
        resp = await api.read_namespaced_deployment(name, 'default')
        self.assertIsNotNone(resp)

        options = v1_delete_options.V1DeleteOptions()
        resp = await api.delete_namespaced_deployment(name, 'default', body=options)
コード例 #2
0
    async def test_create_daemonset(self):
        client = api_client.ApiClient(configuration=self.config)
        api = extensions_v1beta1_api.ExtensionsV1beta1Api(client)
        name = 'nginx-app-' + str(uuid.uuid4())
        daemonset = {
            'apiVersion': 'extensions/v1beta1',
            'kind': 'DaemonSet',
            'metadata': {
                'labels': {'app': 'nginx'},
                'name': '%s' % name,
            },
            'spec': {
                'template': {
                    'metadata': {
                        'labels': {'app': 'nginx'},
                        'name': name},
                    'spec': {
                        'containers': [
                            {'name': 'nginx-app',
                             'image': 'nginx:1.10'},
                        ],
                    },
                },
                'updateStrategy': {
                    'type': 'RollingUpdate',
                },
            }
        }
        resp = await api.create_namespaced_daemon_set('default', body=daemonset)
        resp = await api.read_namespaced_daemon_set(name, 'default')
        self.assertIsNotNone(resp)

        options = v1_delete_options.V1DeleteOptions()
        resp = await api.delete_namespaced_daemon_set(name, 'default', body=options)
コード例 #3
0
    async def test_create_deployment_from_yaml_file(self):
        client = api_client.ApiClient(configuration=self.config)
        api = extensions_v1beta1_api.ExtensionsV1beta1Api(client)
        name = 'nginx-deployment-' + str(uuid.uuid4())
        tempfile = 'temp.yaml'
        deployment = '''apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: %s
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
'''
        with open(tempfile, 'w') as f:
            f.write(deployment % name)
        resp = await utils.create_from_yaml(client, tempfile)
        os.remove(tempfile)
        resp = await api.read_namespaced_deployment(name, 'default')
        self.assertIsNotNone(resp)

        options = v1_delete_options.V1DeleteOptions()
        resp = await api.delete_namespaced_deployment(name,
                                                      'default',
                                                      body=options)