简体   繁体   中英

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

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()

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

如果您手动将 set 语句输入 CLI 的配置模式,则可以使用“show”命令以文本格式查看等效配置或使用“show | display xml”以 XML 格式查看等效配置。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM