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 ``node-templates`` sub-commands.
22 from ..core import aria
25 NODE_TEMPLATE_COLUMNS = ['id', 'name', 'description', 'service_template_name', 'type_name']
28 @aria.group(name='node-templates')
29 @aria.options.verbose()
32 Manages stored service templates' node templates
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
44 def show(node_template_id, model_storage, logger):
46 Show information for a stored node template
48 NODE_TEMPLATE_ID is the unique node template ID.
50 logger.info('Showing node template {0}'.format(node_template_id))
51 node_template = model_storage.node_template.get(node_template_id)
53 table.print_data(NODE_TEMPLATE_COLUMNS, node_template, 'Node template:', col_max_width=50)
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))
60 logger.info('\tNo properties')
63 nodes = node_template.nodes
67 logger.info('\t{0}'.format(node.name))
69 logger.info('\tNo nodes')
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
80 def list(service_template_name, sort_by, descending, model_storage, logger):
82 List stored node templates
84 If SERVICE_TEMPLATE_NAME is provided, list node templates for that stored service template.
85 Otherwise, list node templates for all service templates.
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)
93 logger.info('Listing all node templates...')
96 node_templates_list = model_storage.node_template.list(
98 sort=utils.storage_sort_param(sort_by, descending))
100 table.print_data(NODE_TEMPLATE_COLUMNS, node_templates_list, 'Node templates:')