示例#1
0
def _insert_imported_list(blueprint_holder, blueprints_imported):
    key_holder = Holder(constants.IMPORTED_BLUEPRINTS)
    blueprint_holder.value[key_holder] = Holder([])
    value_holder = blueprint_holder.value[key_holder]

    for import_url in blueprints_imported:
        value_holder.value.append(Holder(import_url))
示例#2
0
def _insert_namespaces_mapping(blueprint_holder, mapping):
    key_holder = Holder(constants.NAMESPACES_MAPPING)
    blueprint_holder.value[key_holder] = Holder({})
    value_holder = blueprint_holder.value[key_holder]

    for namespace, blueprint_id in mapping.items():
        namespace_holder = Holder(namespace)
        value_holder.value[namespace_holder] = Holder(blueprint_id)
示例#3
0
def _insert_new_element(target_holder, key_holder, value_holder, namespace):
    if isinstance(value_holder.value, dict) and namespace:
        # At this level (second level) in the blueprint there are only dict
        # or string, and namespacing is only applied to dict elements.
        new_element = Holder({})
        _merge_into_dict_or_throw_on_duplicate(from_dict_holder=value_holder,
                                               to_dict_holder=new_element,
                                               key_name=key_holder.value,
                                               namespace=namespace)
        target_holder.value[key_holder] = new_element
    else:
        target_holder.value[key_holder] = value_holder
示例#4
0
    def build_ordered_imports_recursive(_current_parsed_dsl_holder,
                                        _current_import,
                                        context_namespace=None,
                                        dsl_version=None):
        imports_key_holder, imports_value_holder = _current_parsed_dsl_holder.\
            get_item(constants.IMPORTS)
        if not imports_value_holder:
            return

        for another_import in imports_value_holder.restore():
            namespace, import_url = _extract_import_parts(
                another_import, resources_base_path, _current_import,
                dsl_version)
            validate_namespace(namespace)
            if context_namespace:
                if namespace:
                    namespace = utils.generate_namespaced_value(
                        context_namespace, namespace)
                else:
                    # In case a namespace was added earlier in the import
                    # chain.
                    namespace = context_namespace
            if import_url is None:
                ex = exceptions.DSLParsingLogicException(
                    13, "Import failed: no suitable location found for "
                    "import '{0}'".format(another_import))
                ex.failed_import = another_import
                raise ex

            if utils.is_blueprint_import(import_url):
                validate_blueprint_import_namespace(namespace, import_url)
                blueprint_id = utils.remove_blueprint_import_prefix(import_url)
                blueprint_imports.add(blueprint_id)
                add_namespace_to_mapping(blueprint_id, namespace)

            import_key = resolve_import_graph_key(import_url, namespace)
            import_context = (location(_current_import), context_namespace)
            if import_key in imports_graph:
                is_cloudify_types = imports_graph[import_key]['cloudify_types']
                validate_import_namespace(namespace, is_cloudify_types,
                                          context_namespace)
                imports_graph.add_graph_dependency(import_url, import_context,
                                                   namespace)
            else:
                imported_dsl = resolver.fetch_import(import_url,
                                                     dsl_version=dsl_version)
                if not is_parsed_resource(imported_dsl):
                    imported_dsl = utils.load_yaml(
                        raw_yaml=imported_dsl,
                        error_message="Failed to parse import '{0}'"
                        "(via '{1}')".format(another_import, import_url),
                        filename=import_url)
                try:
                    plugin = resolver.retrieve_plugin(import_url)
                except InvalidBlueprintImport:
                    plugin = None
                if plugin:
                    # If it is a plugin, then use labels and tags from the DB
                    utils.remove_dsl_keys(
                        imported_dsl, constants.PLUGIN_DSL_KEYS_NOT_FROM_YAML)
                    for key in constants.PLUGIN_DSL_KEYS_READ_FROM_DB:
                        if not plugin.get(key):
                            continue
                        value = plugin[key]
                        if key in constants.PLUGIN_DSL_KEYS_ADD_VALUES_NODE:
                            value = utils.add_values_node_description(value)
                        _merge_into_dict_or_throw_on_duplicate(
                            Holder.of({key: value}), imported_dsl, key,
                            namespace)
                cloudify_basic_types = is_cloudify_basic_types(imported_dsl)
                validate_import_namespace(namespace, cloudify_basic_types,
                                          context_namespace)
                if cloudify_basic_types:
                    # Remove namespace data from import
                    namespace = None
                imports_graph.add(import_url, imported_dsl,
                                  cloudify_basic_types, import_context,
                                  namespace)
                build_ordered_imports_recursive(imported_dsl, import_url,
                                                namespace, dsl_version)