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 # License for the specific language governing permissions and limitations
# under the License. # under the License.
import argparse
import logging import logging
from osc_lib.command import command from osc_lib.command import command
@@ -337,13 +338,14 @@ class ExecContainer(command.Command):
parser.add_argument( parser.add_argument(
'command', 'command',
metavar='<command>', metavar='<command>',
nargs=argparse.REMAINDER,
help='The command to execute.') help='The command to execute.')
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 = getattr(parsed_args, 'command') command = ' '.join(parsed_args.command)
output = client.containers.execute(container, command) output = client.containers.execute(container, command)
print(output) print(output)

View File

@@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import argparse
import json import json
from zunclient.common import cliutils as utils 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.') help='ID or name of the container to execute command in.')
@utils.arg('command', @utils.arg('command',
metavar='<command>', metavar='<command>',
nargs=argparse.REMAINDER,
help='The command to execute in a container') help='The command to execute in a container')
def do_exec(cs, args): def do_exec(cs, args):
"""Execute command in a container.""" """Execute command in a container."""
output = cs.containers.execute(args.container, args.command) output = cs.containers.execute(args.container, ' '.join(args.command))
print(output) print(output)