Skip to content

Commit ed10a1c

Browse files
authored
CY-900 cfy local: add blueprints list (#896)
* cfy local: add `blueprints list` * flake
1 parent 1a3daef commit ed10a1c

11 files changed

Lines changed: 62 additions & 61 deletions

File tree

cloudify_cli/cli/cfy.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,26 +1321,13 @@ def execution_id(required=False, dest=None):
13211321
help=helptexts.EXECUTION_ID)
13221322

13231323
@staticmethod
1324-
def blueprint_id(required=False,
1325-
multiple_blueprints=False,
1326-
validate=False):
1327-
def pass_empty_blueprint_id(func):
1328-
@wraps(func)
1329-
def wrapper(*args, **kwargs):
1330-
kwargs['blueprint_id'] = None
1331-
return func(*args, **kwargs)
1332-
1333-
return wrapper
1334-
1335-
if multiple_blueprints and not env.MULTIPLE_LOCAL_BLUEPRINTS:
1336-
return pass_empty_blueprint_id
1337-
else:
1338-
return click.option(
1339-
'-b',
1340-
'--blueprint-id',
1341-
required=required,
1342-
help=helptexts.BLUEPRINT_ID,
1343-
callback=_get_validate_callback(validate))
1324+
def blueprint_id(required=False, validate=False):
1325+
return click.option(
1326+
'-b',
1327+
'--blueprint-id',
1328+
required=required,
1329+
help=helptexts.BLUEPRINT_ID,
1330+
callback=_get_validate_callback(validate))
13441331

13451332
@staticmethod
13461333
def blueprint_path(required=False):

cloudify_cli/commands/blueprints.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@
4040

4141

4242
DESCRIPTION_LIMIT = 20
43-
BLUEPRINT_COLUMNS = ['id', 'description', 'main_file_name', 'created_at',
44-
'updated_at', 'visibility', 'tenant_name', 'created_by']
43+
BASE_BLUEPRINT_COLUMNS = ['id', 'description', 'main_file_name', 'created_at']
44+
BLUEPRINT_COLUMNS = BASE_BLUEPRINT_COLUMNS + ['updated_at', 'visibility',
45+
'tenant_name', 'created_by']
4546
INPUTS_COLUMNS = ['name', 'type', 'default', 'description']
4647

4748

@@ -210,8 +211,7 @@ def delete(blueprint_id, force, logger, client, tenant_name):
210211
logger.info('Blueprint deleted')
211212

212213

213-
@blueprints.command(name='list',
214-
short_help='List blueprints [manager only]')
214+
@cfy.command(name='list', short_help='List blueprints')
215215
@cfy.options.sort_by()
216216
@cfy.options.descending
217217
@cfy.options.common_options
@@ -224,15 +224,15 @@ def delete(blueprint_id, force, logger, client, tenant_name):
224224
@cfy.assert_manager_active()
225225
@cfy.pass_client()
226226
@cfy.pass_logger
227-
def list(sort_by,
228-
descending,
229-
tenant_name,
230-
all_tenants,
231-
search,
232-
pagination_offset,
233-
pagination_size,
234-
logger,
235-
client):
227+
def manager_list(sort_by,
228+
descending,
229+
tenant_name,
230+
all_tenants,
231+
search,
232+
pagination_offset,
233+
pagination_size,
234+
logger,
235+
client):
236236
"""List all blueprints
237237
"""
238238
def trim_description(blueprint):
@@ -260,6 +260,13 @@ def trim_description(blueprint):
260260
logger.info('Showing {0} of {1} blueprints'.format(len(blueprints), total))
261261

262262

263+
@cfy.command(name='list', short_help='List blueprints')
264+
@cfy.pass_logger
265+
def local_list(logger):
266+
blueprints = local.list_blueprints()
267+
print_data(BASE_BLUEPRINT_COLUMNS, blueprints, 'Blueprints:')
268+
269+
263270
@blueprints.command(name='get',
264271
short_help='Retrieve blueprint information [manager only]')
265272
@cfy.argument('blueprint-id')

cloudify_cli/commands/deployments.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def manager_set_visibility(deployment_id, visibility, logger, client):
581581

582582
@cfy.command(name='inputs', short_help='Show deployment inputs [locally]')
583583
@cfy.options.common_options
584-
@cfy.options.blueprint_id(required=True, multiple_blueprints=True)
584+
@cfy.options.blueprint_id(required=True)
585585
@cfy.pass_logger
586586
def local_inputs(blueprint_id, logger):
587587
"""Display inputs for the execution
@@ -592,7 +592,7 @@ def local_inputs(blueprint_id, logger):
592592

593593
@cfy.command(name='outputs', short_help='Show deployment outputs [locally]')
594594
@cfy.options.common_options
595-
@cfy.options.blueprint_id(required=True, multiple_blueprints=True)
595+
@cfy.options.blueprint_id(required=True)
596596
@cfy.pass_logger
597597
def local_outputs(blueprint_id, logger):
598598
"""Display outputs for the execution

cloudify_cli/commands/executions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def manager_cancel(execution_id, force, kill, logger, client, tenant_name):
336336
@cfy.command(name='start',
337337
short_help='Execute a workflow')
338338
@cfy.argument('workflow-id')
339-
@cfy.options.blueprint_id(required=True, multiple_blueprints=True)
339+
@cfy.options.blueprint_id(required=True)
340340
@cfy.options.parameters
341341
@cfy.options.allow_custom_parameters
342342
@cfy.options.task_retries()

cloudify_cli/commands/init.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
@cfy.command(name='init', short_help='Initialize a working env')
3737
@cfy.argument('blueprint-path', required=False)
3838
@cfy.options.blueprint_filename()
39-
@cfy.options.blueprint_id(
40-
required=False, multiple_blueprints=True, validate=True)
39+
@cfy.options.blueprint_id(required=False, validate=True)
4140
@cfy.options.reset_context
4241
@cfy.options.inputs
4342
@cfy.options.install_plugins
@@ -89,11 +88,10 @@ def init(blueprint_path,
8988
blueprint_filename
9089
)
9190

92-
if env.MULTIPLE_LOCAL_BLUEPRINTS:
93-
blueprint_id = blueprint_id or blueprint.generate_id(
94-
processed_blueprint_path,
95-
blueprint_filename
96-
)
91+
blueprint_id = blueprint_id or blueprint.generate_id(
92+
processed_blueprint_path,
93+
blueprint_filename
94+
)
9795

9896
if os.path.isdir(local.storage_dir(blueprint_id)):
9997
shutil.rmtree(local.storage_dir(blueprint_id))

cloudify_cli/commands/install.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ def manager(ctx,
124124
short_help='Install an application blueprint [locally]')
125125
@cfy.argument('blueprint-path')
126126
@cfy.options.blueprint_filename()
127-
@cfy.options.blueprint_id(
128-
required=False, multiple_blueprints=True, validate=True)
127+
@cfy.options.blueprint_id(required=False, validate=True)
129128
@cfy.options.inputs
130129
@cfy.options.validate
131130
@cfy.options.install_plugins

cloudify_cli/commands/node_instances.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def list(deployment_id,
145145
@cfy.command(name='node-instances',
146146
short_help='Show node-instance information [locally]')
147147
@cfy.argument('node-id', required=False)
148-
@cfy.options.blueprint_id(required=True, multiple_blueprints=True)
148+
@cfy.options.blueprint_id(required=True)
149149
@cfy.options.common_options
150150
@cfy.pass_logger
151151
def local(node_id, blueprint_id, logger):

cloudify_cli/commands/uninstall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def manager(ctx,
9292
@cfy.command(name='uninstall',
9393
short_help='Uninstall an application blueprint')
9494
@cfy.options.workflow_id('uninstall')
95-
@cfy.options.blueprint_id(required=True, multiple_blueprints=True)
95+
@cfy.options.blueprint_id(required=True)
9696
@cfy.options.parameters
9797
@cfy.options.allow_custom_parameters
9898
@cfy.options.task_retries()

cloudify_cli/env.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
constants.CLOUDIFY_BASE_DIRECTORY_NAME)
4848
PROFILES_DIR = os.path.join(CLOUDIFY_WORKDIR, 'profiles')
4949
ACTIVE_PRO_FILE = os.path.join(CLOUDIFY_WORKDIR, 'active.profile')
50-
MULTIPLE_LOCAL_BLUEPRINTS = (
51-
os.environ.get('CFY_MULTIPLE_BLUEPRINTS', 'true') == 'true')
5250
CLUSTER_RETRY_INTERVAL = 5
5351

5452

cloudify_cli/local.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,36 @@ def initialize_blueprint(blueprint_path,
6262

6363
def storage_dir(blueprint_id=None):
6464
if blueprint_id:
65-
return os.path.join(
66-
env.PROFILES_DIR,
67-
_ENV_NAME,
68-
blueprint_id
69-
)
65+
return os.path.join(env.PROFILES_DIR, _ENV_NAME, blueprint_id)
7066
else:
71-
directories = [env.PROFILES_DIR, _ENV_NAME]
72-
if not env.MULTIPLE_LOCAL_BLUEPRINTS:
73-
directories.append('local-storage')
74-
return os.path.join(*directories)
67+
return os.path.join(env.PROFILES_DIR, _ENV_NAME)
68+
69+
70+
def list_blueprints():
71+
blueprints = []
72+
for bp_id in os.listdir(os.path.join(env.PROFILES_DIR, _ENV_NAME)):
73+
bp_env = load_env(bp_id)
74+
blueprints.append({
75+
'id': bp_id,
76+
'description': bp_env.plan['description'],
77+
'main_file_name': os.path.basename(
78+
bp_env.storage.get_blueprint_path()),
79+
'created_at': bp_env.created_at,
80+
})
81+
return blueprints
7582

7683

7784
def get_storage():
7885
return local.FileStorage(storage_dir=storage_dir())
7986

8087

81-
def load_env(blueprint_id=None):
82-
if not os.path.isdir(storage_dir()):
88+
def load_env(blueprint_id):
89+
if not os.path.isdir(storage_dir(blueprint_id)):
8390
error = exceptions.CloudifyCliError('Please initialize a blueprint')
8491
error.possible_solutions = ["Run `cfy init BLUEPRINT_PATH`"]
8592
raise error
86-
return local.load_env(name=blueprint_id or 'local', storage=get_storage())
93+
return local.load_env(name=blueprint_id or 'local',
94+
storage=get_storage())
8795

8896

8997
def _install_plugins(blueprint_path):

0 commit comments

Comments
 (0)