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 ``nodes`` sub-commands.
22 from ..core import aria
25 NODE_COLUMNS = ['id', 'name', 'service_name', 'node_template_name', 'state']
28 @aria.group(name='nodes')
29 @aria.options.verbose()
32 Manage services' nodes
37 @nodes.command(name='show',
38 short_help='Show information for a node')
39 @aria.argument('node_id')
40 @aria.options.verbose()
41 @aria.pass_model_storage
43 def show(node_id, model_storage, logger):
45 Show information for a node
47 NODE_ID is the unique node ID.
49 logger.info('Showing node {0}'.format(node_id))
50 node = model_storage.node.get(node_id)
52 table.print_data(NODE_COLUMNS, node, 'Node:', col_max_width=50)
54 # print node attributes
55 logger.info('Node attributes:')
57 for param_name, param in node.attributes.iteritems():
58 logger.info('\t{0}: {1}'.format(param_name, param.value))
60 logger.info('\tNo attributes')
63 @nodes.command(name='list',
64 short_help='List node')
65 @aria.options.service_name(required=False)
66 @aria.options.sort_by('service_name')
67 @aria.options.descending
68 @aria.options.verbose()
69 @aria.pass_model_storage
71 def list(service_name,
79 If SERVICE_NAME is provided, list nodes for that service. Otherwise, list nodes for all
83 logger.info('Listing nodes for service {0}...'.format(service_name))
84 service = model_storage.service.get_by_name(service_name)
85 filters = dict(service=service)
87 logger.info('Listing all nodes...')
90 nodes_list = model_storage.node.list(
92 sort=utils.storage_sort_param(sort_by, descending))
94 table.print_data(NODE_COLUMNS, nodes_list, 'Nodes:')