JUNOS PYEZ: Over write the Base config of a Device in SET command

693 views Asked by At

I am writing the below code to push the base config to my device. But it is merging the lines and not over writing.

Merging is still keeping the not required lines of Base config which is a problem to me

My config is in set command format . Can some one help me achieve the over write option. Can some one tell me how to convert my set formats to .xml formats so that over write function could be used.

/usr/bin/python

-- coding: utf-8 -

from jnpr.junos import Device
from jnpr.junos.utils.config import Config

dev = Device(host='host', port='22', user='maint', password='jnpr16',
         gather_facts=False)

dev.open()
cu = Config(dev)
data ="""set version 14.2R5-S1.2
set groups re0 system host-name host
set groups re0 interfaces fxp0 unit 0 family inet address 10.202.64/24 
master-only
set groups CUST-NAT-POOL-TEMPLATE services nat pool <*> snmp-trap-
thresholds"""

cu.load(data)
if cu.commit_check():
cu.commit()
else:
cu.rollback()
2

There are 2 answers

0
Nitin Kr On

Check this doc link

http://junos-pyez.readthedocs.io/en/2.1.2/jnpr.junos.utils.html#jnpr.junos.utils.config.Config.load

You have an option "overwrite" but this cant be used with set command. Why dont you use xml/text config

0
Stacy Smith On

If you manually enter your set statements into the CLI's configuration mode, you can then use the "show" command to see the equivalent configuration in text format or "show | display xml" to see the equivalent configuration in XML format.