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
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,
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.
17 CLI ``worfklows`` sub-commands.
21 from ..core import aria
22 from ..exceptions import AriaCliError
24 WORKFLOW_COLUMNS = ['name', 'service_template_name', 'service_name']
27 @aria.group(name='workflows')
30 Manage service workflows
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
42 def show(workflow_name, service_name, model_storage, logger):
44 Show information for a service workflow
46 SERVICE_NAME is the unique name of the service.
48 WORKFLOW_NAME is the unique name of the workflow within the service (e.g. "uninstall").
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)
57 'Workflow {0} not found for service {1}'.format(workflow_name, service_name))
60 'service_template_name': service.service_template_name,
61 'service_name': service.name
63 table.print_data(WORKFLOW_COLUMNS, workflow, 'Workflows:', defaults=defaults)
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
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,
79 logger.info('\t\t{0}'.format(input_name))
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))
87 logger.info('\t\t{0}: \t{1}'.format(input_name,
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
97 def list(service_name, model_storage, logger):
99 List service workflows
101 SERVICE_NAME is the unique name of the service.
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)
108 'service_template_name': service.service_template_name,
109 'service_name': service.name
111 table.print_data(WORKFLOW_COLUMNS, workflows_list, 'Workflows:', defaults=defaults)