Exemplo n.º 1
0
def pyang_plugin_init():
    """Called by pyang plugin framework at to initialize the plugin."""

    # Register the plugin
    plugin.register_plugin(RESTCONFPlugin())

    # Register that we handle extensions from the YANG module 'ietf-restconf'
    grammar.register_extension_module(restconf_module_name)

    yd = (restconf_module_name, 'yang-data')
    statements.add_data_keyword(yd)
    statements.add_keyword_with_children(yd)
    statements.add_keywords_with_no_explicit_config(yd)

    # Register the special grammar
    for (stmt, occurance, (arg, rules), add_to_stmts) in restconf_stmts:
        grammar.add_stmt((restconf_module_name, stmt), (arg, rules))
        grammar.add_to_stmts_rules(add_to_stmts,
                                   [((restconf_module_name, stmt), occurance)])

    # Add validation functions
    statements.add_validation_fun('expand_2', [yd], v_yang_data)

    # Register special error codes
    error.add_error_code(
        'RESTCONF_YANG_DATA_CHILD', 1,
        "the 'yang-data' extension must have exactly one " +
        "child that is a container")
Exemplo n.º 2
0
def pyang_plugin_init():
    """Called by pyang plugin framework at to initialize the plugin."""

    # Register the plugin
    plugin.register_plugin(RESTCONFPlugin())

    # Register that we handle extensions from the YANG module 'ietf-restconf'
    grammar.register_extension_module(restconf_module_name)

    yd = (restconf_module_name, 'yang-data')
    statements.add_data_keyword(yd)
    statements.add_keyword_with_children(yd)
    statements.add_keywords_with_no_explicit_config(yd)

    # Register the special grammar
    for (stmt, occurance, (arg, rules), add_to_stmts) in restconf_stmts:
        grammar.add_stmt((restconf_module_name, stmt), (arg, rules))
        grammar.add_to_stmts_rules(add_to_stmts,
                                   [((restconf_module_name, stmt), occurance)])

    # Add validation functions
    statements.add_validation_fun('expand_2',
                                  [yd],
                                  v_yang_data)

    # Register special error codes
    error.add_error_code('RESTCONF_YANG_DATA_CHILD', 1,
                         "the 'yang-data' extension must have exactly one " +
                         "child that is a container")
Exemplo n.º 3
0
def pyang_plugin_init():
    """Called by pyang plugin framework at to initialize the plugin."""

    # Register the plugin
    plugin.register_plugin(StructurePlugin())

    # Register that we handle extensions from the YANG module
    # 'ietf-yang-structure-ext'
    grammar.register_extension_module(module_name)

    sx = (module_name, 'structure')
    statements.add_data_keyword(sx)
    statements.add_keyword_with_children(sx)
    statements.add_keywords_with_no_explicit_config(sx)
    asx = (module_name, 'augment-structure')
    statements.add_data_keyword(asx)
    statements.add_keyword_with_children(asx)
    statements.add_keywords_with_no_explicit_config(asx)

    # Register the special grammar
    for (stmt, occurance, (arg, rules), add_to_stmts) in structure_stmts:
        grammar.add_stmt((module_name, stmt), (arg, rules))
        grammar.add_to_stmts_rules(add_to_stmts,
                                   [((module_name, stmt), occurance)])
Exemplo n.º 4
0
def pyang_plugin_init():
    """Called by pyang plugin framework at to initialize the plugin."""
    # Register the plugin
    plugin.register_plugin(ComplexTypesPlugin())

    # check whether the plugin is enabled
    try:
        sys.argv.index("--enable-complex-types")
    except ValueError:
        return

   
    # Register that we handle extensions from the YANG module 'complex-types' 
    grammar.register_extension_module(ct_module_name)

    # Register the special grammar
    for (stmt, occurance, (arg, rules), add_to_stmts) in complex_types_stmts:
        grammar.add_stmt((ct_module_name, stmt), (arg, rules))
        grammar.add_to_stmts_rules(add_to_stmts,
                                   [((ct_module_name, stmt), occurance)])

    # Add validation steps
    # init phase: initalizes the module/submodule statements
    statements.add_validation_phase('init_complex_type', after='init2')
    # grammar phase:
    # verifies that all complex-types are unique within a parent node
    statements.add_validation_phase('post_grammar_complex_type',
                                        after='grammar')
    # include phase: loads complex-types from a submodule and
    # checks for complex-type collisions in a submodule
    statements.add_validation_phase('include_complex_type', after='import')
    # validate typed instance identifiers
    statements.add_validation_phase('instance_type', after='type')
    # expand the 'extends' statements;
    statements.add_validation_phase('instantiate_extends', after='expand_1')
    # instantiate all 'instance'/'instance-list' statements;
    # this phase should be marked as v_i_children (validate i_children
    # instead of substatemets) so that we could expand the 'instance'/
    # 'instance-list' created by augmentation nested into a 'uses' statement;
    statements.add_validation_phase('instantiate_instance',
                                        after='instantiate_extends')
    statements.set_phase_i_children('instantiate_instance')
    # inherit 'config' properties for statements nested into 'complex-type';
    # set 'i_config' values;
    statements.add_validation_phase('inherit_properties_complex_type',
                                        after='inherit_properties')
    # validate augmentation statements that refer to 'instace'/'instance-list'
    statements.add_validation_phase('pre_expand_2', before='expand_2')
    # unique names phase: checks for complex type collisions in submodules
    statements.add_validation_phase('unique_name_complex_type',
                                        before='unique_name')
    # expand all recursive datastructures reffered by deviation
    statements.add_validation_phase('pre_reference_2', before='reference_2')

    # Add functions to the validation map
    statements.add_validation_fun('init_complex_type',
                                  ['*'],
                                  v_init_complex_type)

    statements.add_validation_fun('post_grammar_complex_type',
                                  ['*'],
                                  v_post_grammar_complex_type)

    statements.add_validation_fun('include_complex_type',
                                  ['module', 'submodule'],
                                  v_include_complex_type)

    statements.add_validation_fun('type',
                                  [(ct_module_name, str_complex_type)],
                                  v_type_complex_type)

    statements.add_validation_fun('type',
                                  [(ct_module_name, str_instance),
                                  (ct_module_name, str_instance_list)],
                                  v_type_instance)

    statements.add_validation_fun('instance_type',
                                  [(ct_module_name, str_instance_type)],
                                  v_type_instance_type)

    statements.add_validation_fun('instantiate_extends',
                                  [(ct_module_name, str_complex_type)],
                                  v_instantiate_extends)

    statements.add_validation_fun('instantiate_instance',
                                  [(ct_module_name, str_instance),
                                  (ct_module_name, str_instance_list)],
                                  v_instantiate_instance)

    statements.add_validation_fun('inherit_properties_complex_type',
                                  [(ct_module_name, str_complex_type)],
                                  v_inherit_properties_complex_type)

    statements.add_validation_fun('pre_expand_2',
                                  ['augment'],
                                  v_pre_expand_2_augment)

    statements.add_validation_fun('unique_name_complex_type',
                                  ['module'],
                                  v_unique_name_complex_type)

    statements.add_validation_fun('pre_reference_2',
                                  ['deviation'],
                                  v_reference_load_recursive_nodes)

    statements.add_validation_fun('reference_1',
                                  [(ct_module_name, str_complex_type)],
                                  v_reference_complex_type)

    statements.add_validation_fun('reference_2',
                                  [(ct_module_name, str_instance_list)],
                                  v_reference_instance_list)

    statements.add_validation_fun('unused',
                                  [(ct_module_name, str_complex_type)],
                                  v_unused_complex_type)

    # Add 'complex-type'/'instance'/'instance-list' to keywords with children
    statements.add_keyword_with_children((ct_module_name, str_complex_type))
    statements.add_keyword_with_children((ct_module_name, str_instance))
    statements.add_keyword_with_children((ct_module_name, str_instance_list))

    # Add 'instance' and 'instance-list' to the data keywords
    statements.add_data_keyword((ct_module_name, str_instance))
    statements.add_data_keyword((ct_module_name, str_instance_list))

    # add 'instance'/'instance-list' to the possible refinements
    statements.add_refinement_element('description',
                                        (ct_module_name, str_instance))
    statements.add_refinement_element('description',
                                        (ct_module_name, str_instance_list))
    statements.add_refinement_element('reference',
                                        (ct_module_name, str_instance))
    statements.add_refinement_element('reference',
                                        (ct_module_name, str_instance_list))
    statements.add_refinement_element('config', (ct_module_name, str_instance))
    statements.add_refinement_element('config',
                                        (ct_module_name, str_instance_list))
    statements.add_refinement_element('must', (ct_module_name, str_instance))
    statements.add_refinement_element('must',
                                        (ct_module_name, str_instance_list))
    statements.add_refinement_element('mandatory',
                                        (ct_module_name, str_instance))
    statements.add_refinement_element('min-elements',
                                        (ct_module_name, str_instance_list))
    statements.add_refinement_element('max-elements',
                                        (ct_module_name, str_instance_list))

    # add possibale deviation types for 'instance'/'instance-list' statements
    statements.add_deviation_element('config', (ct_module_name, str_instance))
    statements.add_deviation_element('config',
                                        (ct_module_name, str_instance_list))
    statements.add_deviation_element('must', (ct_module_name, str_instance))
    statements.add_deviation_element('must',
                                        (ct_module_name, str_instance_list))
    statements.add_deviation_element('mandatory',
                                        (ct_module_name, str_instance))
    statements.add_deviation_element('min-elements',
                                        (ct_module_name, str_instance_list))
    statements.add_deviation_element('max-elements',
                                        (ct_module_name, str_instance_list))

    # define additional error messages:
    error.add_error_code('COMPLEX_TYPE_ALREADY_DEFINED', 1,
        'complex-type "%s" is already defined at %s')
    error.add_error_code('COMPLEX_TYPE_NOT_FOUND', 1,
        'complex type "%s" not found in module "%s"')
    error.add_error_code('ABSTRACT_NOT_ALLOWED', 1,
        'base complex type "%s" of abstract type "%s" must be abstract')
    error.add_error_code('ABSTRACT_NOT_INSTANTIATED', 1,
        'abstract complex type "%s" can not be instantiated')
    error.add_error_code('UNUSED_COMPLEX_TYPE', 4,
        'complex type "%s" not used')
    error.add_error_code('REDEFINED_KEY', 1,
        'key for complex type "%s" is already defined in base type "%s" at %s')
    error.add_error_code('KEY_REQUIRED', 1,
        'complex-type "%s" instantiated at %s with config true must have key')
    error.add_error_code('REFINE_NOT_INHERITED', 1,
        '"refine" can not be applied to non-inherited node "%s" defined at %s')
    error.add_error_code('BAD_REF_AUG', 1,
        'refinement and augmentation of instance "%s" at %s is not allowed')
    error.add_error_code('MANDATORY_AUGMENTATION', 1,
        'the node "%s" at %s added by the augmentation must not be mandatory')
    error.add_error_code('INSTANCE_IDENTIFIER_REQUIRED', 1,
        'instance-type may not be specified for "%s" type')