
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2017 02:45 AM - edited 03-01-2019 03:50 AM
I need to read if the EFPP “negotiation” is set in the config. This configuration is either present or not present in the config… -> it does not contain an actual value.
Yang model looks like this:
Config:
In the service Reconciliation, I’m trying to read its value like this:
auto_negotiation_path = "/ncs:devices/device[name=’Pf-9k-01']/config/cisco-ios-xr:interface/GigabitEthernet[id='0/0/0/12']/negotiation/auto";
The function maapi.xpathEvalExpr is always returning empty, regardless of the present/absence of negotiation in the config. (I tried several variations like trying to read into a Boolean, different xpath’s, adding prefix,…)
Did anyone faced this issue before?
Solved! Go to Solution.
- Labels:
-
Other NSO Topics
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2017 02:47 AM
an XPath expression returns an XPath value, string, number, boolean or date. You just select a node with no content.
To illustrate I will use the ncs_cmd utility using the 'xe' command, short for XPath Expression:
» ncs_cmd -c "xe /devices/device[name='ios0']/config/ios:router/bgp/as-no"
64512
This returns the text representation of the node as-no, we can also write explicitly:
» ncs_cmd -c "xe /devices/device[name='ios0']/config/ios:router/bgp/as-no/text()"
64512
Selecting a node with no content will yield an empty result:
» ncs_cmd -c "xe /devices/device[name='ios0']/config/ios:router/bgp/bgp"
We are in fact selecting a node it just do not have any content, verify with the XPath function count()
» ncs_cmd -c "xe count(/devices/device[name='ios0']/config/ios:router/bgp/bgp)"
1
What you want is to test if something exists or not, an empty node-set is always false, a non-empty is always true.
You can testthat by using the XPath function boolean():
» ncs_cmd -c "xe boolean(/devices/device[name='ios0']/config/ios:router/bgp[as-no=64512])"
true
» ncs_cmd -c "xe boolean(/devices/device[name='ios0']/config/ios:router/bgp[as-no=64513])"
false
For more one XPath please consult:https://www.w3.org/TR/xpath/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2017 02:46 AM
Try to use this command:
show configuration devices device Pf-9k-01 config cisco-ios-xr:interface GigabitEthernet 0/0/0/12 | display xpath
You will get all the xpath possibilities.
It seems to me that you should get the value of “/ncs:devices/device[name=’Pf-9k-01']/config/cisco-ios-xr:interface/GigabitEthernet[id='0/0/0/12']/negotiation”.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2017 02:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2017 02:46 AM
The path seems to be correct:
admin@ncs> config Entering configuration mode private [ok][2016-04-19 12:58:07]
[edit] admin@ncs% set devices device XRv9K_CASLAB-01 config cisco-ios-xr:interface GigabitEthernet 0/0/0/6 negotiation auto [ok][2016-04-19 12:58:10]
[edit] admin@ncs% commit Commit complete. [ok][2016-04-19 12:58:19]
[edit] admin@ncs% exit [ok][2016-04-19 12:58:31] admin@ncs> show configuration devices device XRv9K_CASLAB-01 config cisco-ios-xr:interface GigabitEthernet 0/0/0/6 negotiation { auto; } [ok][2016-04-19 12:58:37] admin@ncs> show configuration devices device XRv9K_CASLAB-01 config cisco-ios-xr:interface GigabitEthernet 0/0/0/6 | display xpath /devices/device[name='XRv9K_CASLAB-01']/config/cisco-ios-xr:interface/GigabitEthernet[id='0/0/0/6']/negotiation/auto [ok][2016-04-19 12:58:43] |
The REST NBI seems to return different values for configured interfaces (Gi0/0/0/6) and not configured interfaces (Gi0/0/0/5):
Gi0/0/0/6: [ncsdev@ncs ~]$ curl -uadmin:admin -X GET -H "Accept: application/vnd.yang.data+json"http://localhost:8080/api/running/devices/device/XRv9K_CASLAB-01/config/cisco-ios-xr:interface/GigabitEthernet/0%2F0%2F0%2F6/negotiation { "tailf-ned-cisco-ios-xr:negotiation": { "auto": { } } } [ncsdev@ncs ~]$ curl -uadmin:admin -X GET -H "Accept: application/vnd.yang.data+json"http://localhost:8080/api/running/devices/device/XRv9K_CASLAB-01/config/cisco-ios-xr:interface/GigabitEthernet/0%2F0%2F0%2F6/negotiation/auto { "tailf-ned-cisco-ios-xr:auto": { } }
Gi0/0/0/5: [ncsdev@ncs ~]$ curl -uadmin:admin -X GET -H "Accept: application/vnd.yang.data+json"http://localhost:8080/api/running/devices/device/XRv9K_CASLAB-01/config/cisco-ios-xr:interface/GigabitEthernet/0%2F0%2F0%2F5/negotiation/auto |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2017 02:46 AM
If you want to retrieve something, you should be using the getElem method and not xpathEvalExpr, shouldn’t you?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2017 02:47 AM
an XPath expression returns an XPath value, string, number, boolean or date. You just select a node with no content.
To illustrate I will use the ncs_cmd utility using the 'xe' command, short for XPath Expression:
» ncs_cmd -c "xe /devices/device[name='ios0']/config/ios:router/bgp/as-no"
64512
This returns the text representation of the node as-no, we can also write explicitly:
» ncs_cmd -c "xe /devices/device[name='ios0']/config/ios:router/bgp/as-no/text()"
64512
Selecting a node with no content will yield an empty result:
» ncs_cmd -c "xe /devices/device[name='ios0']/config/ios:router/bgp/bgp"
We are in fact selecting a node it just do not have any content, verify with the XPath function count()
» ncs_cmd -c "xe count(/devices/device[name='ios0']/config/ios:router/bgp/bgp)"
1
What you want is to test if something exists or not, an empty node-set is always false, a non-empty is always true.
You can testthat by using the XPath function boolean():
» ncs_cmd -c "xe boolean(/devices/device[name='ios0']/config/ios:router/bgp[as-no=64512])"
true
» ncs_cmd -c "xe boolean(/devices/device[name='ios0']/config/ios:router/bgp[as-no=64513])"
false
For more one XPath please consult:https://www.w3.org/TR/xpath/
