From 62bc41a36b411e66e57f304b6d93b7f898577da6 Mon Sep 17 00:00:00 2001 From: Feng Shengqin Date: Mon, 23 Jan 2017 01:38:34 +0800 Subject: [PATCH] Allow zun exec to take arbitrary number of arguments The patch supports the command and arguments in a different string. For example: zun exec mycontainer echo hello world Change-Id: I403dc744f434e9b09ab5e4f4314e9c1e8fd22913 Closes-Bug: #1651013 --- zunclient/osc/v1/containers.py | 4 +++- zunclient/v1/containers_shell.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/zunclient/osc/v1/containers.py b/zunclient/osc/v1/containers.py index d98aa705..fa1f8f4c 100644 --- a/zunclient/osc/v1/containers.py +++ b/zunclient/osc/v1/containers.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +import argparse import logging from osc_lib.command import command @@ -337,13 +338,14 @@ class ExecContainer(command.Command): parser.add_argument( 'command', metavar='', + nargs=argparse.REMAINDER, help='The command to execute.') return parser def take_action(self, parsed_args): client = _get_client(self, parsed_args) container = parsed_args.container - command = getattr(parsed_args, 'command') + command = ' '.join(parsed_args.command) output = client.containers.execute(container, command) print(output) diff --git a/zunclient/v1/containers_shell.py b/zunclient/v1/containers_shell.py index 971b9c79..75c8f5b4 100644 --- a/zunclient/v1/containers_shell.py +++ b/zunclient/v1/containers_shell.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +import argparse import json from zunclient.common import cliutils as utils @@ -292,10 +293,11 @@ def do_logs(cs, args): help='ID or name of the container to execute command in.') @utils.arg('command', metavar='', + nargs=argparse.REMAINDER, help='The command to execute in a container') def do_exec(cs, args): """Execute command in a container.""" - output = cs.containers.execute(args.container, args.command) + output = cs.containers.execute(args.container, ' '.join(args.command)) print(output)