Junos Automation (Scripting)
Junos Automation (Scripting)

How to replace the existing configuration via PYez ?

2 weeks ago

I have a community as follows:

set policy-options community ExpToUWIT-Primary members 64850:20150

I need to change 64850:20150 to 64850:20050 when I change the local preference from 200 to 90

I have the following xml

 

bgp-1.JPG

I loaded the config as follows:

dev.cu.load(bgp_conf, format="xml", replace = True)

 

After executing the script, I got the following:

set policy-options community ExpToUWIT-Primary members 64850:20150
set policy-options community ExpToUWIT-Primary members 64850:20050

I expected to see only the second one.

 

Any suggestions !!

Attachments

8 REPLIES 8
Junos Automation (Scripting)

Re: How to replace the existing configuration via PYez ?

2 weeks ago

Hi, 

try with dev.cu.load(bgp_conf, format="xml", merge=False)

Junos Automation (Scripting)

Re: How to replace the existing configuration via PYez ?

2 weeks ago

I did, but the same result. The original 64850:20150 was not changed, a new line was added.

 

set policy-options community ExpToUWIT-Primary members 64850:20150
set policy-options community ExpToUWIT-Primary members 64850:20050

 

thanks for taking a look !!

Junos Automation (Scripting)

Re: How to replace the existing configuration via PYez ?

2 weeks ago

Pretty sure it's overwrite = true Smiley Happy

KR Adam

~~~~~~~~~~~~~~~~~~~~~~~
- Please Kudos if you found my response helpful
- Please accept my response as a 'Accepted Solution' if it solved your query
Junos Automation (Scripting)
Solution
Accepted by topic author gongyayu
2 weeks ago

Re: How to replace the existing configuration via PYez ?

[ Edited ]
2 weeks ago

@AdamHartley wrote:

Pretty sure it's overwrite = true Smiley Happy

KR Adam


This will replace the entire candidate configuration with the loaded configuration.

 

gongyayu, try adding attribute node operation with value replace to your XML:

<policy-options>
    <community operation="replace">
        <name>ExpToUWIT-Primary</name>
        <members>{1}</members>
    </community>
</policy-options>
Junos Automation (Scripting)

Re: How to replace the existing configuration via PYez ?

2 weeks ago

Ah my bad, just looked it up and it's 'update=True'

'Compare the complete loaded configuration against the existing configuration. Each configuration element that is different in the loaded configuration replaces its corresponding element in the existing configuration. During the commit operation, only system processes that are affected by changed configuration elements parse the new configuration.'

https://www.juniper.net/documentation/en_US/junos-pyez/topics/task/program/junos-pyez-program-config...

KR
Adam

~~~~~~~~~~~~~~~~~~~~~~~
- Please Kudos if you found my response helpful
- Please accept my response as a 'Accepted Solution' if it solved your query
Junos Automation (Scripting)

Re: How to replace the existing configuration via PYez ?

2 weeks ago
root@NJB-AGG-HA-A1# run op bgpFailover.py

    Usage: Enter 90 to failover to UWT
           Enter 200 to failover back to NJB
Enter LocalPref: 200
<configuration>
            <policy-options>
                <policy-statement>
                    <name>setLocalPref200</name>
                        <then>
                            <local-preference>
                                <local-preference>200</local-preference>
                            </local-preference>
                        </then>
                </policy-statement>
            </policy-options>
            <policy-options>
                <community>
                    <name>ExpToUWIT-Primary</name>
                    <members>64850:20150</members>
                </community>
            </policy-options>
        </configuration>
Locking the configuration
Loading configuration changes
Committing the configuration
Error: Unable to commit configuration
Unlocking the configuration

can't commit after changed to be update = True

Junos Automation (Scripting)

Re: How to replace the existing configuration via PYez ?

2 weeks ago

thanks so much.

It works a a magic.


@tonusoo wrote:

@AdamHartley wrote:

Pretty sure it's overwrite = true Smiley Happy

KR Adam


This will replace the entire candidate configuration with the loaded configuration.

 

gongyayu, try adding attribute node operation with value replace to your XML:

<policy-options>
    <community operation="replace">
        <name>ExpToUWIT-Primary</name>
        <members>{1}</members>
    </community>
</policy-options>

 

Junos Automation (Scripting)

Re: How to replace the existing configuration via PYez ?

[ Edited ]
2 weeks ago

@AdamHartley wrote:

Ah my bad, just looked it up and it's 'update=True'


 

AdamHartleyupdate=True requires a complete configuration. Exactly like overwrite=True. The only differene between the two should be that former intelligently notifies daemons which configuration actually changed.

 

gongyayu, you weren't able to commit with update=True most likely because you were missing mandatory configuration statements like root-authentication.