Пример #1
0
def _parse(dsl_string, resources_base_url, dsl_location=None):
    parsed_dsl_holder = utils.load_yaml(raw_yaml=dsl_string,
                                        error_message='Failed to parse DSL',
                                        filename=dsl_location)

    # validate version
    result = parser.parse(parsed_dsl_holder,
                          element_cls=blueprint.BlueprintVersionExtractor,
                          strict=False)
    version = result['plan_version']

    # handle imports
    result = parser.parse(
        value=parsed_dsl_holder,
        inputs={
            'main_blueprint_holder': parsed_dsl_holder,
            'resources_base_url': resources_base_url,
            'blueprint_location': dsl_location,
            'version': version
        },
        element_cls=blueprint.BlueprintImporter,
        strict=False)
    resource_base = result['resource_base']
    merged_blueprint_holder = result['merged_blueprint']

    # parse blueprint
    plan = parser.parse(
        value=merged_blueprint_holder,
        inputs={
            'resource_base': resource_base
        },
        element_cls=blueprint.Blueprint)

    functions.validate_functions(plan)
    return plan
Пример #2
0
def validate(obj, element_cls):
    class TestElement(Element):
        schema = {
            'tosca_definitions_version': misc.ToscaDefinitionsVersion,
            'test': element_cls
        }
    obj = {
        'tosca_definitions_version': 'cloudify_dsl_1_1',
        'test': obj
    }
    parser.parse(obj, element_cls=TestElement, strict=True)
Пример #3
0
def _parse(dsl_string,
           resources_base_path,
           dsl_location=None,
           resolver=None,
           validate_version=True,
           additional_resource_sources=()):
    parsed_dsl_holder = utils.load_yaml(raw_yaml=dsl_string,
                                        error_message='Failed to parse DSL',
                                        filename=dsl_location)

    if not resolver:
        resolver = DefaultImportResolver()

    # validate version schema and extract actual version used
    result = parser.parse(
        parsed_dsl_holder,
        element_cls=blueprint.BlueprintVersionExtractor,
        inputs={
            'validate_version': validate_version
        },
        strict=False)
    version = result['plan_version']

    # handle imports
    result = parser.parse(
        value=parsed_dsl_holder,
        inputs={
            'main_blueprint_holder': parsed_dsl_holder,
            'resources_base_path': resources_base_path,
            'blueprint_location': dsl_location,
            'version': version,
            'resolver': resolver,
            'validate_version': validate_version
        },
        element_cls=blueprint.BlueprintImporter,
        strict=False)
    resource_base = [result['resource_base']]
    if additional_resource_sources:
        resource_base.extend(additional_resource_sources)

    merged_blueprint_holder = result['merged_blueprint']

    # parse blueprint
    plan = parser.parse(
        value=merged_blueprint_holder,
        inputs={
            'resource_base': resource_base,
            'validate_version': validate_version
        },
        element_cls=blueprint.Blueprint)

    functions.validate_functions(plan)
    return plan
def validate(obj, element_cls):
    class TestElement(Element):
        schema = {
            'tosca_definitions_version': version.ToscaDefinitionsVersion,
            'test': element_cls,
            'data_types': data_types.DataTypes
        }
    obj = {
        'tosca_definitions_version': 'cloudify_dsl_1_1',
        'test': obj
    }
    parser.parse(obj,
                 element_cls=TestElement,
                 inputs={
                     'validate_version': True
                 },
                 strict=True)
Пример #5
0
def _parse(dsl_string, resources_base_url, dsl_location=None, resolver=None, validate_version=True):
    parsed_dsl_holder = utils.load_yaml(raw_yaml=dsl_string, error_message="Failed to parse DSL", filename=dsl_location)

    if not resolver:
        resolver = DefaultImportResolver()

    # validate version schema and extract actual version used
    result = parser.parse(
        parsed_dsl_holder,
        element_cls=blueprint.BlueprintVersionExtractor,
        inputs={"validate_version": validate_version},
        strict=False,
    )
    version = result["plan_version"]

    # handle imports
    result = parser.parse(
        value=parsed_dsl_holder,
        inputs={
            "main_blueprint_holder": parsed_dsl_holder,
            "resources_base_url": resources_base_url,
            "blueprint_location": dsl_location,
            "version": version,
            "resolver": resolver,
            "validate_version": validate_version,
        },
        element_cls=blueprint.BlueprintImporter,
        strict=False,
    )
    resource_base = result["resource_base"]
    merged_blueprint_holder = result["merged_blueprint"]

    # parse blueprint
    plan = parser.parse(
        value=merged_blueprint_holder,
        inputs={"resource_base": resource_base, "validate_version": validate_version},
        element_cls=blueprint.Blueprint,
    )

    functions.validate_functions(plan)
    return plan
 def assert_valid(self, value, element_cls, strict=True):
     self.assertEqual(parser.parse(value=value,
                                   element_cls=element_cls,
                                   strict=strict),
                      value)