1 # Copyright 2012 OpenStack Foundation
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
16 from __future__ import print_function
20 from oslo.utils import strutils
21 import escalatorclient.v1.versions
22 from escalatorclient.common import utils
24 _bool_strict = functools.partial(strutils.bool_from_string, strict=True)
27 def _escalator_show(escalator, max_column_width=80):
28 info = copy.deepcopy(escalator._info)
29 exclusive_field = ('deleted', 'deleted_at')
30 for field in exclusive_field:
33 utils.print_dict(info, max_column_width=max_column_width)
36 @utils.arg('--type', metavar='<TYPE>',
37 help='Type of escalator version, supported type are "internal": '
38 'the internal version of escalator.')
39 def do_version(dc, args):
40 """Get version of escalator."""
41 fields = dict(filter(lambda x: x[1] is not None, vars(args).items()))
43 # Filter out values we can't use
44 VERSION_PARAMS = escalatorclient.v1.versions.VERSION_PARAMS
45 fields = dict(filter(lambda x: x[0] in VERSION_PARAMS, fields.items()))
46 version = dc.versions.version(**fields)
47 _escalator_show(version)
50 @utils.arg('--name', metavar='<NAME>',
51 help='Filter version to those that have this name.')
52 @utils.arg('--status', metavar='<STATUS>',
53 help='Filter version status.')
54 @utils.arg('--type', metavar='<type>',
55 help='Filter by type.')
56 @utils.arg('--version', metavar='<version>',
57 help='Filter by version number.')
58 @utils.arg('--page-size', metavar='<SIZE>', default=None, type=int,
59 help='Number to request in each paginated request.')
60 @utils.arg('--sort-key', default='name',
61 choices=escalatorclient.v1.versions.SORT_KEY_VALUES,
62 help='Sort version list by specified field.')
63 @utils.arg('--sort-dir', default='asc',
64 choices=escalatorclient.v1.versions.SORT_DIR_VALUES,
65 help='Sort version list in specified direction.')
66 def do_cluster_version_list(dc, args):
67 """List hosts you can access."""
68 filter_keys = ['name', 'type', 'status', 'version']
69 filter_items = [(key, getattr(args, key)) for key in filter_keys]
70 filters = dict([item for item in filter_items if item[1] is not None])
72 kwargs = {'filters': filters}
73 if args.page_size is not None:
74 kwargs['page_size'] = args.page_size
76 kwargs['sort_key'] = args.sort_key
77 kwargs['sort_dir'] = args.sort_dir
79 versions = dc.versions.list(**kwargs)
81 columns = ['ID', 'NAME', 'TYPE', 'VERSION', 'size',
82 'checksum', 'description', 'status', 'VERSION_PATCH']
84 utils.print_list(versions, columns)