Skip to content

Commit 5b25216

Browse files
committed
XE get sending correct path
1 parent da34c9d commit 5b25216

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/cisco_gnmi/nx.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ def xpath_to_path_elem(self, request):
9898
if pfx in xpath and 'openconfig' in ns:
9999
origin = 'openconfig'
100100
xpath = xpath.replace(pfx + ':', '')
101-
value = value.replace(pfx + ':', '')
101+
if isinstance(value, string_types):
102+
value = value.replace(pfx + ':', '')
102103
elif pfx in xpath and 'device' in ns:
103104
origin = 'device'
104105
xpath = xpath.replace(pfx + ':', '')
105-
value = value.replace(pfx + ':', '')
106+
if isinstance(value, string_types):
107+
value = value.replace(pfx + ':', '')
106108
if edit_op:
107109
if edit_op in ['create', 'merge', 'replace']:
108110
xpath_lst = xpath.split('/')

src/cisco_gnmi/xe.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
from six import string_types
3030
from .client import Client, proto, util
3131

32+
logger = logging.getLogger(__name__)
33+
3234

3335
class XEClient(Client):
3436
"""IOS XE-specific wrapper for gNMI functionality.
@@ -93,8 +95,6 @@ def xpath_to_path_elem(self, request):
9395
module = ''
9496
if '/Cisco-IOS-' in nspace:
9597
module = nspace[nspace.rfind('/') + 1:]
96-
elif '/cisco-nx' in nspace: # NXOS lowercases namespace
97-
module = 'Cisco-NX-OS-device'
9898
elif '/openconfig.net' in nspace:
9999
module = 'openconfig-'
100100
module += nspace[nspace.rfind('/') + 1:]
@@ -112,8 +112,11 @@ def xpath_to_path_elem(self, request):
112112
edit_op = node.get('edit-op', '')
113113

114114
for pfx, ns in namespace_modules.items():
115-
xpath = xpath.replace(pfx + ':', ns + ':')
116-
value = value.replace(pfx + ':', ns + ':')
115+
if pfx in xpath and 'openconfig' in ns:
116+
origin = 'openconfig'
117+
xpath = xpath.replace(pfx + ':', '')
118+
if isinstance(value, string_types):
119+
value = value.replace(pfx + ':', '')
117120
if edit_op:
118121
if edit_op in ['create', 'merge', 'replace']:
119122
xpath_lst = xpath.split('/')
@@ -144,7 +147,7 @@ def xpath_to_path_elem(self, request):
144147
message['delete'] = set(xpath)
145148
else:
146149
message['get'].append(xpath)
147-
return namespace_modules, message
150+
return namespace_modules, message, origin
148151

149152
def delete_xpaths(self, xpaths, prefix=None):
150153
"""A convenience wrapper for set() which constructs Paths from supplied xpaths
@@ -203,14 +206,14 @@ def set_json(self, update_json_configs=None, replace_json_configs=None, ietf=Tru
203206

204207
def check_configs(configs):
205208
if isinstance(configs, string_types):
206-
logging.debug("Handling as JSON string.")
209+
logger.debug("Handling as JSON string.")
207210
try:
208211
configs = json.loads(configs)
209212
except:
210213
raise Exception("{0}\n is invalid JSON!".format(configs))
211214
configs = [configs]
212215
elif isinstance(configs, dict):
213-
logging.debug("Handling already serialized JSON object.")
216+
logger.debug("Handling already serialized JSON object.")
214217
configs = [configs]
215218
elif not isinstance(configs, (list, set)):
216219
raise Exception(
@@ -249,7 +252,7 @@ def create_updates(configs):
249252
replaces = create_updates(replace_json_configs)
250253
return self.set(updates=updates, replaces=replaces)
251254

252-
def get_xpaths(self, xpaths, data_type="ALL", encoding="JSON_IETF"):
255+
def get_xpaths(self, xpaths, data_type="ALL", encoding="JSON_IETF", origin=None):
253256
"""A convenience wrapper for get() which forms proto.gnmi_pb2.Path from supplied xpaths.
254257
255258
Parameters
@@ -278,13 +281,16 @@ def get_xpaths(self, xpaths, data_type="ALL", encoding="JSON_IETF"):
278281
)
279282
gnmi_path = None
280283
if isinstance(xpaths, (list, set)):
281-
gnmi_path = map(self.parse_xpath_to_gnmi_path, set(xpaths))
284+
gnmi_path = []
285+
for xpath in set(xpaths):
286+
gnmi_path.append(self.parse_xpath_to_gnmi_path(xpath, origin))
282287
elif isinstance(xpaths, string_types):
283-
gnmi_path = [self.parse_xpath_to_gnmi_path(xpaths)]
288+
gnmi_path = [self.parse_xpath_to_gnmi_path(xpaths, origin)]
284289
else:
285290
raise Exception(
286291
"xpaths must be a single xpath string or iterable of xpath strings!"
287292
)
293+
logger.info('GNMI get:\n{0}\n{1}'.format(9 * '=', str(gnmi_path)))
288294
return self.get(gnmi_path, data_type=data_type, encoding=encoding)
289295

290296
def subscribe_xpaths(

0 commit comments

Comments
 (0)