Skip to content

Commit

Permalink
Support for py2-py3 migration scripts (#334)
Browse files Browse the repository at this point in the history
Added following commands:
1. calm decompile app-migratable-bp <app_name> : Will decompile bp that
will only contain escript tasks
2. calm describe app-migratable-entities <app_name> : Will describe
escript tasks that can be modified under diff entities.
3. calm update app-migratable-bp <app_name> -f <bp_file>: Will update
the app-blueprint escripts

---------

Signed-off-by: Satheesh Rajendran <[email protected]>
Co-authored-by: Gullapalli Akhil Sai <[email protected]>
Co-authored-by: Satheesh Rajendran <[email protected]>
(cherry picked from commit c8ad0e626cc643c3c3acc8be66d9609ebf6ce30c)
  • Loading branch information
abhijeetkaurav1st authored and navtejpreetsingh committed Dec 14, 2023
1 parent 8ac5720 commit 52bc710
Show file tree
Hide file tree
Showing 15 changed files with 1,654 additions and 4 deletions.
19 changes: 19 additions & 0 deletions calm/dsl/api/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def __init__(self, connection):
self.DOWNLOAD_RUNLOG = self.ITEM + "/app_runlogs/{}/output/download"
self.ACTION_VARIABLE = self.ITEM + "/actions/{}/variables"
self.RECOVERY_GROUPS_LIST = self.ITEM + "/recovery_groups/list"
self.BLUEPRINTS_ORIGINAL = self.ITEM + "/blueprints/original"
self.BLUEPRINT_ENTITIES_ESCRIPT_UPDATE = (
self.ITEM + "/blueprints/entities/update"
)

def run_action(self, app_id, action_id, payload):
return self.connection._call(
Expand All @@ -20,6 +24,21 @@ def run_action(self, app_id, action_id, payload):
method=REQUEST.METHOD.POST,
)

def blueprints_original(self, app_id):
return self.connection._call(
self.BLUEPRINTS_ORIGINAL.format(app_id),
verify=False,
method=REQUEST.METHOD.GET,
)

def blueprints_entities_update(self, app_id, payload):
return self.connection._call(
self.BLUEPRINT_ENTITIES_ESCRIPT_UPDATE.format(app_id),
request_json=payload,
verify=False,
method=REQUEST.METHOD.PUT,
)

def run_patch(self, app_id, patch_id, payload):
return self.connection._call(
self.PATCH_RUN.format(app_id, patch_id),
Expand Down
2 changes: 1 addition & 1 deletion calm/dsl/builtins/models/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def decompile(mcls, cdict, context=[], prefix=""):
elif package_type == "SUBSTRATE_IMAGE":
disk_pkg_data = {
"name": cdict["name"],
"description": cdict["description"],
"description": cdict.get("description", ""),
"options": cdict["options"],
}
types = EntityTypeBase.get_entity_types()
Expand Down
54 changes: 53 additions & 1 deletion calm/dsl/cli/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

from calm.dsl.api import get_api_client

from .main import main, get, describe, delete, run, watch, download, create, update
from .main import (
main,
get,
describe,
delete,
run,
watch,
download,
create,
update,
decompile,
)
from .utils import Display, FeatureFlagGroup
from .apps import (
get_apps,
Expand All @@ -14,6 +25,9 @@
delete_app,
download_runlog,
create_app,
describe_app_actions_to_update,
decompile_app_migratable_bp,
update_app_migratable_bp,
)
from calm.dsl.log import get_logging_handle

Expand Down Expand Up @@ -104,6 +118,44 @@ def _get_apps(name, filter_by, limit, offset, quiet, all_items, out):
get_apps(name, filter_by, limit, offset, quiet, all_items, out)


@describe.command("app-migratable-entities")
@click.argument("app_name")
def _describe_app(app_name):
"""Display app-actions to be migrated"""

describe_app_actions_to_update(app_name)


@decompile.command("app-migratable-bp")
@click.option(
"--dir",
"-d",
"bp_dir",
default=None,
help="Blueprint directory location used for placing decompiled entities",
)
@click.argument("app_name")
def _decompile_app_migratable_bp(app_name, bp_dir):
"""Decompile app-blueprint app-actions to be migrated"""

decompile_app_migratable_bp(app_name, bp_dir)


@update.command("app-migratable-bp")
@click.option(
"--file",
"-f",
"bp_file",
type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True),
help="Path to Blueprint file",
)
@click.argument("app_name")
def _update_app_migratable_bp(app_name, bp_file):
"""update app-blueprint app-actions to be migrated"""

update_app_migratable_bp(app_name, bp_file)


@describe.command("app")
@click.argument("app_name")
@click.option(
Expand Down
Loading

0 comments on commit 52bc710

Please sign in to comment.