summaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/pyang_plugins/README.rst3
-rw-r--r--tools/pyang_plugins/bgpyang2golang.py27
2 files changed, 29 insertions, 1 deletions
diff --git a/tools/pyang_plugins/README.rst b/tools/pyang_plugins/README.rst
index 7fcb3018..4d45904e 100644
--- a/tools/pyang_plugins/README.rst
+++ b/tools/pyang_plugins/README.rst
@@ -18,4 +18,5 @@ How to use
$ source ./env.sh
$ PYTHONPATH=. ./bin/pyang --plugindir $GOBGP_PATH/tools/pyang_plugins \
-p $YANG_DIR/bgp -p $YANG_DIR/policy \
- -f golang $YANG_DIR/bgp/bgp.yang |gofmt > $GOBGP_PATH/config/bgp_configs.go
+ -f golang $YANG_DIR/bgp/bgp.yang \
+ --augment $YANG_DIR/bgp/bgp-policy.yang |gofmt > $GOBGP_PATH/config/bgp_configs.go
diff --git a/tools/pyang_plugins/bgpyang2golang.py b/tools/pyang_plugins/bgpyang2golang.py
index c61d9c85..765e2f12 100644
--- a/tools/pyang_plugins/bgpyang2golang.py
+++ b/tools/pyang_plugins/bgpyang2golang.py
@@ -14,6 +14,7 @@
# limitations under the License.
+import optparse
import StringIO
import sys
from pyang import plugin
@@ -46,6 +47,19 @@ class GolangPlugin(plugin.PyangPlugin):
def add_output_format(self, fmts):
fmts['golang'] = self
+
+
+ def add_opts(self, optparser):
+ optlist = [
+ optparse.make_option("--augment",
+ dest="augment",
+ 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 = {}
@@ -57,6 +71,19 @@ class GolangPlugin(plugin.PyangPlugin):
ctx.module_deps = []
check_module_deps(ctx, modules[0])
+
+ # load augment module
+ if ctx.opts.augment:
+ aug_mod_path = ctx.opts.augment
+ try:
+ fd = open(aug_mod_path)
+ 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(aug_mod_path, text)
+ check_module_deps(ctx, aug_mod)
+
# visit yang statements
visit_modules(ctx)
# emit bgp_configs