def main(): for k, v in eos_bgp.iteritems(): ocbgp = ocbind.openconfig_bgp(path_helper=ph) ocbgp.bgp.global_.config.as_ = v['AS'] ocbgp.bgp.global_.config.router_id = v['ROUTER_ID'] ocbgp.bgp.neighbors.neighbor.add(str(v['PEER'])) ocbgp.bgp.neighbors.neighbor[str( v['PEER'])].config.peer_as = v['PEER_AS'] struct = json.dumps(json.loads(pybindJSON.dumps(ocbgp)), indent=4, sort_keys=True) print struct with open(k, 'w') as f: f.write(struct)
#!/usr/bin/python from ocbind import openconfig_bgp import json import pyangbind.lib.pybindJSON as pybindJSON ocbgp = openconfig_bgp() ocbgp.bgp.global_.config.as_ = 1 #Configures the rw bgp - > global - > config passes in the oc-inet:as-number ocbgp.bgp.global_.config.router_id = "1.1.1.1" #Passes in the rw bgp - > global - > config - > router-id passes in the oc-yang:dotted-quad ocbgp.bgp.neighbors.neighbor.add("10.12.0.2") ocbgp.bgp.neighbors.neighbor["10.12.0.2"].config.neighbor_address = "10.12.0.2" ocbgp.bgp.neighbors.neighbor["10.12.0.2"].config.peer_as = 10 ocbgp.bgp.neighbors.neighbor["10.12.0.2"].config.description = "Spine 1" print(pybindJSON.dumps(ocbgp, mode="ietfww")) json_data = pybindJSON.dumps(ocbgp, mode="ietf") with open("../../../flask/static/demo.json", 'w') as f: f.write(json_data)
def __init__(self, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs) import ocbind self.ph = YANGPathHelper() self.instance = ocbind.openconfig_bgp(path_helper=self.ph)
#!/usr/bin/env python import sys import os sys.path.append("pyangbind/pyangbind/") import pyangbind.lib.pybindJSON as pybindJSON import pyangbind.lib.xpathhelper as xpathhelper import json import ocbind from pyangbind.lib.serialise import pybindJSONDecoder ph = xpathhelper.YANGPathHelper() ocbgp = ocbind.openconfig_bgp(path_helper=ph) ocbgp.bgp.global_.config.as_ = 1 ocbgp.bgp.global_.config.router_id = "1.1.1.1" struct = json.dumps(ocbgp.get(filter=True), indent=4) print struct with open('simple.json', 'w') as f: f.write(struct) I