summaryrefslogtreecommitdiffhomepage
path: root/tools/pyang_plugins
diff options
context:
space:
mode:
authorHiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp>2015-04-24 20:30:30 +0900
committerHiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp>2015-04-24 20:33:17 +0900
commit99133709be6c555b814347f7deb34f45129be5dd (patch)
tree45c206c8c25814ed0e7a4381b73c932bb29e90c2 /tools/pyang_plugins
parentf7401e177a2a60d6537339e6ee11576d23f32c41 (diff)
config: add bgp-policy configuration
Diffstat (limited to 'tools/pyang_plugins')
-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