vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / aria / cli / commands / node_templates.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 ``node-templates`` sub-commands.
18 """
19
20 from .. import table
21 from .. import utils
22 from ..core import aria
23
24
25 NODE_TEMPLATE_COLUMNS = ['id', 'name', 'description', 'service_template_name', 'type_name']
26
27
28 @aria.group(name='node-templates')
29 @aria.options.verbose()
30 def node_templates():
31     """
32     Manages stored service templates' node templates
33     """
34     pass
35
36
37 @node_templates.command(name='show',
38                         short_help='Show information for a stored node template')
39 @aria.argument('node-template-id')
40 # @aria.options.service_template_name(required=True)
41 @aria.options.verbose()
42 @aria.pass_model_storage
43 @aria.pass_logger
44 def show(node_template_id, model_storage, logger):
45     """
46     Show information for a stored node template
47
48     NODE_TEMPLATE_ID is the unique node template ID.
49     """
50     logger.info('Showing node template {0}'.format(node_template_id))
51     node_template = model_storage.node_template.get(node_template_id)
52
53     table.print_data(NODE_TEMPLATE_COLUMNS, node_template, 'Node template:', col_max_width=50)
54
55     # print node template properties
56     logger.info('Node template properties:')
57     if node_template.properties:
58         logger.info(utils.get_parameter_templates_as_string(node_template.properties))
59     else:
60         logger.info('\tNo properties')
61
62     # print node IDs
63     nodes = node_template.nodes
64     logger.info('Nodes:')
65     if nodes:
66         for node in nodes:
67             logger.info('\t{0}'.format(node.name))
68     else:
69         logger.info('\tNo nodes')
70
71
72 @node_templates.command(name='list',
73                         short_help='List stored node templates')
74 @aria.options.service_template_name()
75 @aria.options.sort_by('service_template_name')
76 @aria.options.descending
77 @aria.options.verbose()
78 @aria.pass_model_storage
79 @aria.pass_logger
80 def list(service_template_name, sort_by, descending, model_storage, logger):
81     """
82     List stored node templates
83
84     If SERVICE_TEMPLATE_NAME is provided, list node templates for that stored service template.
85     Otherwise, list node templates for all service templates.
86     """
87     if service_template_name:
88         logger.info('Listing node templates for service template {0}...'.format(
89             service_template_name))
90         service_template = model_storage.service_template.get_by_name(service_template_name)
91         filters = dict(service_template=service_template)
92     else:
93         logger.info('Listing all node templates...')
94         filters = {}
95
96     node_templates_list = model_storage.node_template.list(
97         filters=filters,
98         sort=utils.storage_sort_param(sort_by, descending))
99
100     table.print_data(NODE_TEMPLATE_COLUMNS, node_templates_list, 'Node templates:')