Skip to content

Commit 9bd139a

Browse files
committed
Merge branch 'develop'
2 parents a4f83d2 + 197d232 commit 9bd139a

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

src/cisco_gnmi/client.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,19 @@ def parse_xpath_to_gnmi_path(self, xpath, origin=None):
342342
return path
343343

344344
def combine_configs(self, payload, last_xpath, xpath, config):
345+
"""Walking from end to finish 2 xpaths merge so combine them
346+
347+
|---last xpath config
348+
----|
349+
|---this xpath config
350+
351+
Parameters
352+
----------
353+
payload: dict of partial payload
354+
last_xpath: last xpath that was processed
355+
xpath: colliding xpath
356+
config: dict of values associated to colliding xpath
357+
"""
345358
last_set = set(last_xpath.split('/'))
346359
curr_diff = set(xpath.split('/')) - last_set
347360
if len(curr_diff) > 1:
@@ -368,6 +381,18 @@ def combine_configs(self, payload, last_xpath, xpath, config):
368381
return payload
369382

370383
def xpath_to_json(self, configs, last_xpath='', payload={}):
384+
"""Try to combine Xpaths/values into a common payload (recursive).
385+
386+
Parameters
387+
----------
388+
configs: tuple of xpath/value dict
389+
last_xpath: str of last xpath that was recusivly processed.
390+
payload: dict being recursively built for JSON transformation.
391+
392+
Returns
393+
-------
394+
dict of combined xpath/value dict.
395+
"""
371396
for i, cfg in enumerate(configs, 1):
372397
xpath, config, is_key = cfg
373398
if last_xpath and xpath not in last_xpath:
@@ -408,6 +433,12 @@ def xpath_to_json(self, configs, last_xpath='', payload={}):
408433
RE_FIND_KEYS = re.compile(r'\[.*?\]')
409434

410435
def get_payload(self, configs):
436+
"""Common Xpaths were detected so try to consolidate them.
437+
438+
Parameter
439+
---------
440+
configs: tuple of xpath/value dicts
441+
"""
411442
# Number of updates are limited so try to consolidate into lists.
412443
xpaths_cfg = []
413444
first_key = set()

src/cisco_gnmi/nx.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,27 @@ class NXClient(Client):
5858
"""
5959

6060
def xpath_to_path_elem(self, request):
61+
"""Helper function for Nexus clients.
62+
63+
Parameters
64+
---------
65+
request: dict containing request namespace and nodes to be worked on.
66+
namespace: dict of <prefix>: <namespace>
67+
nodes: list of dict
68+
<xpath>: Xpath pointing to resource
69+
<value>: value to set resource to
70+
<edit-op>: equivelant NETCONF edit-config operation
71+
72+
Returns
73+
-------
74+
tuple: namespace_modules, message dict, origin
75+
namespace_modules: dict of <prefix>: <module name>
76+
Needed for future support.
77+
message dict: 4 lists containing possible updates, replaces,
78+
deletes, or gets derived form input nodes.
79+
origin str: DME, device, or openconfig
80+
"""
81+
6182
paths = []
6283
message = {
6384
'update': [],
@@ -187,6 +208,26 @@ def check_configs(self, configs):
187208
return configs
188209

189210
def create_updates(self, configs, origin, json_ietf=False):
211+
"""Check configs, and construct "Update" messages.
212+
213+
Parameters
214+
----------
215+
configs: dict of <xpath>: <dict val for JSON>
216+
origin: str [DME, device, openconfig]
217+
json_ietf: bool encoding type for Update val (default False)
218+
219+
Returns
220+
-------
221+
List of Update messages with val populated.
222+
223+
If a set of configs contain a common Xpath, the Update must contain
224+
a consolidation of xpath/values for 2 reasons:
225+
226+
1. Devices may have a restriction on how many Update messages it will
227+
accept at once.
228+
2. Some xpath/values are required to be set in same Update because of
229+
dependencies like leafrefs, mandatory settings, and if/when/musts.
230+
"""
190231
if not configs:
191232
return []
192233
configs = self.check_configs(configs)

src/cisco_gnmi/xe.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,26 @@ class XEClient(Client):
8080
"""
8181

8282
def xpath_to_path_elem(self, request):
83+
"""Helper function for Cisco XE clients.
84+
85+
Parameters
86+
---------
87+
request: dict containing request namespace and nodes to be worked on.
88+
namespace: dict of <prefix>: <namespace>
89+
nodes: list of dict
90+
<xpath>: Xpath pointing to resource
91+
<value>: value to set resource to
92+
<edit-op>: equivelant NETCONF edit-config operation
93+
94+
Returns
95+
-------
96+
tuple: namespace_modules, message dict, origin
97+
namespace_modules: dict of <prefix>: <module name>
98+
Needed for future support.
99+
message dict: 4 lists containing possible updates, replaces,
100+
deletes, or gets derived form input nodes.
101+
origin str: openconfig if detected (XE uses rfc7951 by default)
102+
"""
83103
paths = []
84104
message = {
85105
'update': [],
@@ -201,6 +221,26 @@ def check_configs(self, configs):
201221
return configs
202222

203223
def create_updates(self, configs, origin, json_ietf=True):
224+
"""Check configs, and construct "Update" messages.
225+
226+
Parameters
227+
----------
228+
configs: dict of <xpath>: <dict val for JSON>
229+
origin: None or 'openconfig'
230+
json_ietf: bool encoding type for Update val (default True)
231+
232+
Returns
233+
-------
234+
List of Update messages with val populated.
235+
236+
If a set of configs contain a common Xpath, the Update must contain
237+
a consolidation of xpath/values for 2 reasons:
238+
239+
1. Devices may have a restriction on how many Update messages it will
240+
accept at once.
241+
2. Some xpath/values are required to be set in same Update because of
242+
dependencies like leafrefs, mandatory settings, and if/when/musts.
243+
"""
204244
if not configs:
205245
return None
206246
configs = self.check_configs(configs)

0 commit comments

Comments
 (0)