Add OSC Plugin for openstack appcontainer run
This change implements the "openstack appcontainer run" command Based on existing zun command: zun run Partially Implements:blueprint zun-osc-plugin Co-Authored-By: Sheel Rana <ranasheel2000@gmail.com> Depends-On: I2120e2ae9bda2eea84f1459f768405bd7c677849 Change-Id: I45afcb2b554f87fc019ec171a83bd7dfae14e5ba
This commit is contained in:
parent
edb07a1be9
commit
cf17711041
@ -44,6 +44,7 @@ openstack.container.v1 =
|
||||
appcontainer_logs = zunclient.osc.v1.containers:LogsContainer
|
||||
appcontainer_kill = zunclient.osc.v1.containers:KillContainer
|
||||
appcontainer_stop = zunclient.osc.v1.containers:StopContainer
|
||||
appcontainer_run = zunclient.osc.v1.containers:RunContainer
|
||||
|
||||
[build_sphinx]
|
||||
source-dir = doc/source
|
||||
|
@ -403,3 +403,77 @@ class StopContainer(command.Command):
|
||||
except Exception as e:
|
||||
print("Stop for container %(container)s failed: %(e)s" %
|
||||
{'container': container, 'e': e})
|
||||
|
||||
|
||||
class RunContainer(command.ShowOne):
|
||||
"""Creates and run a new container"""
|
||||
|
||||
log = logging.getLogger(__name__ + ".RunContainer")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(RunContainer, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
metavar='<name>',
|
||||
help='name of the container')
|
||||
parser.add_argument(
|
||||
'image',
|
||||
metavar='<image>',
|
||||
help='name or ID of the image')
|
||||
parser.add_argument(
|
||||
'--command',
|
||||
metavar='<command>',
|
||||
help='Send command to the container')
|
||||
parser.add_argument(
|
||||
'--cpu',
|
||||
metavar='<cpu>',
|
||||
help='The number of virtual cpus.')
|
||||
parser.add_argument(
|
||||
'--memory',
|
||||
metavar='<memory>',
|
||||
help='The container memory size in MiB')
|
||||
parser.add_argument(
|
||||
'--environment',
|
||||
metavar='<KEY=VALUE>',
|
||||
action='append', default=[],
|
||||
help='The environment variables')
|
||||
parser.add_argument(
|
||||
'--workdir',
|
||||
metavar='<workdir>',
|
||||
help='The working directory for commands to run in')
|
||||
parser.add_argument(
|
||||
'--label',
|
||||
metavar='<KEY=VALUE>',
|
||||
action='append', default=[],
|
||||
help='Adds a map of labels to a container. '
|
||||
'May be used multiple times.')
|
||||
parser.add_argument(
|
||||
'--image-pull-policy',
|
||||
dest='image_pull_policy',
|
||||
metavar='<policy>',
|
||||
choices=['never', 'always', 'ifnotpresent'],
|
||||
help='The policy which determines if the image should '
|
||||
'be pulled prior to starting the container. '
|
||||
'It can have following values: '
|
||||
'"ifnotpresent": only pull the image if it does not '
|
||||
'already exist on the node. '
|
||||
'"always": Always pull the image from repositery.'
|
||||
'"never": never pull the image')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = _get_client(self, parsed_args)
|
||||
opts = {}
|
||||
opts['name'] = parsed_args.name
|
||||
opts['image'] = parsed_args.image
|
||||
opts['command'] = parsed_args.command
|
||||
opts['memory'] = parsed_args.memory
|
||||
opts['cpu'] = parsed_args.cpu
|
||||
opts['environment'] = zun_utils.format_args(parsed_args.environment)
|
||||
opts['workdir'] = parsed_args.workdir
|
||||
opts['labels'] = zun_utils.format_args(parsed_args.label)
|
||||
opts['image_pull_policy'] = parsed_args.image_pull_policy
|
||||
|
||||
container = client.containers.run(**opts)
|
||||
columns = _container_columns(container)
|
||||
return columns, utils.get_item_properties(container, columns)
|
||||
|
Loading…
Reference in New Issue
Block a user