def get_import_resolver(): if not is_initialized(): return None config = CloudifyConfig() # get the resolver configuration from the config file local_import_resolver = config.local_import_resolver return dsl_parser_utils.create_import_resolver(local_import_resolver)
def _update_parser_context_in_app(self, context): raw_parser_context = self._extract_parser_context(context) resolver = dsl_parser_utils.create_import_resolver( raw_parser_context['resolver_section']) validate_definitions_version = raw_parser_context[ 'validate_definitions_version'] current_app.parser_context = { 'resolver': resolver, 'validate_version': validate_definitions_version }
def get_import_resolver(): local_import_resolver = { 'implementation': 'cloudify_cli.config.config:ResolverWithPlugins' } if env.is_initialized(): config = CloudifyConfig() # get the resolver configuration from the config file if isinstance(config.local_import_resolver, dict): local_import_resolver.update(config.local_import_resolver) return dsl_parser_utils.create_import_resolver(local_import_resolver)
def get_import_resolver(): local_import_resolver = { 'implementation': 'cloudify_cli.config.config:ResolverWithCatalogIdentification' } if env.is_initialized(): config = CloudifyConfig() # get the resolver configuration from the config file if isinstance(config.local_import_resolver, dict): local_import_resolver.update(config.local_import_resolver) return dsl_parser_utils.create_import_resolver(local_import_resolver)
def _extract_parser_context(context): context = context or {} cloudify_section = context.get(constants.CLOUDIFY, {}) resolver_section = cloudify_section.get( constants.IMPORT_RESOLVER_KEY) or {} resolver_section.setdefault( 'implementation', 'manager_rest.app_context:ResolverWithPlugins') resolver = dsl_parser_utils.create_import_resolver(resolver_section) return { 'resolver': resolver, 'validate_version': cloudify_section.get(constants.VALIDATE_DEFINITIONS_VERSION, True) }
def _extract_parser_context(context): context = context or {} cloudify_section = context.get(constants.CLOUDIFY, {}) resolver_section = cloudify_section.get( constants.IMPORT_RESOLVER_KEY) or {} resolver_section.setdefault( 'implementation', 'manager_rest.' 'resolver_with_catalog_support:ResolverWithCatalogSupport') resolver = dsl_parser_utils.create_import_resolver(resolver_section) return { 'resolver': resolver, 'validate_version': cloudify_section.get( constants.VALIDATE_DEFINITIONS_VERSION, True) }
def _test_create_import_resolver(self, resolver_configuration=None, expected_resolver=None, expected_params_name=None, err_msg_regex=None): if expected_resolver: resolver = utils.create_import_resolver(resolver_configuration) self.assertEqual(resolver.__class__, expected_resolver.__class__) if expected_params_name: self.assertEqual( resolver.__getattribute__(expected_params_name), expected_resolver.__getattribute__(expected_params_name)) else: self.assertRaisesRegex(utils.ResolverInstantiationError, err_msg_regex, utils.create_import_resolver, resolver_configuration)
def extract_parser_context(context, resolver_parameters): context = context or {} cloudify_section = context.get(constants.CLOUDIFY, {}) resolver_section = cloudify_section.get(constants.IMPORT_RESOLVER_KEY, {}) resolver_section.setdefault( 'implementation', 'cloudify_system_workflows.dsl_import_resolver' '.resolver_with_catalog_support:ResolverWithCatalogSupport') if resolver_parameters: if constants.PARAMETERS not in resolver_section: resolver_section[constants.PARAMETERS] = {} resolver_section[constants.PARAMETERS].update(resolver_parameters) resolver = dsl_parser_utils.create_import_resolver(resolver_section) return { 'resolver': resolver, 'validate_version': cloudify_section.get(constants.VALIDATE_DEFINITIONS_VERSION, True) }
def main(tenant_names, all_tenants, plugin_names, blueprint_ids, mapping_file, correct): def update_suggestions(new_suggestion: dict): for plugin_name, plugin_version in new_suggestion.items(): if plugin_name not in install_suggestions: install_suggestions[plugin_name] = [] if plugin_version not in install_suggestions[plugin_name]: install_suggestions[plugin_name].append(plugin_version) if all_tenants and tenant_names: print('--all-tenants and --tenant-name options are mutually exclusive') exit(1) if not tenant_names: tenant_names = (DEFAULT_TENANT, ) setup_environment() set_tenant_in_app(get_tenant_by_name(DEFAULT_TENANT)) sm = get_storage_manager() # Prepare the resolver cloudify_section = sm.get(models.ProviderContext, PROVIDER_CONTEXT_ID).\ context.get(CLOUDIFY, {}) resolver_section = cloudify_section.get(IMPORT_RESOLVER_KEY, {}) resolver_section.setdefault( 'implementation', 'manager_rest.' 'resolver_with_catalog_support:ResolverWithCatalogSupport') resolver = dsl_parser_utils.create_import_resolver(resolver_section) if all_tenants: tenants = sm.list(models.Tenant, get_all_results=True) else: tenants = [get_tenant_by_name(name) for name in tenant_names] blueprint_filter = {'tenant': None} if blueprint_ids: blueprint_filter['id'] = blueprint_ids mappings = load_mappings(mapping_file) if correct else {} stats, install_suggestions, blueprints_processed = {}, {}, 0 for tenant in tenants: set_tenant_in_app(get_tenant_by_name(tenant.name)) sm = get_storage_manager() blueprint_filter['tenant'] = tenant blueprints = sm.list(models.Blueprint, filters=blueprint_filter, get_all_results=True) for blueprint in blueprints: print('Processing blueprint of {0}: {1} '.format( tenant.name, blueprint.id)) blueprint_identifier = '{0}::{1}'.format(tenant.name, blueprint.id) if correct: try: result = correct_blueprint( blueprint, plugin_names, mappings.get(tenant.name, {}).get(blueprint.id)) except UpdateException as ex: print(ex) else: blueprints_processed += 1 if result not in stats: stats[result] = [blueprint_identifier] else: stats[result].append(blueprint_identifier) else: try: a_mapping, a_statistic, a_suggestion = \ scan_blueprint(resolver, blueprint, plugin_names) except UpdateException as ex: print(ex) else: blueprints_processed += 1 if a_mapping: if tenant.name not in mappings: mappings[tenant.name] = {} mappings[tenant.name][blueprint.id] = a_mapping if a_statistic: stats[blueprint_identifier] = a_statistic if a_suggestion: update_suggestions(a_suggestion) # Wrap it up if correct: printout_correction_stats(stats) else: with open(mapping_file, 'w') as output_file: yaml.dump(mappings, output_file, default_flow_style=False) chmod(mapping_file, 0o644) print('\nSaved mapping file to the {0}'.format(mapping_file)) printout_scanning_stats(blueprints_processed, mappings, stats) printout_install_suggestions(install_suggestions)