Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot filter based on key in XR #89

Open
jc-rode opened this issue Nov 6, 2020 · 0 comments
Open

Cannot filter based on key in XR #89

jc-rode opened this issue Nov 6, 2020 · 0 comments
Labels
informational os/xr IOS XR wontfix This will not be worked on

Comments

@jc-rode
Copy link

jc-rode commented Nov 6, 2020

When trying to filter in some xpath for a "get" in IOS-XR... for instance:

'Cisco-IOS-XR-infra-statsd-oper:infra-statistics/interfaces/interface[interface-name="MgmtEth0/RP0/CPU0/0"]/generic-counters'

This will create a grpc path:

elem {
  name: "infra-statistics"
}
elem {
  name: "interfaces"
}
elem {
  name: "interface"
  key {
    key: "interface-name"
    value: "MgmtEth0/RP0/CPU0/0"
  }
}
elem {
  name: "generic-counters"
}

But this will fail due to CSCvk26949 as IOS-XR expects key values to be inserted in double quotes like this:

elem {
  name: "infra-statistics"
}
elem {
  name: "interfaces"
}
elem {
  name: "interface"
  key {
    key: "interface-name"
    value: "\"MgmtEth0/RP0/CPU0/0\""
  }
}
elem {
  name: "generic-counters"
}

The returned error message will mention something like 'lexical error: invalid char in json text.'.

These diffs seem to make it work for me:

diff --git a/src/cisco_gnmi/xr.py b/src/cisco_gnmi/xr.py
index c55d6e4..50f4240 100644
--- a/src/cisco_gnmi/xr.py
+++ b/src/cisco_gnmi/xr.py
@@ -352,7 +352,13 @@ class XRClient(Client):
                 # module name
                 origin, xpath = xpath.split(":", 1)
                 origin = origin.strip("/")
-        return super(XRClient, cls).parse_xpath_to_gnmi_path(xpath, origin)
+        path = super(XRClient, cls).parse_xpath_to_gnmi_path(xpath, origin)
+        # Need to have double quotes around key value in IOS-XR (CSCvk26949)
+        for elem in path.elem:
+            if elem.key:
+                for key in list(elem.key.keys()):
+                    elem.key[key] = '"{}"'.format(elem.key[key])
+        return path

     @classmethod
     def parse_cli_to_gnmi_path(cls, command):
@miott miott added informational os/xr IOS XR wontfix This will not be worked on labels Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
informational os/xr IOS XR wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants