def _decompile_bp(bp_payload, with_secrets=False): """decompiles the blueprint from payload""" blueprint = bp_payload["spec"]["resources"] blueprint_name = bp_payload["spec"].get("name", "DslBlueprint") blueprint_description = bp_payload["spec"].get("description", "") # Copying dsl_name_map to global client_attrs if bp_payload["spec"]["resources"]["client_attrs"].get("None", {}): init_dsl_metadata_map(bp_payload["spec"]["resources"]["client_attrs"]["None"]) LOG.info("Decompiling blueprint {}".format(blueprint_name)) for sub_obj in blueprint.get("substrate_definition_list"): sub_type = sub_obj.get("type", "") or "AHV_VM" if sub_type == "K8S_POD": raise NotImplementedError( "Decompilation for k8s pod is not supported right now" ) elif sub_type != "AHV_VM": LOG.warning( "Decompilation support for providers other than AHV is experimental/best effort" ) break bp_cls = BlueprintType.decompile(blueprint) bp_cls.__name__ = get_valid_identifier(blueprint_name) bp_cls.__doc__ = blueprint_description create_bp_dir(bp_cls=bp_cls, with_secrets=with_secrets) click.echo("\nSuccessfully decompiled. Directory location: {}".format(get_bp_dir()))
def decompile_marketplace_bp(name, version, app_source, bp_name, project, with_secrets, bp_dir): """decompiles marketplace blueprint""" if not version: LOG.info("Fetching latest version of Marketplace Blueprint {} ".format( name)) version = get_mpi_latest_version(name=name, app_source=app_source) LOG.info(version) LOG.info("Converting MPI into blueprint") bp_payload = convert_mpi_into_blueprint(name=name, version=version, project_name=project, app_source=app_source) del bp_payload["status"] client = get_api_client() blueprint_uuid = bp_payload["metadata"]["uuid"] res, err = client.blueprint.export_file(blueprint_uuid) if err: LOG.error("[{}] - {}".format(err["code"], err["error"])) sys.exit(-1) bp_payload = res.json() blueprint = bp_payload["spec"]["resources"] blueprint_name = get_valid_identifier(bp_name or name) if not bp_dir: bp_dir_suffix = bp_name or "mpi_bp_{}_v{}".format( blueprint_name, version) bp_dir = os.path.join(os.getcwd(), bp_dir_suffix) blueprint_description = bp_payload["spec"].get("description", "") LOG.info("Decompiling marketplace blueprint {}".format(name)) for sub_obj in blueprint.get("substrate_definition_list"): sub_type = sub_obj.get("type", "") or "AHV_VM" if sub_type == "K8S_POD": raise NotImplementedError( "Decompilation for k8s pod is not supported right now") elif sub_type != "AHV_VM": LOG.warning( "Decompilation support for providers other than AHV is experimental." ) break bp_cls = BlueprintType.decompile(blueprint) bp_cls.__name__ = blueprint_name bp_cls.__doc__ = blueprint_description create_bp_dir(bp_cls=bp_cls, bp_dir=bp_dir, with_secrets=with_secrets) click.echo( "\nSuccessfully decompiled. Directory location: {}. Blueprint location: {}" .format(get_bp_dir(), os.path.join(get_bp_dir(), "blueprint.py")))
def _decompile_bp(bp_payload, with_secrets=False, prefix="", bp_dir=None): """decompiles the blueprint from payload""" blueprint = bp_payload["spec"]["resources"] blueprint_name = bp_payload["spec"].get("name", "DslBlueprint") blueprint_description = bp_payload["spec"].get("description", "") blueprint_metadata = bp_payload["metadata"] # POP unnecessary keys blueprint_metadata.pop("creation_time", None) blueprint_metadata.pop("last_update_time", None) metadata_obj = MetadataType.decompile(blueprint_metadata) # Copying dsl_name_map to global client_attrs if bp_payload["spec"]["resources"]["client_attrs"].get("None", {}): init_dsl_metadata_map(bp_payload["spec"]["resources"]["client_attrs"]["None"]) LOG.info("Decompiling blueprint {}".format(blueprint_name)) for sub_obj in blueprint.get("substrate_definition_list"): sub_type = sub_obj.get("type", "") or "AHV_VM" if sub_type == "K8S_POD": raise NotImplementedError( "Decompilation for k8s pod is not supported right now" ) elif sub_type != "AHV_VM": LOG.warning( "Decompilation support for providers other than AHV is experimental." ) break prefix = get_valid_identifier(prefix) bp_cls = BlueprintType.decompile(blueprint, prefix=prefix) bp_cls.__name__ = get_valid_identifier(blueprint_name) bp_cls.__doc__ = blueprint_description create_bp_dir( bp_cls=bp_cls, with_secrets=with_secrets, metadata_obj=metadata_obj, bp_dir=bp_dir, ) click.echo( "\nSuccessfully decompiled. Directory location: {}. Blueprint location: {}".format( get_bp_dir(), os.path.join(get_bp_dir(), "blueprint.py") ) )