1) Handles chuncked xml requests from Netconf client, 2) Handles nested xml parameters from Netconf client, 3) Handles all currently exposed rpcs
Change-Id: Id478f355ab53afc876c4f5fd9ad8f1a048a50748
diff --git a/netconf/nc_rpc/ext/voltha_rpc.py b/netconf/nc_rpc/ext/voltha_rpc.py
index 835f900..9d4bf33 100644
--- a/netconf/nc_rpc/ext/voltha_rpc.py
+++ b/netconf/nc_rpc/ext/voltha_rpc.py
@@ -83,17 +83,29 @@
self.request_xml)
return
+ # Helper function to parse a complex xml into a dict
+ def _parse_params(self, node):
+ params = {}
+ if node is not None:
+ for r in node:
+ children = r.getchildren()
+ if children:
+ params[ r.tag.replace(qmap(C.VOLTHA), "")] = \
+ self._parse_params(children)
+ else:
+ params[
+ r.tag.replace(qmap(C.VOLTHA), "")] = r.text
+ return params
+
def _extract_parameters(self):
try:
rpc_node = self.request_xml.find(''.join(
[qmap(C.VOLTHA),
self.request['command']])
)
- self.request['params'] = {}
- if rpc_node is not None:
- for r in rpc_node:
- self.request['params'][
- r.tag.replace(qmap(C.VOLTHA), "")] = r.text
+
+ # Parse rpc the parameters
+ self.request['params'] = self._parse_params(rpc_node)
# Remove the subclass element in the request if it is present as
# it is not required for rpc calls
diff --git a/netconf/nc_rpc/rpc_response.py b/netconf/nc_rpc/rpc_response.py
index 19e01e2..aced3f9 100644
--- a/netconf/nc_rpc/rpc_response.py
+++ b/netconf/nc_rpc/rpc_response.py
@@ -131,11 +131,7 @@
if (attrib == 'list'):
if list(elem) is None:
return self.copy_basic_element(elem)
- # if elem.tag == 'items':
- # new_elem = etree.Element('items')
new_elem = etree.Element('ignore')
- # else:
- # new_elem = etree.Element('ignore')
for elm in list(elem):
elm.tag = elem.tag
if elm.get('type') in ['list', 'dict']:
@@ -171,25 +167,31 @@
elms = list(from_xml)
xml_tag = yang_options[0]
list_items_name = yang_options[1]
- # special case the xml contain a list type
+ # Handle the special case when the the xml contains 1 element which
+ # is a list type
if len(elms) == 1:
item = elms[0]
if item.get('type') == 'list':
- if list_items_name == 'items':
- # Create a new parent element
- new_elem = etree.Element(xml_tag)
- self.add_node(self.process_element(item), new_elem)
- top.append(new_elem)
- else:
- if xml_tag and custom_rpc:
+ if custom_rpc: # custom rpc request
+ if list_items_name == 'items': # no pre-processing required
+ self.add_node(self.process_element(item), top)
+ return top
+ if xml_tag:
item.tag = xml_tag
- elif request.has_key('subclass'):
+ else:
+ item.tag = 'ignore'
+ else:
+ # Default netconf operations - may end up needing
+ # specific parsing per request type
+ if request.has_key('subclass'):
item.tag = request['subclass']
# remove the subclass element in request to avoid duplicate tag
del request['subclass']
+ elif list_items_name == 'items':
+ item.tag = xml_tag
else:
item.tag = 'ignore'
- self.add_node(self.process_element(item), top)
+ self.add_node(self.process_element(item), top)
return top
# Process normally for all other cases