Automation

 View Only
last person joined: 6 days ago 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  How to Automatically Update Prefix Lists - Script fails

    Posted 07-16-2022 10:14
    Good Day,

    I've been trying to get this script from How to Automatically Update Prefix Lists
    Juniper remove preview
    How to Automatically Update Prefix Lists
    Throughout this book you have worked extensively with prefix lists. A prefix list contains one or more prefixes that can be used in routing policies. When you build your network, you usually start with manually-created and manually-updated prefix lists.
    View this on Juniper >
    , to run.

    However, I get this message:

    Connect to [10.10.1.1]...
    Open private configuration...
    Traceback (most recent call last):
    File "./plist.py", line 36, in <module>
    with Config(device, mode='private') as config:
    File "/usr/local/lib/python3.8/site-packages/jnpr/junos/utils/config.py", line 885, in __enter__
    {
    File "/usr/local/lib/python3.8/site-packages/jnpr/junos/utils/config.py", line 834, in _open_configuration_private
    raise err
    File "/usr/local/lib/python3.8/site-packages/jnpr/junos/utils/config.py", line 832, in _open_configuration_private
    self.rpc.open_configuration(private=True)
    File "/usr/local/lib/python3.8/site-packages/jnpr/junos/rpcmeta.py", line 364, in _exec_rpc
    return self._junos.execute(rpc, **dec_args)
    File "/usr/local/lib/python3.8/site-packages/jnpr/junos/decorators.py", line 76, in wrapper
    return function(*args, **kwargs)
    File "/usr/local/lib/python3.8/site-packages/jnpr/junos/decorators.py", line 31, in wrapper
    return function(*args, **kwargs)
    File "/usr/local/lib/python3.8/site-packages/jnpr/junos/device.py", line 818, in execute
    raise EzErrors.ConnectClosedError(self)
    jnpr.junos.exception.ConnectClosedError: ConnectClosedError(10.10.1.1)


    Any hint on what the issue is?

    Thanks.


    ------------------------------
    Dragan Jovicic
    ------------------------------


  • 2.  RE: How to Automatically Update Prefix Lists - Script fails

     
    Posted 07-18-2022 10:02
    Hello Dragan,

    The error message is not very helpful, but I think the issue begins here:

    File "/usr/local/lib/python3.8/site-packages/jnpr/junos/utils/config.py", line 834, in _open_configuration_private
    raise err

    The first thing I think of when I see this is that the script is unable to open a private configuration on the device, could you try to removing the private mode and see if you have success (or at least a new error?)

    with Config(device, mode='private') as config:
    to 

    with Config(device) as config:


    ---

    Here are some of the options available when opening an instance of the configuration object: PyEZ docs link to options

    ------------------------------
    Calvin Remsburg | Global Enterprise Architect | Juniper Networks
    ------------------------------



  • 3.  RE: How to Automatically Update Prefix Lists - Script fails

    Posted 07-18-2022 17:49
    Hello!

    I've spend good portion of today's free time to try and solve this.
    Anyway when I do as suggested and remove 'private' - it seems to continue up to the point where it needs to load the XML patch into config:

    $ ./plist.py
    Connect to [10.10.1.1]...
    Open private configuration...

    Update prefix list [AS65500] with [3] entries:
    ---
    <configuration>
    <policy-options>
    <prefix-list replace="replace">
    <name>AS65500</name>
    <prefix-list-item>
    <name>192.168.10.0/24</name>
    </prefix-list-item>
    <prefix-list-item>
    <name>192.168.11.0/24</name>
    </prefix-list-item>
    <prefix-list-item>
    <name>192.168.12.0/24</name>
    </prefix-list-item>
    </prefix-list>
    </policy-options>
    </configuration>
    ---
    Traceback (most recent call last):
    File "./plist.py", line 67, in <module>
    config.load(patch)
    File "/usr/local/lib/python3.8/site-packages/jnpr/junos/utils/config.py", line 589, in load
    return try_load(rpc_contents, rpc_xattrs, ignore_warning=ignore_warning)
    File "/usr/local/lib/python3.8/site-packages/jnpr/junos/utils/config.py", line 500, in try_load
    got = self.rpc.load_config(
    File "/usr/local/lib/python3.8/site-packages/jnpr/junos/rpcmeta.py", line 288, in load_config
    return self._junos.execute(rpc, ignore_warning=ignore_warning)
    File "/usr/local/lib/python3.8/site-packages/jnpr/junos/decorators.py", line 76, in wrapper
    return function(*args, **kwargs)
    File "/usr/local/lib/python3.8/site-packages/jnpr/junos/decorators.py", line 31, in wrapper
    return function(*args, **kwargs)
    File "/usr/local/lib/python3.8/site-packages/jnpr/junos/device.py", line 818, in execute
    raise EzErrors.ConnectClosedError(self)
    jnpr.junos.exception.ConnectClosedError: ConnectClosedError(10.10.1.1)

    So, the script read from prefix-list.d directory, looks into AS65500.txt file and then fetches 3 lines - basically the way it is explained within documentation (posted link in 1st post).

    As a side note - I tried a bit different configuration using 'set' rather than XML format, and it works - even when using private mode - which I'm not sure why is an issue to begin with. So this piece of script works:

    from jnpr.junos.utils.config import Config
    from jnpr.junos import Device
    ...
    print('Connect to [%s]...' % HOST)

    with Device(host=HOST, user=USER, passwd=PASS) as dev:
    with Config(dev, mode='private') as cu:
    set_command = []
    set_command.append("set policy-options policy-statement ps-auto term 1 then accept")
    set_command.append("set policy-options policy-statement ps-auto term default then reject")
    print (set_command)
    cu.load("\n".join(set_command), format='set')
    cu.pdiff()
    if cu.commit_check():
    if cu.commit():
    print ("Done")

    Thanks a lot.









    ------------------------------
    Dragan Jovicic
    ------------------------------