From d931b591e42d3d3e89deb21a8753c721500b6d1b Mon Sep 17 00:00:00 2001 From: tengqm Date: Mon, 2 Mar 2015 14:08:15 +0800 Subject: [PATCH] Added support to profile-update operation --- senlinclient/v1/shell.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py index 295f8439..69b162d3 100644 --- a/senlinclient/v1/shell.py +++ b/senlinclient/v1/shell.py @@ -123,7 +123,7 @@ def _show_profile(sc, profile_id): if profile.type == 'os.heat.stack': formatters['spec'] = utils.nested_dict_formatter( ['disable_rollback', 'environment', 'files', 'parameters', - 'template', 'timeout'], + 'template', 'timeout'], ['property', 'value']) utils.print_dict(profile.to_dict(), formatters=formatters) @@ -166,6 +166,44 @@ def do_profile_show(sc, args): _show_profile(sc, args.id) +@utils.arg('-n', '--name', metavar='', + help=_('The new name for the profile.')) +@utils.arg('-s', '--spec-file', metavar='', + help=_('The new spec file for the profile.')) +@utils.arg('-p', '--permission', metavar='', default='', + help=_('A string format permission for this profile.')) +@utils.arg('-g', '--tags', metavar='', + help=_('Tag values to be attached to the profile. ' + 'This can be specified multiple times, or once with tags' + 'separated by a semicolon.'), + action='append') +@utils.arg('id', metavar='', + help=_('Name or ID of the profile to update.')) +def do_profile_update(sc, args): + '''Update a profile.''' + spec = None + if args.spec_file: + spec = utils.get_spec_content(args.spec_file) + if args.profile_type == 'os.heat.stack': + spec = utils.process_stack_spec(spec) + params = { + 'name': args.name, + 'spec': spec, + 'permission': args.permission, + 'tags': utils.format_parameters(args.tags), + } + + # Find the profile first, we need its id + try: + profile = sc.get(models.Profile, {'id': args.id}) + except exc.HTTPNotFound: + raise exc.CommandError(_('Profile not found: %s') % args.id) + + params['id'] = profile.id + sc.update(models.Profile, params) + _show_profile(sc, args.id) + + @utils.arg('-f', '--force', default=False, action="store_true", help=_('Delete the profile completely from database.')) @utils.arg('id', metavar='', nargs='+',