|
16 | 16 |
|
17 | 17 | import json |
18 | 18 |
|
| 19 | +import click |
19 | 20 | from cloudify_rest_client.exceptions import CloudifyClientError |
20 | 21 |
|
21 | 22 | from .. import utils |
|
24 | 25 | from ..logger import get_global_json_output |
25 | 26 | from ..table import print_data, print_details, print_single |
26 | 27 | from ..exceptions import CloudifyCliError |
| 28 | +from .summary import BASE_SUMMARY_FIELDS, structure_summary_results |
27 | 29 |
|
28 | 30 |
|
29 | 31 | NODE_INSTANCE_COLUMNS = ['id', 'deployment_id', 'host_id', 'node_id', 'state', |
30 | 32 | 'visibility', 'tenant_name', 'created_by'] |
| 33 | +NODE_INSTANCES_SUMMARY_FIELDS = [ |
| 34 | + 'deployment_id', |
| 35 | + 'node_id', |
| 36 | + 'state', |
| 37 | + 'host_id', |
| 38 | +] + BASE_SUMMARY_FIELDS |
31 | 39 |
|
32 | 40 |
|
33 | 41 | @cfy.group(name='node-instances') |
34 | 42 | @cfy.options.common_options |
35 | 43 | @cfy.assert_manager_active() |
36 | | -def manager(): |
| 44 | +def node_instances(): |
37 | 45 | """Handle a deployment's node-instances |
38 | 46 | """ |
39 | 47 | pass |
40 | 48 |
|
41 | 49 |
|
42 | | -@manager.command(name='get', |
43 | | - short_help='Retrieve node-instance information ' |
44 | | - '[manager only]') |
| 50 | +@node_instances.command(name='get', |
| 51 | + short_help='Retrieve node-instance information ' |
| 52 | + '[manager only]') |
45 | 53 | @cfy.argument('node_instance_id') |
46 | 54 | @cfy.options.common_options |
47 | 55 | @cfy.options.tenant_name( |
@@ -82,9 +90,9 @@ def get(node_instance_id, logger, client, tenant_name): |
82 | 90 | logger.info('') |
83 | 91 |
|
84 | 92 |
|
85 | | -@manager.command(name='list', |
86 | | - short_help='List node-instances for a deployment ' |
87 | | - '[manager only]') |
| 93 | +@node_instances.command(name='list', |
| 94 | + short_help='List node-instances for a deployment ' |
| 95 | + '[manager only]') |
88 | 96 | @cfy.options.deployment_id(required=False) |
89 | 97 | @cfy.options.node_name |
90 | 98 | @cfy.options.sort_by('node_id') |
@@ -142,6 +150,53 @@ def list(deployment_id, |
142 | 150 | .format(len(node_instances), total)) |
143 | 151 |
|
144 | 152 |
|
| 153 | +@node_instances.command(name='summary', |
| 154 | + short_help='Retrieve summary of node instance ' |
| 155 | + 'details [manager only]') |
| 156 | +@cfy.argument('target_field', |
| 157 | + type=click.Choice(NODE_INSTANCES_SUMMARY_FIELDS)) |
| 158 | +@cfy.argument('sub_field', |
| 159 | + type=click.Choice(NODE_INSTANCES_SUMMARY_FIELDS), |
| 160 | + default=None, required=False) |
| 161 | +@cfy.options.common_options |
| 162 | +@cfy.options.tenant_name(required=False, resource_name_for_help='summary') |
| 163 | +@cfy.options.all_tenants |
| 164 | +@cfy.pass_logger |
| 165 | +@cfy.pass_client() |
| 166 | +def summary(target_field, sub_field, logger, client, tenant_name, |
| 167 | + all_tenants): |
| 168 | + """Retrieve summary of node instances, e.g. a count of each node instance |
| 169 | + with the same deployment ID. |
| 170 | +
|
| 171 | + `TARGET_FIELD` is the field to summarise node instances on. |
| 172 | + """ |
| 173 | + utils.explicit_tenant_name_message(tenant_name, logger) |
| 174 | + logger.info( |
| 175 | + 'Retrieving summary of node instances on field {field}'.format( |
| 176 | + field=target_field, |
| 177 | + ) |
| 178 | + ) |
| 179 | + |
| 180 | + summary = client.summary.node_instances.get( |
| 181 | + _target_field=target_field, |
| 182 | + _sub_field=sub_field, |
| 183 | + _all_tenants=all_tenants, |
| 184 | + ) |
| 185 | + |
| 186 | + columns, items = structure_summary_results( |
| 187 | + summary.items, |
| 188 | + target_field, |
| 189 | + sub_field, |
| 190 | + 'node_instances', |
| 191 | + ) |
| 192 | + |
| 193 | + print_data( |
| 194 | + columns, |
| 195 | + items, |
| 196 | + 'Node instance summary by {field}'.format(field=target_field), |
| 197 | + ) |
| 198 | + |
| 199 | + |
145 | 200 | @cfy.command(name='node-instances', |
146 | 201 | short_help='Show node-instance information [locally]') |
147 | 202 | @cfy.argument('node-id', required=False) |
|
0 commit comments