zun: add 'tty' property to container
This property allows users to open the TTY of the container. It basically allows users to use horizon's console to access the container interactively. For example: resources: test: type: OS::Zun::Container properties: image: "cirros" interactive: true tty: true command: "/bin/sh" Change-Id: I70f64d43ed6d2bcb5bab3e5c8f986ca827df8c6f Closes-Bug: #1856233
This commit is contained in:
parent
ed7add1638
commit
74567b3f08
@ -28,9 +28,9 @@ class ZunClientPlugin(client_plugin.ClientPlugin):
|
|||||||
default_version = '1.12'
|
default_version = '1.12'
|
||||||
|
|
||||||
supported_versions = [
|
supported_versions = [
|
||||||
V1_12, V1_18
|
V1_12, V1_18, V1_36,
|
||||||
] = [
|
] = [
|
||||||
'1.12', '1.18'
|
'1.12', '1.18', '1.36',
|
||||||
]
|
]
|
||||||
|
|
||||||
def _create(self, version=None):
|
def _create(self, version=None):
|
||||||
|
@ -39,12 +39,12 @@ class Container(resource.Resource,
|
|||||||
NAME, IMAGE, COMMAND, CPU, MEMORY,
|
NAME, IMAGE, COMMAND, CPU, MEMORY,
|
||||||
ENVIRONMENT, WORKDIR, LABELS, IMAGE_PULL_POLICY,
|
ENVIRONMENT, WORKDIR, LABELS, IMAGE_PULL_POLICY,
|
||||||
RESTART_POLICY, INTERACTIVE, IMAGE_DRIVER, HINTS,
|
RESTART_POLICY, INTERACTIVE, IMAGE_DRIVER, HINTS,
|
||||||
HOSTNAME, SECURITY_GROUPS, MOUNTS, NETWORKS,
|
HOSTNAME, SECURITY_GROUPS, MOUNTS, NETWORKS, TTY,
|
||||||
) = (
|
) = (
|
||||||
'name', 'image', 'command', 'cpu', 'memory',
|
'name', 'image', 'command', 'cpu', 'memory',
|
||||||
'environment', 'workdir', 'labels', 'image_pull_policy',
|
'environment', 'workdir', 'labels', 'image_pull_policy',
|
||||||
'restart_policy', 'interactive', 'image_driver', 'hints',
|
'restart_policy', 'interactive', 'image_driver', 'hints',
|
||||||
'hostname', 'security_groups', 'mounts', 'networks',
|
'hostname', 'security_groups', 'mounts', 'networks', 'tty',
|
||||||
)
|
)
|
||||||
|
|
||||||
_NETWORK_KEYS = (
|
_NETWORK_KEYS = (
|
||||||
@ -129,6 +129,11 @@ class Container(resource.Resource,
|
|||||||
properties.Schema.BOOLEAN,
|
properties.Schema.BOOLEAN,
|
||||||
_('Keep STDIN open even if not attached.'),
|
_('Keep STDIN open even if not attached.'),
|
||||||
),
|
),
|
||||||
|
TTY: properties.Schema(
|
||||||
|
properties.Schema.BOOLEAN,
|
||||||
|
_('Whether the container allocates a TTY for itself.'),
|
||||||
|
support_status=support.SupportStatus(version='14.0.0'),
|
||||||
|
),
|
||||||
IMAGE_DRIVER: properties.Schema(
|
IMAGE_DRIVER: properties.Schema(
|
||||||
properties.Schema.STRING,
|
properties.Schema.STRING,
|
||||||
_('The image driver to use to pull container image.'),
|
_('The image driver to use to pull container image.'),
|
||||||
@ -320,7 +325,12 @@ class Container(resource.Resource,
|
|||||||
command = args.pop(self.COMMAND, None)
|
command = args.pop(self.COMMAND, None)
|
||||||
if command:
|
if command:
|
||||||
args['command'] = shlex.split(command)
|
args['command'] = shlex.split(command)
|
||||||
container = self.client().containers.run(**args)
|
|
||||||
|
if self.TTY in args:
|
||||||
|
container = self.client(
|
||||||
|
version=self.client_plugin().V1_36).containers.run(**args)
|
||||||
|
else:
|
||||||
|
container = self.client().containers.run(**args)
|
||||||
self.resource_id_set(container.uuid)
|
self.resource_id_set(container.uuid)
|
||||||
return container.uuid
|
return container.uuid
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@ resources:
|
|||||||
image_pull_policy: always
|
image_pull_policy: always
|
||||||
restart_policy: on-failure:2
|
restart_policy: on-failure:2
|
||||||
interactive: false
|
interactive: false
|
||||||
|
tty: false
|
||||||
image_driver: docker
|
image_driver: docker
|
||||||
hints:
|
hints:
|
||||||
hintkey: hintval
|
hintkey: hintval
|
||||||
@ -108,6 +109,7 @@ class ZunContainerTest(common.HeatTestCase):
|
|||||||
self.fake_restart_policy = {'MaximumRetryCount': '2',
|
self.fake_restart_policy = {'MaximumRetryCount': '2',
|
||||||
'Name': 'on-failure'}
|
'Name': 'on-failure'}
|
||||||
self.fake_interactive = False
|
self.fake_interactive = False
|
||||||
|
self.fake_tty = False
|
||||||
self.fake_image_driver = 'docker'
|
self.fake_image_driver = 'docker'
|
||||||
self.fake_hints = {'hintkey': 'hintval'}
|
self.fake_hints = {'hintkey': 'hintval'}
|
||||||
self.fake_hostname = 'myhost'
|
self.fake_hostname = 'myhost'
|
||||||
@ -194,6 +196,7 @@ class ZunContainerTest(common.HeatTestCase):
|
|||||||
value.image_pull_policy = self.fake_image_policy
|
value.image_pull_policy = self.fake_image_policy
|
||||||
value.restart_policy = self.fake_restart_policy
|
value.restart_policy = self.fake_restart_policy
|
||||||
value.interactive = self.fake_interactive
|
value.interactive = self.fake_interactive
|
||||||
|
value.tty = self.fake_tty
|
||||||
value.image_driver = self.fake_image_driver
|
value.image_driver = self.fake_image_driver
|
||||||
value.hints = self.fake_hints
|
value.hints = self.fake_hints
|
||||||
value.hostname = self.fake_hostname
|
value.hostname = self.fake_hostname
|
||||||
@ -248,6 +251,9 @@ class ZunContainerTest(common.HeatTestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.fake_interactive,
|
self.fake_interactive,
|
||||||
c.properties.get(container.Container.INTERACTIVE))
|
c.properties.get(container.Container.INTERACTIVE))
|
||||||
|
self.assertEqual(
|
||||||
|
self.fake_tty,
|
||||||
|
c.properties.get(container.Container.TTY))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.fake_image_driver,
|
self.fake_image_driver,
|
||||||
c.properties.get(container.Container.IMAGE_DRIVER))
|
c.properties.get(container.Container.IMAGE_DRIVER))
|
||||||
@ -283,6 +289,7 @@ class ZunContainerTest(common.HeatTestCase):
|
|||||||
image_pull_policy=self.fake_image_policy,
|
image_pull_policy=self.fake_image_policy,
|
||||||
restart_policy=self.fake_restart_policy,
|
restart_policy=self.fake_restart_policy,
|
||||||
interactive=self.fake_interactive,
|
interactive=self.fake_interactive,
|
||||||
|
tty=self.fake_tty,
|
||||||
image_driver=self.fake_image_driver,
|
image_driver=self.fake_image_driver,
|
||||||
hints=self.fake_hints,
|
hints=self.fake_hints,
|
||||||
hostname=self.fake_hostname,
|
hostname=self.fake_hostname,
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add ``tty`` property to ``OS::Zun::Container``.
|
||||||
|
This property allows users to open the TTY of the container.
|
Loading…
Reference in New Issue
Block a user