Merge "vFW and vDNS support added to azure-plugin"
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / aria / cli / commands / workflows.py
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements.  See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License.  You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 """
17 CLI ``worfklows`` sub-commands.
18 """
19
20 from .. import table
21 from ..core import aria
22 from ..exceptions import AriaCliError
23
24 WORKFLOW_COLUMNS = ['name', 'service_template_name', 'service_name']
25
26
27 @aria.group(name='workflows')
28 def workflows():
29     """
30     Manage service workflows
31     """
32     pass
33
34
35 @workflows.command(name='show',
36                    short_help='Show information for a service workflow')
37 @aria.argument('workflow-name')
38 @aria.options.service_name(required=True)
39 @aria.options.verbose()
40 @aria.pass_model_storage
41 @aria.pass_logger
42 def show(workflow_name, service_name, model_storage, logger):
43     """
44     Show information for a service workflow
45
46     SERVICE_NAME is the unique name of the service.
47
48     WORKFLOW_NAME is the unique name of the workflow within the service (e.g. "uninstall").
49     """
50     logger.info('Retrieving workflow {0} for service {1}'.format(
51         workflow_name, service_name))
52     service = model_storage.service.get_by_name(service_name)
53     workflow = next((wf for wf in service.workflows.itervalues() if
54                      wf.name == workflow_name), None)
55     if not workflow:
56         raise AriaCliError(
57             'Workflow {0} not found for service {1}'.format(workflow_name, service_name))
58
59     defaults = {
60         'service_template_name': service.service_template_name,
61         'service_name': service.name
62     }
63     table.print_data(WORKFLOW_COLUMNS, workflow, 'Workflows:', defaults=defaults)
64
65     # print workflow inputs
66     required_inputs = dict()
67     optional_inputs = dict()
68     for input_name, input in workflow.inputs.iteritems():
69         inputs_group = optional_inputs if input.value is not None else required_inputs
70         inputs_group[input_name] = input
71
72     logger.info('Workflow Inputs:')
73     logger.info('\tMandatory Inputs:')
74     for input_name, input in required_inputs.iteritems():
75         if input.description is not None:
76             logger.info('\t\t{0}\t({1})'.format(input_name,
77                                                 input.description))
78         else:
79             logger.info('\t\t{0}'.format(input_name))
80
81     logger.info('\tOptional Inputs:')
82     for input_name, input in optional_inputs.iteritems():
83         if input.description is not None:
84             logger.info('\t\t{0}: \t{1}\t({2})'.format(
85                 input_name, input.value, input.description))
86         else:
87             logger.info('\t\t{0}: \t{1}'.format(input_name,
88                                                 input.value))
89
90
91 @workflows.command(name='list',
92                    short_help='List service workflows')
93 @aria.options.service_name(required=True)
94 @aria.options.verbose()
95 @aria.pass_model_storage
96 @aria.pass_logger
97 def list(service_name, model_storage, logger):
98     """
99     List service workflows
100
101     SERVICE_NAME is the unique name of the service.
102     """
103     logger.info('Listing workflows for service {0}...'.format(service_name))
104     service = model_storage.service.get_by_name(service_name)
105     workflows_list = sorted(service.workflows.itervalues(), key=lambda w: w.name)
106
107     defaults = {
108         'service_template_name': service.service_template_name,
109         'service_name': service.name
110     }
111     table.print_data(WORKFLOW_COLUMNS, workflows_list, 'Workflows:', defaults=defaults)