Add support for interactive mode in shell when zun run and create
Part of blueprint support-interactive-mode Change-Id: I0ef8ff4899e2c25d83d0ae36e8aa38c770ab0a59 Signed-off-by: Kevin Zhao <kevin.zhao@linaro.org>
This commit is contained in:
@@ -21,7 +21,7 @@ from zunclient import exceptions
|
|||||||
|
|
||||||
CREATION_ATTRIBUTES = ['name', 'image', 'command', 'cpu', 'memory',
|
CREATION_ATTRIBUTES = ['name', 'image', 'command', 'cpu', 'memory',
|
||||||
'environment', 'workdir', 'labels', 'image_pull_policy',
|
'environment', 'workdir', 'labels', 'image_pull_policy',
|
||||||
'restart_policy']
|
'restart_policy', 'tty', 'stdin_open']
|
||||||
|
|
||||||
|
|
||||||
class Container(base.Resource):
|
class Container(base.Resource):
|
||||||
|
@@ -97,6 +97,16 @@ def _check_restart_policy(policy):
|
|||||||
metavar='<restart>',
|
metavar='<restart>',
|
||||||
help='Restart policy to apply when a container exits'
|
help='Restart policy to apply when a container exits'
|
||||||
'(no, on-failure[:max-retry], always, unless-stopped)')
|
'(no, on-failure[:max-retry], always, unless-stopped)')
|
||||||
|
@utils.arg('-t', '--tty',
|
||||||
|
dest='tty',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='Allocate a pseudo-TTY')
|
||||||
|
@utils.arg('-i', '--interactive',
|
||||||
|
dest='stdin_open',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='Keep STDIN open even if not attached')
|
||||||
def do_create(cs, args):
|
def do_create(cs, args):
|
||||||
"""Create a container."""
|
"""Create a container."""
|
||||||
opts = {}
|
opts = {}
|
||||||
@@ -111,6 +121,10 @@ def do_create(cs, args):
|
|||||||
opts['image_pull_policy'] = args.image_pull_policy
|
opts['image_pull_policy'] = args.image_pull_policy
|
||||||
if args.restart:
|
if args.restart:
|
||||||
opts['restart_policy'] = _check_restart_policy(args.restart)
|
opts['restart_policy'] = _check_restart_policy(args.restart)
|
||||||
|
if args.tty:
|
||||||
|
opts['tty'] = True
|
||||||
|
if args.stdin_open:
|
||||||
|
opts['stdin_open'] = True
|
||||||
_show_container(cs.containers.create(**opts))
|
_show_container(cs.containers.create(**opts))
|
||||||
|
|
||||||
|
|
||||||
@@ -350,6 +364,16 @@ def do_kill(cs, args):
|
|||||||
metavar='<restart>',
|
metavar='<restart>',
|
||||||
help='Restart policy to apply when a container exits'
|
help='Restart policy to apply when a container exits'
|
||||||
'(no, on-failure[:max-retry], always, unless-stopped)')
|
'(no, on-failure[:max-retry], always, unless-stopped)')
|
||||||
|
@utils.arg('-t', '--tty',
|
||||||
|
dest='tty',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='Allocate a pseudo-TTY')
|
||||||
|
@utils.arg('-i', '--interactive',
|
||||||
|
dest='stdin_open',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='Keep STDIN open even if not attached')
|
||||||
def do_run(cs, args):
|
def do_run(cs, args):
|
||||||
"""Run a command in a new container"""
|
"""Run a command in a new container"""
|
||||||
opts = {}
|
opts = {}
|
||||||
@@ -364,6 +388,10 @@ def do_run(cs, args):
|
|||||||
opts['image_pull_policy'] = args.image_pull_policy
|
opts['image_pull_policy'] = args.image_pull_policy
|
||||||
if args.restart:
|
if args.restart:
|
||||||
opts['restart_policy'] = _check_restart_policy(args.restart)
|
opts['restart_policy'] = _check_restart_policy(args.restart)
|
||||||
|
if args.tty:
|
||||||
|
opts['tty'] = True
|
||||||
|
if args.stdin_open:
|
||||||
|
opts['stdin_open'] = True
|
||||||
_show_container(cs.containers.run(**opts))
|
_show_container(cs.containers.run(**opts))
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user