Add host show CLI

Add host show CLI
I cannot bump the api version to 1.5 as the unit test fail. seem
pecan check the request version to all controller function which
lead to unit test fail.

Change-Id: I4662bde3737b6c0a4c1ea1d51ca67c072f6b3011
Partially-Implements: blueprint show-container-engine-info
This commit is contained in:
ShunliZhou 2017-07-24 14:23:33 +08:00
parent 544be4cb42
commit ae8a0055de
4 changed files with 59 additions and 0 deletions

View File

@ -59,6 +59,7 @@ openstack.container.v1 =
appcontainer_image_list = zunclient.osc.v1.images:ListImage
appcontainer_image_pull = zunclient.osc.v1.images:PullImage
appcontainer_host_list = zunclient.osc.v1.hosts:ListHost
appcontainer_host_show = zunclient.osc.v1.hosts:ShowHost
[build_sphinx]
source-dir = doc/source

View File

@ -16,6 +16,11 @@ from osc_lib.command import command
from osc_lib import utils
def _host_columns(host):
del host._info['links']
return host._info.keys()
def _get_client(obj, parsed_args):
obj.log.debug("take_action(%s)" % parsed_args)
return obj.app.client_manager.container
@ -61,3 +66,25 @@ class ListHost(command.Lister):
columns = ('uuid', 'hostname', 'mem_total', 'cpus', 'os', 'labels')
return (columns, (utils.get_item_properties(host, columns)
for host in hosts))
class ShowHost(command.ShowOne):
"""Show a host"""
log = logging.getLogger(__name__ + ".ShowHost")
def get_parser(self, prog_name):
parser = super(ShowHost, self).get_parser(prog_name)
parser.add_argument(
'host',
metavar='<host>',
help='ID or name of the host to show.')
return parser
def take_action(self, parsed_args):
client = _get_client(self, parsed_args)
host = parsed_args.host
host = client.hosts.get(host)
columns = _host_columns(host)
return columns, utils.get_item_properties(host, columns)

View File

@ -74,3 +74,9 @@ class HostManager(base.Manager):
return self._list_pagination(self._path(path),
"hosts",
limit=limit)
def get(self, id):
try:
return self._list(self._path(id))[0]
except IndexError:
return None

View File

@ -10,6 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import yaml
from zunclient.common import cliutils as utils
from zunclient.common import utils as zun_utils
@ -42,3 +45,25 @@ def do_host_list(cs, args):
utils.print_list(hosts, columns,
{'versions': zun_utils.print_list_field('versions')},
sortby_index=None)
@utils.arg('host',
metavar='<host>',
help='ID or name of the host to show.')
@utils.arg('-f', '--format',
metavar='<format>',
action='store',
choices=['json', 'yaml', 'table'],
default='table',
help='Print representation of the host.'
'The choices of the output format is json,table,yaml.'
'Defaults to table.')
def do_host_show(cs, args):
"""Show details of a host."""
host = cs.hosts.get(args.host)
if args.format == 'json':
print(json.dumps(host._info, indent=4, sort_keys=True))
elif args.format == 'yaml':
print(yaml.safe_dump(host._info, default_flow_style=False))
elif args.format == 'table':
utils.print_dict(host._info)