vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / aria / cli / commands / nodes.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 ``nodes`` sub-commands.
18 """
19
20 from .. import table
21 from .. import utils
22 from ..core import aria
23
24
25 NODE_COLUMNS = ['id', 'name', 'service_name', 'node_template_name', 'state']
26
27
28 @aria.group(name='nodes')
29 @aria.options.verbose()
30 def nodes():
31     """
32     Manage services' nodes
33     """
34     pass
35
36
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
42 @aria.pass_logger
43 def show(node_id, model_storage, logger):
44     """
45     Show information for a node
46
47     NODE_ID is the unique node ID.
48     """
49     logger.info('Showing node {0}'.format(node_id))
50     node = model_storage.node.get(node_id)
51
52     table.print_data(NODE_COLUMNS, node, 'Node:', col_max_width=50)
53
54     # print node attributes
55     logger.info('Node attributes:')
56     if node.attributes:
57         for param_name, param in node.attributes.iteritems():
58             logger.info('\t{0}: {1}'.format(param_name, param.value))
59     else:
60         logger.info('\tNo attributes')
61
62
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
70 @aria.pass_logger
71 def list(service_name,
72          sort_by,
73          descending,
74          model_storage,
75          logger):
76     """
77     List nodes
78
79     If SERVICE_NAME is provided, list nodes for that service. Otherwise, list nodes for all
80     services.
81     """
82     if service_name:
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)
86     else:
87         logger.info('Listing all nodes...')
88         filters = {}
89
90     nodes_list = model_storage.node.list(
91         filters=filters,
92         sort=utils.storage_sort_param(sort_by, descending))
93
94     table.print_data(NODE_COLUMNS, nodes_list, 'Nodes:')