Add the parameter interactive in ExecContainer

Change-Id: I050c8273975da97c4b8f673be9636963d0b9533c
This commit is contained in:
00129207
2017-07-18 13:30:51 +08:00
parent 9b4f4a389c
commit af050e4cf9

View File

@@ -399,13 +399,28 @@ class ExecContainer(command.Command):
metavar='<command>', metavar='<command>',
nargs=argparse.REMAINDER, nargs=argparse.REMAINDER,
help='The command to execute.') help='The command to execute.')
parser.add_argument(
'--interactive',
dest='interactive',
action='store_true',
default=False,
help='Keep STDIN open and allocate a pseudo-TTY for interactive')
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
client = _get_client(self, parsed_args) client = _get_client(self, parsed_args)
container = parsed_args.container container = parsed_args.container
command = zun_utils.parse_command(parsed_args.command) opts = {}
response = client.containers.execute(container, command=command) opts['command'] = zun_utils.parse_command(parsed_args.command)
if parsed_args.interactive:
opts['interactive'] = True
opts['run'] = False
response = client.containers.execute(container, **opts)
if parsed_args.interactive:
exec_id = response['exec_id']
url = response['url']
websocketclient.do_exec(client, url, container, exec_id, "~", 0.5)
else:
output = response['output'] output = response['output']
exit_code = response['exit_code'] exit_code = response['exit_code']
print(output) print(output)