Skip to content

Commit 2cc7204

Browse files
Maddageokala
authored andcommitted
Move summary commands to their respective entities
1 parent e548b3b commit 2cc7204

9 files changed

Lines changed: 264 additions & 267 deletions

File tree

cloudify_cli/commands/blueprints.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@
3737
from ..utils import (prettify_client_error,
3838
get_visibility,
3939
validate_visibility)
40+
from .summary import BASE_SUMMARY_FIELDS, structure_summary_results
4041

4142

4243
DESCRIPTION_LIMIT = 20
4344
BASE_BLUEPRINT_COLUMNS = ['id', 'description', 'main_file_name', 'created_at']
4445
BLUEPRINT_COLUMNS = BASE_BLUEPRINT_COLUMNS + ['updated_at', 'visibility',
4546
'tenant_name', 'created_by']
4647
INPUTS_COLUMNS = ['name', 'type', 'default', 'description']
48+
BLUEPRINTS_SUMMARY_FIELDS = BASE_SUMMARY_FIELDS
4749

4850

4951
@cfy.group(name='blueprints')
@@ -457,3 +459,45 @@ def set_visibility(blueprint_id, visibility, logger, client):
457459
client.blueprints.set_visibility(blueprint_id, visibility)
458460
logger.info('Blueprint `{0}` was set to {1}'.format(blueprint_id,
459461
visibility))
462+
463+
464+
@blueprints.command(name='summary',
465+
short_help='Retrieve summary of blueprint details '
466+
'[manager only]')
467+
@cfy.argument('target_field', type=click.Choice(BLUEPRINTS_SUMMARY_FIELDS))
468+
@cfy.argument('sub_field', type=click.Choice(BLUEPRINTS_SUMMARY_FIELDS),
469+
default=None, required=False)
470+
@cfy.options.common_options
471+
@cfy.options.tenant_name(required=False, resource_name_for_help='summary')
472+
@cfy.options.all_tenants
473+
@cfy.pass_logger
474+
@cfy.pass_client()
475+
def summary(target_field, sub_field, logger, client, tenant_name,
476+
all_tenants):
477+
"""Retrieve summary of blueprints, e.g. a count of each blueprint with
478+
the same tenant name.
479+
480+
`TARGET_FIELD` is the field to summarise blueprints on.
481+
"""
482+
utils.explicit_tenant_name_message(tenant_name, logger)
483+
logger.info('Retrieving summary of blueprints on field {field}'.format(
484+
field=target_field))
485+
486+
summary = client.summary.blueprints.get(
487+
_target_field=target_field,
488+
_sub_field=sub_field,
489+
_all_tenants=all_tenants,
490+
)
491+
492+
columns, items = structure_summary_results(
493+
summary.items,
494+
target_field,
495+
sub_field,
496+
'blueprints',
497+
)
498+
499+
print_data(
500+
columns,
501+
items,
502+
'Blueprint summary by {field}'.format(field=target_field),
503+
)

cloudify_cli/commands/deployments.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
import json
1919
import shutil
2020

21-
from StringIO import StringIO
22-
21+
import click
2322
from cloudify_rest_client.constants import VISIBILITY_EXCEPT_PRIVATE
2423
from cloudify_rest_client.exceptions import (
2524
DeploymentPluginNotFound,
@@ -29,6 +28,9 @@
2928
UnsupportedDeploymentGetSecretError,
3029
CloudifyClientError
3130
)
31+
from StringIO import StringIO
32+
33+
3234
from . import blueprints
3335
from ..local import load_env
3436
from ..table import print_data, print_single, print_details
@@ -44,6 +46,7 @@
4446
get_visibility,
4547
validate_visibility,
4648
get_deployment_environment_execution)
49+
from .summary import BASE_SUMMARY_FIELDS, structure_summary_results
4750

4851

4952
DEPLOYMENT_COLUMNS = ['id', 'blueprint_id', 'created_at', 'updated_at',
@@ -52,6 +55,9 @@
5255
'execution_id', 'created_at', 'visibility',
5356
'old_blueprint_id', 'new_blueprint_id']
5457
TENANT_HELP_MESSAGE = 'The name of the tenant of the deployment'
58+
DEPLOYMENTS_SUMMARY_FIELDS = [
59+
'blueprint_id',
60+
] + BASE_SUMMARY_FIELDS
5561

5662

5763
@cfy.group(name='deployments')
@@ -599,3 +605,45 @@ def local_outputs(blueprint_id, logger):
599605
"""
600606
env = load_env(blueprint_id)
601607
logger.info(json.dumps(env.outputs() or {}, sort_keys=True, indent=2))
608+
609+
610+
@deployments.command(name='summary',
611+
short_help='Retrieve summary of deployment details '
612+
'[manager only]')
613+
@cfy.argument('target_field', type=click.Choice(DEPLOYMENTS_SUMMARY_FIELDS))
614+
@cfy.argument('sub_field', type=click.Choice(DEPLOYMENTS_SUMMARY_FIELDS),
615+
default=None, required=False)
616+
@cfy.options.common_options
617+
@cfy.options.tenant_name(required=False, resource_name_for_help='summary')
618+
@cfy.options.all_tenants
619+
@cfy.pass_logger
620+
@cfy.pass_client()
621+
def summary(target_field, sub_field, logger, client, tenant_name,
622+
all_tenants):
623+
"""Retrieve summary of deployments, e.g. a count of each deployment with
624+
the same blueprint ID.
625+
626+
`TARGET_FIELD` is the field to summarise deployments on.
627+
"""
628+
utils.explicit_tenant_name_message(tenant_name, logger)
629+
logger.info('Retrieving summary of deployments on field {field}'.format(
630+
field=target_field))
631+
632+
summary = client.summary.deployments.get(
633+
_target_field=target_field,
634+
_sub_field=sub_field,
635+
_all_tenants=all_tenants,
636+
)
637+
638+
columns, items = structure_summary_results(
639+
summary.items,
640+
target_field,
641+
sub_field,
642+
'deployments',
643+
)
644+
645+
print_data(
646+
columns,
647+
items,
648+
'Deployment summary by {field}'.format(field=target_field),
649+
)

cloudify_cli/commands/executions.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import json
1818
import time
1919

20+
import click
2021
from cloudify_rest_client import exceptions
2122

2223
from .. import local
@@ -29,6 +30,7 @@
2930
from ..execution_events_fetcher import wait_for_execution
3031
from ..exceptions import CloudifyCliError, ExecutionTimeoutError, \
3132
SuppressedCloudifyCliError
33+
from .summary import BASE_SUMMARY_FIELDS, structure_summary_results
3234

3335
_STATUS_CANCELING_MESSAGE = (
3436
'NOTE: Executions currently in a "canceling/force-canceling" status '
@@ -44,6 +46,12 @@
4446
'is_dry_run', 'deployment_id', 'created_at', 'started_at', 'scheduled_for',
4547
'visibility', 'tenant_name', 'created_by']
4648
EXECUTION_TABLE_LABELS = {'status_display': 'status'}
49+
EXECUTIONS_SUMMARY_FIELDS = [
50+
'status',
51+
'blueprint_id',
52+
'deployment_id',
53+
'workflow_id',
54+
] + BASE_SUMMARY_FIELDS
4755

4856

4957
@cfy.group(name='executions')
@@ -405,3 +413,45 @@ def local_start(workflow_id,
405413
task_thread_pool_size=task_thread_pool_size)
406414
if result is not None:
407415
logger.info(json.dumps(result, sort_keys=True, indent=2))
416+
417+
418+
@executions.command(name='summary',
419+
short_help='Retrieve summary of execution details '
420+
'[manager only]')
421+
@cfy.argument('target_field', type=click.Choice(EXECUTIONS_SUMMARY_FIELDS))
422+
@cfy.argument('sub_field', type=click.Choice(EXECUTIONS_SUMMARY_FIELDS),
423+
default=None, required=False)
424+
@cfy.options.common_options
425+
@cfy.options.tenant_name(required=False, resource_name_for_help='summary')
426+
@cfy.options.all_tenants
427+
@cfy.pass_logger
428+
@cfy.pass_client()
429+
def summary(target_field, sub_field, logger, client, tenant_name,
430+
all_tenants):
431+
"""Retrieve summary of executions, e.g. a count of each execution with
432+
the same deployment ID.
433+
434+
`TARGET_FIELD` is the field to summarise executions on.
435+
"""
436+
utils.explicit_tenant_name_message(tenant_name, logger)
437+
logger.info('Retrieving summary of executions on field {field}'.format(
438+
field=target_field))
439+
440+
summary = client.summary.executions.get(
441+
_target_field=target_field,
442+
_sub_field=sub_field,
443+
_all_tenants=all_tenants,
444+
)
445+
446+
columns, items = structure_summary_results(
447+
summary.items,
448+
target_field,
449+
sub_field,
450+
'executions',
451+
)
452+
453+
print_data(
454+
columns,
455+
items,
456+
'Execution summary by {field}'.format(field=target_field),
457+
)

cloudify_cli/commands/node_instances.py

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import json
1818

19+
import click
1920
from cloudify_rest_client.exceptions import CloudifyClientError
2021

2122
from .. import utils
@@ -24,24 +25,31 @@
2425
from ..logger import get_global_json_output
2526
from ..table import print_data, print_details, print_single
2627
from ..exceptions import CloudifyCliError
28+
from .summary import BASE_SUMMARY_FIELDS, structure_summary_results
2729

2830

2931
NODE_INSTANCE_COLUMNS = ['id', 'deployment_id', 'host_id', 'node_id', 'state',
3032
'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
3139

3240

3341
@cfy.group(name='node-instances')
3442
@cfy.options.common_options
3543
@cfy.assert_manager_active()
36-
def manager():
44+
def node_instances():
3745
"""Handle a deployment's node-instances
3846
"""
3947
pass
4048

4149

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]')
4553
@cfy.argument('node_instance_id')
4654
@cfy.options.common_options
4755
@cfy.options.tenant_name(
@@ -82,9 +90,9 @@ def get(node_instance_id, logger, client, tenant_name):
8290
logger.info('')
8391

8492

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]')
8896
@cfy.options.deployment_id(required=False)
8997
@cfy.options.node_name
9098
@cfy.options.sort_by('node_id')
@@ -142,6 +150,53 @@ def list(deployment_id,
142150
.format(len(node_instances), total))
143151

144152

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+
145200
@cfy.command(name='node-instances',
146201
short_help='Show node-instance information [locally]')
147202
@cfy.argument('node-id', required=False)

0 commit comments

Comments
 (0)