From a34d8d2651877998fe01d35350259c979a49d295 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Thu, 21 Apr 2016 08:48:24 +0000 Subject: config: simplify config structures stop generating self-contained leafref fields in openconfig model. (e.g. bgp:neighbor/bgp:neighbor-address ) Signed-off-by: ISHIDA Wataru --- tools/pyang_plugins/bgpyang2golang.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'tools/pyang_plugins') diff --git a/tools/pyang_plugins/bgpyang2golang.py b/tools/pyang_plugins/bgpyang2golang.py index 0ab5ab59..1f6ee7d0 100644 --- a/tools/pyang_plugins/bgpyang2golang.py +++ b/tools/pyang_plugins/bgpyang2golang.py @@ -168,6 +168,8 @@ def emit_class_def(ctx, yang_statement, struct_name, prefix): # case leafref elif type_name == 'leafref': + if type_obj.search_one('path').arg.startswith('../config'): + continue t = dig_leafref(type_obj) if is_translation_required(t): print >> o, ' //%s:%s\'s original type is %s' \ @@ -243,7 +245,10 @@ def emit_class_def(ctx, yang_statement, struct_name, prefix): l = t.i_children[0] emit_type_name = '[]' + l.golang_name equal_type = EQUAL_TYPE_MAP - equal_data = t.i_children[0].search_one('key').arg + equal_data = l.search_one('key').arg + leaf = l.search_one('leaf').search_one('type') + if leaf.arg == 'leafref' and leaf.search_one('path').arg.startswith('../config'): + equal_data = 'config.' + equal_data else: emit_type_name = t.golang_name equal_type = EQUAL_TYPE_CONTAINER @@ -692,9 +697,9 @@ def translate_type(key): # 'hoge-hoge' -> 'HogeHoge' def convert_to_golang(type_string): - a = type_string.split('-') + a = type_string.split('.') a = map(lambda x: x.capitalize(), a) # XXX locale sensitive - return ''.join(a) + return '.'.join( ''.join(t.capitalize() for t in x.split('-')) for x in a) # 'hoge-hoge' -> 'HOGE_HOGE' -- cgit v1.2.3