Junos Automation (Scripting)
Highlighted
Junos Automation (Scripting)

XPath basics

[ Edited ]
‎11-11-2018 07:22 AM

Hi

 

Need some assistance here please:

I am running an rpc against my qfx switch:

 

results = dev.rpc.get_evpn_database_information(mac_address='18:66:da:94:ab:23',normalize=True)

this is returning correctly.

when there is no entry the results is None.

But when there is an entry a etree.dump(results) gives me:

<evpn-database-information>
<evpn-database-instance style="normal">
<instance-name>default-switch</instance-name>
<mac-entry style="normal">
<vni-id>96</vni-id>
<mac-address>18:66:da:94:ab:23</mac-address>
<active-source>172.16.111.3</active-source>
<active-source-timestamp>Nov 02 13:37:51</active-source-timestamp>
</mac-entry>
</evpn-database-instance>
</evpn-database-information>

 yet when I try to access an element by using a results.find() or results.findall() etc I always get back None??

 

example I have tried so far:

str1 = results.find("mac-entry")

str1 = results.find("evpn-database-information/evpn-database-instance/mac-entry")

 

I wish to access some elements of the response to use as input for further rpc calls.

 

I have used an external XPath checker website to check the syntax and all looks ok.

 

any comments please.

1 REPLY
Junos Automation (Scripting)
Solution
Accepted by topic author wjonline1975
‎11-11-2018 09:18 AM

Re: XPath basics

‎11-11-2018 09:00 AM

Hi

 

I think it should be results.find("evpn-database-instance/mac-entry") as the result is parked at <evpn-database-information> element. Let me know if it works.

 

Best Regards,
PK

Juniper Ambassador, Juniper Networks Certified Instructor,
JNCIE-SEC #98, JNCIE-ENT #393, JNCIE-SP #2253
Twitter: @JuniperTrain
GitHub: https://github.com/pklimai
[Juniper Authorized Education & Support in Russia]