Skip to content

Commit a6ceda1

Browse files
authored
CY-873 cfy profiles show: show cluster nodes (#887)
* CY-873 cfy profiles show: show cluster nodes Instead of showing just the profile data which contains a single manager_ip, if the current profile is a cluster profile, show all stored nodes * Factor out a function
1 parent ef799c5 commit a6ceda1

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

cloudify_cli/commands/profiles.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
PROFILE_COLUMNS = ['name', 'manager_ip', 'manager_username', 'manager_tenant',
4040
'ssh_user', 'ssh_key_path', 'ssh_port', 'kerberos_env',
4141
'rest_port', 'rest_protocol', 'rest_certificate']
42+
CLUSTER_PROFILE_COLUMNS = ['profile_name', 'cluster_node_name'] \
43+
+ PROFILE_COLUMNS[1:]
4244

4345

4446
@cfy.group(name='profiles')
@@ -57,6 +59,24 @@ def profiles():
5759
init.init_local_profile()
5860

5961

62+
def _format_cluster_profile(profile):
63+
"""Format the list of cluster nodes for display
64+
65+
In `cfy cluster show`, we show the profile details of every stored
66+
cluster node.
67+
"""
68+
common_attributes = {k: profile.get(k) for k in PROFILE_COLUMNS}
69+
nodes = []
70+
for node in profile['cluster']:
71+
# merge the common attrs with node data, but rename node's name
72+
# attribute to cluster_node, because the attribute 'name' is
73+
# reserved for the profile name
74+
node_data = dict(node)
75+
node_data['cluster_node_name'] = node_data.pop('name')
76+
nodes.append(dict(common_attributes, **node_data))
77+
return nodes
78+
79+
6080
@profiles.command(name='show-current',
6181
short_help='Retrieve current profile information')
6282
@cfy.options.common_options
@@ -71,7 +91,18 @@ def show(logger):
7191
return
7292

7393
active_profile = _get_profile(env.get_active_profile())
74-
print_single(PROFILE_COLUMNS, active_profile, 'Active profile:')
94+
if active_profile.get('cluster'):
95+
96+
columns = PROFILE_COLUMNS[:1] + ['cluster_node_name'] \
97+
+ PROFILE_COLUMNS[1:]
98+
print_data(columns, _format_cluster_profile(active_profile),
99+
'Cluster nodes in profile {0}:'
100+
.format(active_profile['name']),
101+
labels={
102+
'profile_name': 'name',
103+
'cluster_node_name': 'cluster node name'})
104+
else:
105+
print_single(PROFILE_COLUMNS, active_profile, 'Active profile:')
75106

76107

77108
@profiles.command(name='list',

0 commit comments

Comments
 (0)