Automation

Expand all | Collapse all

How to replace the existing configuration via PYez ?

Jump to Best Answer
  • 1.  How to replace the existing configuration via PYez ?

    Posted 01-08-2020 16:09
      |   view attached

    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 !!



  • 2.  RE: How to replace the existing configuration via PYez ?

    Posted 01-08-2020 17:24

    Hi, 

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



  • 3.  RE: How to replace the existing configuration via PYez ?

    Posted 01-09-2020 05:33

    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 !!



  • 4.  RE: How to replace the existing configuration via PYez ?

    Posted 01-09-2020 06:28

    Pretty sure it's overwrite = true 🙂

    KR Adam



  • 5.  RE: How to replace the existing configuration via PYez ?
    Best Answer

    Posted 01-09-2020 07:26

    @AdamHartley wrote:

    Pretty sure it's overwrite = true 🙂

    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>


  • 6.  RE: How to replace the existing configuration via PYez ?

    Posted 01-09-2020 07:37

    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-configuration-data-loading.html

    KR
    Adam



  • 7.  RE: How to replace the existing configuration via PYez ?

    Posted 01-09-2020 08:46
    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



  • 8.  RE: How to replace the existing configuration via PYez ?

    Posted 01-10-2020 03:31

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



  • 9.  RE: How to replace the existing configuration via PYez ?

    Posted 01-09-2020 08:50

    thanks so much.

    It works a a magic.


    @tonusoo wrote:

    @AdamHartley wrote:

    Pretty sure it's overwrite = true 🙂

    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>