Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing -ws flags for bp launch #209

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion calm/dsl/cli/bp_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ def create_blueprint_command(bp_file, name, description, force):

@launch.command("bp")
@click.argument("blueprint_name")
@click.option(
"--with_secrets",
"-ws",
is_flag=True,
default=False,
help="Preserve secrets while launching the blueprint",
)
@click.option(
"--environment", "-e", default=None, help="Environment for the application"
)
Expand Down Expand Up @@ -299,6 +306,7 @@ def create_blueprint_command(bp_file, name, description, force):
def launch_blueprint_command(
blueprint_name,
environment,
with_secrets,
app_name,
ignore_runtime_variables,
profile_name,
Expand Down Expand Up @@ -368,7 +376,7 @@ def launch_blueprint_command(

app_name = app_name or "App-{}-{}".format(blueprint_name, int(time.time()))
blueprint_name, blueprint = patch_bp_if_required(
environment, blueprint_name, profile_name
with_secrets, environment, blueprint_name, profile_name
)

launch_blueprint_simple(
Expand Down
19 changes: 14 additions & 5 deletions calm/dsl/cli/bps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,8 @@ def launch_blueprint_simple(
LOG.error("[{}] - {}".format(err["code"], err["error"]))
sys.exit("Unable to retrieve protection policies")
protection_policies = [p["status"] for p in res.json()["entities"]]
res, err = client.environment.list()
payload = {"filter": "uuid=={}". format(env_uuids[0])}
res, err = client.environment.list(payload)
if err:
LOG.error("[{}] - {}".format(err["code"], err["error"]))
sys.exit("Unable to retrieve environments")
Expand Down Expand Up @@ -1745,7 +1746,7 @@ def delete_blueprint(blueprint_names):


def create_patched_blueprint(
blueprint, project_data, environment_data, profile_name=None
blueprint, project_data, environment_data, profile_name=None, with_secrets=False
):
"""Patch the blueprint with the given environment to create a new blueprint"""
client = get_api_client()
Expand All @@ -1766,13 +1767,19 @@ def create_patched_blueprint(
{
"environment": {"uuid": env_uuid},
"app_profile": {"name": profile_name},
"keep_secrets": with_secrets,
}
],
"new_blueprint": {"name": new_bp_name},
},
}

LOG.info("Creating Patched blueprint")
msg = (
"Creating Patched blueprint with secrets preserved"
if with_secrets
else "Creating Patched blueprint"
)
LOG.info(msg)
bp_res, err = client.blueprint.patch_with_environment(org_bp_uuid, request_spec)
if err:
LOG.error("[{}] - {}".format(err["code"], err["error"]))
Expand All @@ -1787,7 +1794,9 @@ def create_patched_blueprint(
return bp_res


def patch_bp_if_required(environment_name=None, blueprint_name=None, profile_name=None):
def patch_bp_if_required(
with_secrets=False, environment_name=None, blueprint_name=None, profile_name=None
):
"""Patch the blueprint with the given environment to create a new blueprint if the requested app profile
is not already linked to the given environment"""
if environment_name:
Expand Down Expand Up @@ -1816,7 +1825,7 @@ def patch_bp_if_required(environment_name=None, blueprint_name=None, profile_nam
)
if ref_env_uuid != env_uuid:
new_blueprint = create_patched_blueprint(
bp, project_data, environment_data, profile_name
bp, project_data, environment_data, profile_name, with_secrets
)
return new_blueprint["metadata"]["name"], new_blueprint

Expand Down