Policy Reconfiguration, Component Spec, Help text
[dcaegen2/platform/cli.git] / dcae-cli / dcae_cli / commands / profiles / commands.py
1 # ============LICENSE_START=======================================================
2 # org.onap.dcae
3 # ================================================================================
4 # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
18 #
19 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
20
21 # -*- coding: utf-8 -*-
22 """
23 Provides profiles commands
24 """
25 import json
26
27 import click
28
29 from dcae_cli.util.exc import DcaeException
30 from dcae_cli.util.profiles import (get_profiles, activate_profile, get_active_name, update_profile,
31                                     delete_profile, create_profile)
32
33
34 @click.group()
35 def profiles():
36     pass
37
38
39 @profiles.command()
40 @click.argument('name')
41 def activate(name):
42     '''Sets profile (name) as the active profile'''
43     activate_profile(name)
44
45
46 @profiles.command(name='list')
47 def list_profiles():
48     '''Lists available profiles'''
49     profiles = get_profiles(include_active=False)
50     active = get_active_name()
51     names = sorted(profiles.keys())
52     outputs = ("{} {}".format('  ' if not name == active else '* ', name) for name in names)
53     click.echo('\n'.join(outputs))
54
55
56 @profiles.command()
57 @click.argument('name')
58 def show(name):
59     '''Provides more information about a Profile'''
60     profiles = get_profiles()
61     try:
62         click.echo(json.dumps(profiles[name], sort_keys=True, indent=4))
63     except KeyError as e:
64         raise DcaeException("Profile '{}' does not exist.".format(e))
65
66
67 @profiles.command()
68 @click.argument('name', type=click.STRING)
69 def create(name):
70     '''Creates new profile (name), with defaults'''
71     create_profile(name)
72
73
74 @profiles.command(name='set')
75 @click.argument('name')
76 @click.argument('key')
77 @click.argument('value')
78 def update(name, key, value):
79     '''Updates profile (name) for specific Key/Value'''
80     update_profile(name, **{key: value})
81
82
83 @profiles.command()
84 @click.argument('name')
85 def delete(name):
86     '''Deletes profile (name)'''
87     delete_profile(name)