X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=client%2Fescalatorclient%2Fv1%2Fshell.py;h=10aa1bc4e03991d707749006fcac5cfd73943ecb;hb=3e90898f667afa508137e7be885daa62fbdb86d9;hp=f926a8a6044dd7c07a3d4fbd2eee3b6b26514cb0;hpb=340b19bd919c42d12db1c10d1663ac501a7664f4;p=escalator.git diff --git a/client/escalatorclient/v1/shell.py b/client/escalatorclient/v1/shell.py index f926a8a..10aa1bc 100644 --- a/client/escalatorclient/v1/shell.py +++ b/client/escalatorclient/v1/shell.py @@ -17,11 +17,10 @@ from __future__ import print_function import copy import functools -from oslo_utils import encodeutils from oslo_utils import strutils import escalatorclient.v1.versions +import escalatorclient.v1.clusters from escalatorclient.common import utils -from escalatorclient import exc _bool_strict = functools.partial(strutils.bool_from_string, strict=True) @@ -43,94 +42,47 @@ def do_version(dc, args): fields = dict(filter(lambda x: x[1] is not None, vars(args).items())) # Filter out values we can't use - VERSION_PARAMS = escalatorclient.v1.version.VERSION_PARAMS + VERSION_PARAMS = escalatorclient.v1.versions.VERSION_PARAMS fields = dict(filter(lambda x: x[0] in VERSION_PARAMS, fields.items())) - version = dc.version.version(**fields) + version = dc.versions.version(**fields) _escalator_show(version) -@utils.arg('id', metavar='', - help='Filter version to those that have this id.') -def do_version_detail(dc, args): - """Get backend_types of escalator.""" - version = utils.find_resource(dc.versions, args.id) - _escalator_show(version) - - -@utils.arg('name', metavar='', - help='name of version.') -@utils.arg('type', metavar='', - help='version type.eg redhat7.0...') -@utils.arg('--size', metavar='', - help='size of the version file.') -@utils.arg('--checksum', metavar='', - help='md5 of version file') -@utils.arg('--version', metavar='', - help='version number of version file') -@utils.arg('--description', metavar='', - help='description of version file') -@utils.arg('--status', metavar='', - help='version file status.default:init') -def do_version_add(dc, args): - """Add a version.""" - - fields = dict(filter(lambda x: x[1] is not None, vars(args).items())) - - # Filter out values we can't use - CREATE_PARAMS = escalatorclient.v1.versions.CREATE_PARAMS - fields = dict(filter(lambda x: x[0] in CREATE_PARAMS, fields.items())) - - version = dc.versions.add(**fields) - _escalator_show(version) - - -@utils.arg('id', metavar='', - help='ID of versions.') @utils.arg('--name', metavar='', - help='name of version.') -@utils.arg('--type', metavar='', - help='version type.eg redhat7.0...') -@utils.arg('--size', metavar='', - help='size of the version file.') -@utils.arg('--checksum', metavar='', - help='md5 of version file') -@utils.arg('--version', metavar='', - help='version number of version file') -@utils.arg('--description', metavar='', - help='description of version file') + help='Filter version to those that have this name.') @utils.arg('--status', metavar='', - help='version file status.default:init') -def do_version_update(dc, args): - """Add a version.""" + help='Filter version status.') +@utils.arg('--type', metavar='', + help='Filter by type.') +@utils.arg('--version', metavar='', + help='Filter by version number.') +@utils.arg('--page-size', metavar='', default=None, type=int, + help='Number to request in each paginated request.') +@utils.arg('--sort-key', default='name', + choices=escalatorclient.v1.versions.SORT_KEY_VALUES, + help='Sort version list by specified field.') +@utils.arg('--sort-dir', default='asc', + choices=escalatorclient.v1.versions.SORT_DIR_VALUES, + help='Sort version list in specified direction.') +def do_cluster_version_list(dc, args): + """List hosts you can access.""" + filter_keys = ['name', 'type', 'status', 'version'] + filter_items = [(key, getattr(args, key)) for key in filter_keys] + filters = dict([item for item in filter_items if item[1] is not None]) - fields = dict(filter(lambda x: x[1] is not None, vars(args).items())) + kwargs = {'filters': filters} + if args.page_size is not None: + kwargs['page_size'] = args.page_size - # Filter out values we can't use - CREATE_PARAMS = escalatorclient.v1.versions.CREATE_PARAMS - fields = dict(filter(lambda x: x[0] in CREATE_PARAMS, fields.items())) - version_id = fields.get('id', None) - version = dc.versions.update(version_id, **fields) - _escalator_show(version) + kwargs['sort_key'] = args.sort_key + kwargs['sort_dir'] = args.sort_dir + versions = dc.versions.list(**kwargs) -@utils.arg('id', metavar='', nargs='+', - help='ID of versions.') -def do_version_delete(dc, args): - """Delete specified template(s).""" - fields = dict(filter(lambda x: x[1] is not None, vars(args).items())) - versions = fields.get('id', None) - for version in versions: - try: - if args.verbose: - print('Requesting version delete for %s ...' % - encodeutils.safe_decode(version), end=' ') - dc.versions.delete(version) - if args.verbose: - print('[Done]') - except exc.HTTPException as e: - if args.verbose: - print('[Fail]') - print('%s: Unable to delete version %s' % (e, version)) + columns = ['ID', 'NAME', 'TYPE', 'VERSION', 'size', + 'checksum', 'description', 'status', 'VERSION_PATCH'] + + utils.print_list(versions, columns) @utils.arg('--name', metavar='', @@ -149,9 +101,9 @@ def do_version_delete(dc, args): @utils.arg('--sort-dir', default='asc', choices=escalatorclient.v1.versions.SORT_DIR_VALUES, help='Sort version list in specified direction.') -def do_version_list(dc, args): - """List hosts you can access.""" - filter_keys = ['name', 'type', 'status', 'version'] +def do_cluster_list(gc, args): + """List clusters you can access.""" + filter_keys = ['name'] filter_items = [(key, getattr(args, key)) for key in filter_keys] filters = dict([item for item in filter_items if item[1] is not None]) @@ -162,17 +114,27 @@ def do_version_list(dc, args): kwargs['sort_key'] = args.sort_key kwargs['sort_dir'] = args.sort_dir - versions = dc.versions.list(**kwargs) - - columns = ['ID', 'NAME', 'TYPE', 'VERSION', 'size', - 'checksum', 'description', 'status', 'VERSION_PATCH'] + clusters = gc.clusters.list(**kwargs) - utils.print_list(versions, columns) + columns = ['ID', 'Name', 'Description', 'Nodes', 'Networks', + 'Auto_scale', 'Use_dns', 'Status'] + utils.print_list(clusters, columns) @utils.arg('id', metavar='', - help='Filter version patch to those that have this id.') -def do_version_patch_detail(dc, args): - """Get version_patch of escalator.""" - version = utils.find_resource(dc.version_patchs, args.id) - _escalator_show(version) + help='Filter cluster to those that have this id.') +def do_cluster_detail(gc, args): + """List cluster you can access.""" + filter_keys = ['id'] + filter_items = [(key, getattr(args, key)) for key in filter_keys] + filters = dict([item for item in filter_items if item[1] is not None]) + fields = dict(filter(lambda x: x[1] is not None, vars(args).items())) + kwargs = {'filters': filters} + if filters: + cluster = utils.find_resource(gc.clusters, fields.pop('id')) + _escalator_show(cluster) + else: + cluster = gc.clusters.list(**kwargs) + columns = ['ID', 'Name', 'Description', 'Nodes', + 'Networks', 'Auto_scale', 'Use_dns'] + utils.print_list(cluster, columns)