Skip to content

Instantly share code, notes, and snippets.

@rwestphal
Created September 4, 2018 04:14
Show Gist options
  • Save rwestphal/defa9bd1ccf216ab082d4711ae402f95 to your computer and use it in GitHub Desktop.
Save rwestphal/defa9bd1ccf216ab082d4711ae402f95 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
Create configuration for model frr-ripd.
usage: ydk_ripd_test_netconf.py [-h] [-v] device
positional arguments:
device NETCONF device (ssh://user:password@host:port)
optional arguments:
-h, --help show this help message and exit
-v, --verbose print debugging messages
"""
from argparse import ArgumentParser
from urlparse import urlparse
from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.models.frr import frr_interface as frr_interface
from ydk.models.frr import frr_ripd as frr_ripd
from ydk.models.frr import frr_route_types as frr_route_types
import logging
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("-v", "--verbose", help="print debugging messages",
action="store_true")
parser.add_argument("device",
help="NETCONF device (ssh://user:password@host:port)")
args = parser.parse_args()
device = urlparse(args.device)
# log debug messages if verbose argument specified
if args.verbose:
logger = logging.getLogger("ydk")
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
formatter = logging.Formatter(("%(asctime)s - %(name)s - "
"%(levelname)s - %(message)s"))
handler.setFormatter(formatter)
logger.addHandler(handler)
# create NETCONF provider
provider = NetconfServiceProvider(address=device.hostname,
port=device.port,
username=device.username,
password=device.password,
protocol=device.scheme)
# create CRUD service
crud = CRUDService()
# create frr-interface object
lib_iface = frr_interface.Lib()
iface = lib_iface.Interface()
iface.name = "eth0"
iface.vrf = "default"
iface.description = "Engineering Department"
iface.rip = iface.Rip()
iface.rip.split_horizon = iface.rip.SplitHorizon.poison_reverse
iface.rip.version_receive = iface.rip.VersionReceive.both
iface.rip.v2_broadcast = True
lib_iface.interface.append(iface)
# submit configuration to NETCONF device
crud.create(provider, lib_iface)
# create frr-ripd object
rip = frr_ripd.Ripd()
rip.instance = rip.Instance()
rip.instance.allow_ecmp = True
rip.instance.default_information_originate = True
rip.instance.default_metric = 10
rip.instance.network.append("10.0.1.0/24")
rip.instance.network.append("10.0.2.0/24")
rip.instance.passive_interface.append("eth0")
rip.instance.timers = rip.instance.Timers()
rip.instance.timers.flush_interval = 50
rip.instance.timers.holddown_interval = 80
redistribute = rip.instance.Redistribute()
redistribute.protocol = frr_route_types.FrrRouteTypesV4.isis
redistribute.route_map = 'FILTER_VLAN_10'
redistribute.metric = 2
rip.instance.redistribute.append(redistribute)
# submit configuration to NETCONF device
crud.create(provider, rip)
exit()
# End of script
@duanzhili
Copy link

when i test this script with my frr router,i found there have no module ydk.models.frr,could you share it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment