Automation

 View Only
last person joined: 15 hours ago 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  PyEZ (2.6.7) RPC get.config (format set) special characters handling

    Posted 05-22-2023 03:10

    Hello,

     I am doing some tests with Pyez (downloading the configuration file) and noted an issue.
    Maybe somebody was already dealing with it and can point me to a solution (o direction).

    I am using dev.rpc.get_config(options={'format':'set'}, normalize=True, encoding='unicode'), and in general all looks good, but …

    This part of the configuration (from the device)

    set groups INTF interfaces <xe-> unit <> family iso
    set groups INTF interfaces <xe-> unit <> family inet6
    set groups INTF interfaces <xe-> unit <> family mpls

    shows a bit strange after the RPC call is completed:

     set groups INTF interfaces &lt;xe-&gt; unit &lt;&gt;

    if I use format text - it's showing the same issue.
     if I use the format JSON it shows all clean
     

    {'name': 'INTF', 'interfaces': {'interface': [{'name': '<xe-*>', 'unit': [{'name': '<*>', 'family': {'iso': [None], 'inet6': [None], 'mpls': [None]}}]}]}}]

    Does anybody knows how this issue can be resolved for SET format, was wondering if I am missing some "options or parameters"

    Thank you in advance,
    Andrei



    ------------------------------
    Andrei Cebotareanu
    ------------------------------


  • 2.  RE: PyEZ (2.6.7) RPC get.config (format set) special characters handling

    Posted 05-22-2023 03:42

    Hi Andrei,

    The issue is with xml parsing while we pull the config from the device because < and > are part of xml structure they get changed to text, you would have to solve that programmatically in your code, but you will see that if you push the same config to device that will get pushed properly.

    Best regads,
    Adrian.



    ------------------------------
    Teodor Adrian Soroceanu
    ------------------------------



  • 3.  RE: PyEZ (2.6.7) RPC get.config (format set) special characters handling

    Posted 05-22-2023 03:47

    Thank you Adrian,

    you saved my day!!

    All the best



    ------------------------------
    Andrei Cebotareanu
    ------------------------------



  • 4.  RE: PyEZ (2.6.7) RPC get.config (format set) special characters handling

    Posted 05-22-2023 04:50

    @Teodor Adrian Soroceanu

    I was trying to "upload" the configuration file.
    I was using the "text format" in my case.

    The part of the config (that I consider an issue) under the text format is as follows:

    INTF {

    interfaces {

    &lt;xe-*&gt; {

    unit &lt;*&gt; {


    and the alarms/error I received is as follows:

    ´´´´´´´´´´´´´´´´´´´´
    ConfigLoadError(severity: error, bad_element: <configuration-text>, message: error: syntax error
    error: invalid interface type: &
    error: missing or invalid fpc number '*' in 'xe-*'
    error: invalid value
    error: invalid interface type: *



    The set format is showing same issues

    <error-severity>error</error-severity>
    <error-message>unknown command</error-message>
    <error-info>
    <bad-element>&lt;configuration-set&gt;</bad-element>
    </error-info>
    </rpc-error>
    <rpc-error>


    or 

    ConfigLoadError(severity: error, bad_element: <configuration-set>, message: error: unknown command
    error: invalid interface type: &
    error: invalid interface type: &
    error: invalid interface type: &
    error: unknown command)


    Any ideas/comments?


    Thank you in advance



    ------------------------------
    Andrei Cebotareanu
    ------------------------------



  • 5.  RE: PyEZ (2.6.7) RPC get.config (format set) special characters handling

    Posted 05-22-2023 05:08

    Hi Andrei,

    I think that you should always work with XML in this case, because going back from set to text to xml will lose this special characters.

    See if you can find your answer here: https://www.juniper.net/documentation/en_US/day-one-books/DO_PyEZ_Cookbook.pdf or here:  https://www.juniper.net/documentation/us/en/software/junos-pyez/junos-pyez-developer/topics/topic-map/junos-pyez-program-configuration-retrieving.html and https://www.juniper.net/documentation/us/en/software/junos-pyez/junos-pyez-developer/topics/example/junos-pyez-program-configuration-data-loading-from-file.html.

    Let me know if you don`t manage i will spin a lab also and take a look. Just to understand you want to save the active config and then restore at some later point in time, right?



    ------------------------------
    Teodor Adrian Soroceanu
    ------------------------------



  • 6.  RE: PyEZ (2.6.7) RPC get.config (format set) special characters handling

    Posted 05-22-2023 05:32

    @Teodor Adrian Soroceanu

    Thank you for the resources! 

    The "pure" xml works in my case... so I do have some "working solution". 

    Thank you for your help.

    BR



    ------------------------------
    Andrei Cebotareanu
    ------------------------------



  • 7.  RE: PyEZ (2.6.7) RPC get.config (format set) special characters handling

    Posted 05-23-2023 03:30

    @Teodor Adrian Soroceanu

    I was advised by @  to do the following
    ___________________
    Do you mean printing out the retrieved configuration with etree.tostring? If so, add method='text' as an argument and it should come out without the character encoding
    ___________________

    And this looks to be a solution for any format methode.

    JFYI.

    BR,

    method='text'


    ------------------------------
    Andrei Cebotareanu
    ------------------------------



  • 8.  RE: PyEZ (2.6.7) RPC get.config (format set) special characters handling

    Posted 05-23-2023 03:35

    Hi Andrei,

    I am glad you got the correct answer, i am also at the learing stage at the moment, but i know i faced the xml issue in some past troubleshooting, and that`s why i shared.

    Thanks,
    Adrian.



    ------------------------------
    Teodor Adrian Soroceanu
    ------------------------------



  • 9.  RE: PyEZ (2.6.7) RPC get.config (format set) special characters handling

    Posted 05-23-2023 03:39

    @Teodor Adrian Soroceanu Thank you so much! Your help is very appreciated!



    ------------------------------
    Andrei Cebotareanu
    ------------------------------