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
This commit is contained in:
Feng Shengqin
2017-01-23 01:38:34 +08:00
parent e32dcad8db
commit 62bc41a36b
2 changed files with 6 additions and 2 deletions

View File

@@ -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='<command>',
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)

View File

@@ -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='<command>',
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)