Is it possible to edit the prefix list and policy statements through pyez in juniper router.
Device details
junos version : 15.1f5, Device : juniper mx240
And i am using pyez on top of netconf to automate
Is it possible to edit the prefix list and policy statements through pyez in juniper router.
Device details
junos version : 15.1f5, Device : juniper mx240
And i am using pyez on top of netconf to automate
PyEZ has Config utility which allows you to add configuration and commit it. You can supply your config in the following formats:
So you don't have to build rpc on your own.
Below is simple example:
from jnpr.junos import Device
from jnpr.junos.utils.config import Config
dev = Device(host='somehost', username='username', password='password')
dev.open()
dev.bind(cu=Config)
set_command = []
ip = ['172.30.0.0/24', '172.30.1.0/24']
for i in ip:
set_command.append(
"set policy-options policy-statement new term 1 from route-filter {} exact"
.format(
i.rstrip("\n")
))
set_command.append("set policy-options policy-statement new term 1 from protocol static")
set_command.append("set policy-options policy-statement new term 1 then accept")
set_command.append("set policy-options policy-statement new term default then reject")
print set_command
rsp = dev.cu.load("\n".join(set_command), format='set')
print dev.cu.diff()
if dev.cu.commit_check():
if dev.cu.commit():
print "Done"
You can use PyEZ to edit/set any hierarchy (allowed to the script user) in Junos configuration residing on the RE.