Automation

 View Only
last person joined: yesterday 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  Space API with xpath filters

    Posted 03-22-2024 12:12

    Hello everyone,

    i am trying to get every management ip (master-only) of our firewall clusters via the space api. If i call the configurations/expanded api it shows everything fine, but as soon as i use xpath filters for the interfaces, it returns every interface except the fxp0 interface.

    Is there a bug or do i need a different filter expression to filter for the fxp0 interface?

    Method: POST

    URL: https://<space_ip>/api/space/device-management/devices/<device_id>/configurations/expanded

    Header:

    Accept= application/vnd.net.juniper.space.device-management.expanded-xml-configuration+xml;version=5

    Content-Type= application/vnd.net.juniper.space.device-management.expanded-xml-configuration-request+xml;version=5;charset=UTF-8

    (example) XML-Body: 

    <expanded-xml-configuration-request>
    <xpath-list>
    <xpath>/configuration/interfaces/interface/*</xpath>
    </xpath-list>
    </expanded-xml-configuration-request>

    Idealy i would like to filter for only the "master-only" interface ip address, but for research purposes i filtered for all interfaces.

    thanks



    ------------------------------
    Nusret Buyukluoglu
    ------------------------------


  • 2.  RE: Space API with xpath filters

     
    Posted 03-24-2024 06:54
    Edited by asharp 03-24-2024 15:34

    Not sure which version of Space you are using, although this looks like it might work, or it does in my test environment using Space 23.1R1.4

    POST: /api/space/device-management/devices/<device-id>/configurations/expanded
    Content-Type: application/vnd.net.juniper.space.device-management.xpath+xml;version=1;charset=UTF-8
    Accept: application/vnd.net.juniper.space.device-management.expanded-configuration+xml;version=1
    
    Body:
     <xpaths>
       <xpath>/configuration/interfaces/interface/unit/family/inet/address/master-only/../name</xpath>
    </xpaths>

    This returns a response like:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <expanded-configuration>
    	<configuration>&lt;name junos:group="node0"&gt;192.168.0.212/24&lt;/name&gt;</configuration>
    	<method href="/api/space/device-management/devices/1/configurations/expanded/match-content"/>
    </expanded-configuration>

    Which is the master address of my SRX cluster.

    Since there are multiple methods of performing this task via the API, the following should match what you have been trying already.

    POST: https://192.168.0.201/api/space/device-management/devices/1/configurations/expanded
    Content-Type: application/vnd.net.juniper.space.device-management.expanded-xml-configuration-request+xml;version=5;charset=UTF-8
    Accept: application/vnd.net.juniper.space.device-management.expanded-xml-configuration+xml;version=5
    Body XML:
    <expanded-xml-configuration-request>
         <xpath-list>
               <xpath>/configuration/interfaces/interface/unit/family/inet/address/master-only/../name</xpath>
         </xpath-list>
    </expanded-xml-configuration-request>
    
    Reply from 1st node of cluster.
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <expanded-xml-configuration uri="/api/space/device-management/devices/1/configurations/expanded/1">
    	<id>1</id>
    	<configuration>
    		<![CDATA[<name junos:group="node0">192.168.0.212/24</name>]]>
    	</configuration>
    </expanded-xml-configuration>
    
    Reply from 2nd node of cluster(POST: https://192.168.0.201/api/space/device-management/devices/3/configurations/expanded)
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <expanded-xml-configuration uri="/api/space/device-management/devices/3/configurations/expanded/3">
    	<id>3</id>
    	<configuration>
    		<![CDATA[<name junos:group="node1">192.168.0.212/24</name>]]>
    	</configuration>
    </expanded-xml-configuration>
    

    Finally, lots of choice as to which XPATH expression you choose to use.  full path as shown above, or other variants, as you prefer or what works with the setup that you have etc.

    <expanded-xml-configuration-request>
         <xpath-list>
               <xpath>//master-only/../name</xpath>
         </xpath-list>
    </expanded-xml-configuration-request>
    
    <expanded-xml-configuration-request>
         <xpath-list>
               <xpath>//interface[starts-with(name,"fxp")]/unit/family/inet/address/master-only/../name</xpath>
         </xpath-list>
    </expanded-xml-configuration-request>
    
    <expanded-xml-configuration-request>
         <xpath-list>
               <xpath>/configuration/interfaces/interface/unit/family/inet/address[master-only]/name</xpath>
         </xpath-list>
    </expanded-xml-configuration-request>

    Regards,

    ------------------------------
    Andy Sharp
    ------------------------------