Add Cli support action list and show operation
Change-Id: Ic6cb3e395462022b5f3732bc0abd88c8b6ecb012 Closes-Bug: 1753887
This commit is contained in:
parent
9ffca9fd3d
commit
430e211f7d
@ -68,6 +68,8 @@ openstack.container.v1 =
|
||||
appcontainer_remove_security_group = zunclient.osc.v1.containers:RemoveSecurityGroup
|
||||
appcontainer_image_show = zunclient.osc.v1.images:ShowImage
|
||||
appcontainer_rebuild = zunclient.osc.v1.containers:RebuildContainer
|
||||
appcontainer_action_list = zunclient.osc.v1.containers:ActionList
|
||||
appcontainer_action_show = zunclient.osc.v1.containers:ActionShow
|
||||
|
||||
[build_sphinx]
|
||||
source-dir = doc/source
|
||||
|
@ -37,6 +37,10 @@ def _get_client(obj, parsed_args):
|
||||
return obj.app.client_manager.container
|
||||
|
||||
|
||||
def _action_columns(action):
|
||||
return action._info.keys()
|
||||
|
||||
|
||||
class CreateContainer(command.ShowOne):
|
||||
"""Create a container"""
|
||||
|
||||
@ -1250,3 +1254,52 @@ class NetworkList(command.Lister):
|
||||
network, columns, formatters={
|
||||
'fixed_ips': zun_utils.format_fixed_ips})
|
||||
for network in networks))
|
||||
|
||||
|
||||
class ActionList(command.Lister):
|
||||
"""List actions on a container"""
|
||||
log = logging.getLogger(__name__ + ".ListActions")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ActionList, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'container',
|
||||
metavar='<container>',
|
||||
help='ID or name of the container to list actions.'
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = _get_client(self, parsed_args)
|
||||
container = parsed_args.container
|
||||
actions = client.actions.list(container)
|
||||
columns = ('user_id', 'container_uuid', 'request_id', 'action',
|
||||
'message', 'start_time')
|
||||
return (columns, (utils.get_item_properties(action, columns)
|
||||
for action in actions))
|
||||
|
||||
|
||||
class ActionShow(command.ShowOne):
|
||||
"""Show a action"""
|
||||
|
||||
log = logging.getLogger(__name__ + ".ShowAction")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ActionShow, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'container',
|
||||
metavar='<container>',
|
||||
help='ID or name of the container to show.')
|
||||
parser.add_argument(
|
||||
'request_id',
|
||||
metavar='<request_id>',
|
||||
help='request ID of action to describe.')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = _get_client(self, parsed_args)
|
||||
container = parsed_args.container
|
||||
request_id = parsed_args.request_id
|
||||
action = client.actions.get(container, request_id)
|
||||
columns = _action_columns(action)
|
||||
return columns, utils.get_item_properties(action, columns)
|
||||
|
46
zunclient/v1/actions.py
Normal file
46
zunclient/v1/actions.py
Normal file
@ -0,0 +1,46 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from zunclient.common import base
|
||||
|
||||
|
||||
class Action(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<Action %s>" % self._info
|
||||
|
||||
|
||||
class ActionManager(base.Manager):
|
||||
resource_class = Action
|
||||
|
||||
@staticmethod
|
||||
def _path(container, request_id=None):
|
||||
|
||||
if request_id:
|
||||
return '/v1/containers/%s/container_actions/%s' % (container,
|
||||
request_id)
|
||||
else:
|
||||
return '/v1/containers/%s/container_actions' % container
|
||||
|
||||
def list(self, container):
|
||||
"""Retrieve a list of actions.
|
||||
|
||||
:returns: A list of actions.
|
||||
|
||||
"""
|
||||
|
||||
return self._list(self._path(container), "containerActions")
|
||||
|
||||
def get(self, container, request_id):
|
||||
try:
|
||||
return self._list(self._path(container, request_id))[0]
|
||||
except IndexError:
|
||||
return None
|
44
zunclient/v1/actions_shell.py
Normal file
44
zunclient/v1/actions_shell.py
Normal file
@ -0,0 +1,44 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from zunclient.common import cliutils as utils
|
||||
from zunclient.common import utils as zun_utils
|
||||
|
||||
|
||||
def _show_action(action):
|
||||
utils.print_dict(action._info)
|
||||
|
||||
|
||||
@utils.arg('container',
|
||||
metavar='<container>',
|
||||
help='ID or name of the container to attach network.')
|
||||
def do_action_list(cs, args):
|
||||
"""Print a list of available actions."""
|
||||
container = args.container
|
||||
actions = cs.actions.list(container)
|
||||
columns = ('user_id', 'container_uuid', 'request_id', 'action',
|
||||
'message', 'start_time')
|
||||
utils.print_list(actions, columns,
|
||||
{'versions': zun_utils.print_list_field('versions')},
|
||||
sortby_index=None)
|
||||
|
||||
|
||||
@utils.arg('container',
|
||||
metavar='<container>',
|
||||
help='ID or name of the container whose actions are showed.')
|
||||
@utils.arg('request_id',
|
||||
metavar='<request_id>',
|
||||
help='request ID of action to describe.')
|
||||
def do_action_show(cs, args):
|
||||
"""Describe a specific action."""
|
||||
action = cs.actions.get(args.container, args.request_id)
|
||||
_show_action(action)
|
@ -17,6 +17,7 @@ from keystoneauth1 import loading
|
||||
from keystoneauth1 import session as ksa_session
|
||||
|
||||
from zunclient.common import httpclient
|
||||
from zunclient.v1 import actions
|
||||
from zunclient.v1 import availability_zones as az
|
||||
from zunclient.v1 import capsules
|
||||
from zunclient.v1 import containers
|
||||
@ -129,6 +130,7 @@ class Client(object):
|
||||
self.versions = versions.VersionManager(self.http_client)
|
||||
self.capsules = capsules.CapsuleManager(self.http_client)
|
||||
self.availability_zones = az.AvailabilityZoneManager(self.http_client)
|
||||
self.actions = actions.ActionManager(self.http_client)
|
||||
|
||||
@property
|
||||
def api_version(self):
|
||||
|
@ -13,6 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from zunclient.v1 import actions_shell
|
||||
from zunclient.v1 import availability_zones_shell
|
||||
from zunclient.v1 import capsules_shell
|
||||
from zunclient.v1 import containers_shell
|
||||
@ -29,4 +30,5 @@ COMMAND_MODULES = [
|
||||
hosts_shell,
|
||||
versions_shell,
|
||||
capsules_shell,
|
||||
actions_shell,
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user