Junos Automation (Scripting)
Junos Automation (Scripting)

How to replace the existing configuration via PYez ?

‎01-08-2020 04:09 PM

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
Highlighted
Junos Automation (Scripting)

Re: How to replace the existing configuration via PYez ?

‎01-08-2020 05:24 PM

Hi, 

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

Junos Automation (Scripting)

Re: How to replace the existing configuration via PYez ?

‎01-09-2020 05:32 AM

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 ?

‎01-09-2020 06:28 AM

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
‎01-09-2020 08:49 AM

Re: How to replace the existing configuration via PYez ?

[ Edited ]
‎01-09-2020 07:25 AM

@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 ?

‎01-09-2020 07:36 AM

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 ?

‎01-09-2020 08:45 AM
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 ?

‎01-09-2020 08:50 AM

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 ]
‎01-10-2020 03:31 AM

@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.