diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-07-11 18:49:57 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-01-09 05:17:57 -0800 |
commit | 26c03bb779fbb59bb3de1c98a2c9d65e192b50bb (patch) | |
tree | f68629f1089561e494b26291bf3ec548c7eb93ef /tools | |
parent | 6733b6afb27f3dd3943d8325d2656f9e98740c17 (diff) |
tools: avoid adding a new option to bgpyang2golang.py and fix gobgp.yang
pyang has an internal flag "multiple_modules" to handle multiple yang modules.
use it instead of introducing a new option --augment
also, fix warnings and errors in gobgp.yang which were there but not has been
detected for a while due to the usage of --augment.
by using "multiple_modules" flag, pyang detected them.
most notable error is wrong usage of list, which needs a key in its
substatement.
this patch adds key to some of them, and for others uses leaf-list
instead.
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/pyang_plugins/README.rst | 4 | ||||
-rw-r--r-- | tools/pyang_plugins/bgpyang2golang.py | 34 | ||||
-rw-r--r-- | tools/pyang_plugins/gobgp.yang | 71 |
3 files changed, 44 insertions, 65 deletions
diff --git a/tools/pyang_plugins/README.rst b/tools/pyang_plugins/README.rst index eaf3f89e..10b44d71 100644 --- a/tools/pyang_plugins/README.rst +++ b/tools/pyang_plugins/README.rst @@ -21,6 +21,6 @@ How to use -p $YANG_DIR/experimental/openconfig/bgp \ -p $YANG_DIR/experimental/openconfig/policy \ -f golang $YANG_DIR/experimental/openconfig/bgp/bgp.yang \ - --augment $YANG_DIR/experimental/openconfig/bgp/bgp-policy.yang \ - --augment $GOBGP_PATH/tools/pyang_plugins/gobgp.yang \ + $YANG_DIR/bgp/bgp.yang $YANG_DIR/bgp/bgp-policy.yang \ + $GOBGP_PATH/tools/pyang_plugins/gobgp.yang \ | gofmt > $GOBGP_PATH/config/bgp_configs.go diff --git a/tools/pyang_plugins/bgpyang2golang.py b/tools/pyang_plugins/bgpyang2golang.py index ed02b451..3b7702e9 100644 --- a/tools/pyang_plugins/bgpyang2golang.py +++ b/tools/pyang_plugins/bgpyang2golang.py @@ -45,21 +45,9 @@ def pyang_plugin_init(): class GolangPlugin(plugin.PyangPlugin): def add_output_format(self, fmts): + self.multiple_modules = True fmts['golang'] = self - - - def add_opts(self, optparser): - optlist = [ - optparse.make_option("--augment", - dest="augment", action="append", - help="Yang file which has augment statements"), - ] - g = optparser.add_option_group("GolangPlugin specific options") - g.add_options(optlist) - - - def emit(self, ctx, modules, fd): ctx.golang_identity_map = {} @@ -70,20 +58,8 @@ class GolangPlugin(plugin.PyangPlugin): ctx.prefix_rel = {} ctx.module_deps = [] - check_module_deps(ctx, modules[0]) - - # load augment module - if ctx.opts.augment: - aug_mod_path = ctx.opts.augment - for p in aug_mod_path: - with open(p) as fd: - try: - text = fd.read() - except IOError as ex: - sys.stderr.write("error %s: %s\n" % (aug_mod_path, str(ex))) - sys.exit(1) - aug_mod = ctx.add_module(p, text) - check_module_deps(ctx, aug_mod) + for m in modules: + check_module_deps(ctx, m) # visit yang statements visit_modules(ctx) @@ -207,6 +183,8 @@ def emit_class_def(ctx, yang_statement, struct_name, prefix): if is_leaflist(child): type_obj = child.search_one('type') type_name = type_obj.arg + val_name_go = val_name_go + 'List' + tag_name += '-list' # case leafref if type_name == 'leafref': @@ -532,7 +510,7 @@ _type_translation_map = { 'inet:ip-prefix': 'string', 'inet:ipv4-address': 'string', 'inet:as-number': 'uint32', - 'bgp-set-community-option-type' : 'string', + 'bgp-set-community-option-type': 'string', 'identityref' : 'string', 'inet:port-number': 'uint16', 'yang:timeticks': 'int64', diff --git a/tools/pyang_plugins/gobgp.yang b/tools/pyang_plugins/gobgp.yang index c849127e..73f886ad 100644 --- a/tools/pyang_plugins/gobgp.yang +++ b/tools/pyang_plugins/gobgp.yang @@ -1,4 +1,4 @@ -module bgp-gobgp { +module gobgp { yang-version "1"; @@ -13,6 +13,7 @@ module bgp-gobgp { import policy-types {prefix ptypes; } import bgp-policy {prefix bgp-pol; } import ietf-inet-types { prefix inet; } + import ietf-yang-types { prefix yang; } // meta organization @@ -403,12 +404,16 @@ module bgp-gobgp { description "additional RPKI structure"; container rpki-servers { - description - "List of RPKI servers configured on the local system"; list rpki-server { - container rpki-server { - uses gobgp-rpki-server-set; + key "address"; + description + "List of RPKI servers configured on the local system"; + leaf address { + type leafref { + path "../config/address"; + } } + uses gobgp-rpki-server-set; } } } @@ -457,12 +462,16 @@ module bgp-gobgp { description "BGP Monitoring Protocol servers"; container bmp-servers { - description - "List of BMP servers configured on the local system"; list bmp-server { - container bmp-server { - uses gobgp-bmp-server-set; + key "address"; + description + "List of BMP servers configured on the local system"; + leaf address { + type leafref { + path "../config/address"; + } } + uses gobgp-bmp-server-set; } } } @@ -568,12 +577,10 @@ module bgp-gobgp { augment "/rpol:routing-policy/rpol:defined-sets/rpol:neighbor-sets/rpol:neighbor-set" { description "alternative for the existing neighbor element"; - list neighbor-info { - leaf address { - type inet:ip-address; - description + leaf-list neighbor-info { + description "neighbor ip address"; - } + type inet:ip-address; } } @@ -581,12 +588,10 @@ module bgp-gobgp { "bgp-pol:bgp-defined-sets/bgp-pol:community-sets/bgp-pol:community-set" { description "alternative for the existing community-member"; - list community { - leaf community { - type string; - description - "community set member"; - } + leaf-list community { + description + "community set member"; + type string; } } @@ -594,12 +599,10 @@ module bgp-gobgp { "bgp-pol:bgp-defined-sets/bgp-pol:ext-community-sets/bgp-pol:ext-community-set" { description "alternative for the existing ext-community-member"; - list ext-community { - leaf ext-community { - type string; - description - "extended community set member"; - } + leaf-list ext-community { + type string; + description + "extended community set member"; } } @@ -607,12 +610,10 @@ module bgp-gobgp { "bgp-pol:bgp-defined-sets/bgp-pol:as-path-sets/bgp-pol:as-path-set" { description "alternative for the existing as-path-set-member"; - list as-path { - leaf as-path { - type string; - description - "AS path expression"; - } + leaf-list as-path { + type string; + description + "AS path expression"; } } @@ -661,9 +662,9 @@ module bgp-gobgp { description "Configure url for zebra."; } - list redistribute-route-type { - leaf route-type { - type ptypes:install-protocol-type; + leaf-list redistribute-route-type { + type identityref { + base ptypes:install-protocol-type; } } } |