Implemented acqusition of zone staging data

parent 68a99e3e
...@@ -367,11 +367,13 @@ class BaseDatastore: ...@@ -367,11 +367,13 @@ class BaseDatastore:
if yl_data: if yl_data:
root = self._yang_lib_data root = self._yang_lib_data
else: elif staging:
if staging: try:
root = self.get_data_root_staging(rpc.username) root = self.get_data_root_staging(rpc.username)
else: except NoHandlerError:
root = self._data root = self._data
else:
root = self._data
# Resolve schema node of the desired data node # Resolve schema node of the desired data node
sch_pth_list = filter(lambda isel: isinstance(isel, MemberName), ii) sch_pth_list = filter(lambda isel: isinstance(isel, MemberName), ii)
...@@ -381,7 +383,7 @@ class BaseDatastore: ...@@ -381,7 +383,7 @@ class BaseDatastore:
state_roots = sn.state_roots() state_roots = sn.state_roots()
if state_roots and not yl_data: if state_roots and not yl_data:
print("state roots: {}".format(state_roots)) debug_data("State roots: {}".format(state_roots))
for state_root_sch_pth in state_roots: for state_root_sch_pth in state_roots:
state_root_sn = self._dm.get_data_node(state_root_sch_pth) state_root_sn = self._dm.get_data_node(state_root_sch_pth)
...@@ -389,7 +391,7 @@ class BaseDatastore: ...@@ -389,7 +391,7 @@ class BaseDatastore:
sni = sn sni = sn
is_child = False is_child = False
while sni: while sni:
if sni == state_root_sn: if sni is state_root_sn:
is_child = True is_child = True
break break
sni = sni.parent sni = sni.parent
...@@ -399,11 +401,15 @@ class BaseDatastore: ...@@ -399,11 +401,15 @@ class BaseDatastore:
sdh = STATE_DATA_HANDLES.get_handler(state_root_sch_pth) sdh = STATE_DATA_HANDLES.get_handler(state_root_sch_pth)
if sdh is not None: if sdh is not None:
if isinstance(sdh, ContainerNodeHandlerBase): if isinstance(sdh, ContainerNodeHandlerBase):
state_handler_val = sdh.generate_node(ii, staging) state_handler_val = sdh.generate_node(ii, rpc.username, staging)
state_root_n = sdh.schema_node.orphan_instance(state_handler_val) state_root_n = sdh.schema_node.orphan_instance(state_handler_val)
elif isinstance(sdh, ListNodeHandlerBase): elif isinstance(sdh, ListNodeHandlerBase):
state_handler_val = sdh.generate_item(ii, staging) if (sn is sdh.schema_node) and isinstance(ii[-1], MemberName):
state_root_n = sdh.schema_node.orphan_entry(state_handler_val) state_handler_val = sdh.generate_list(ii, rpc.username, staging)
state_root_n = sdh.schema_node.orphan_instance(state_handler_val)
else:
state_handler_val = sdh.generate_item(ii, rpc.username, staging)
state_root_n = sdh.schema_node.orphan_entry(state_handler_val)
# Select desired subnode from handler-generated content # Select desired subnode from handler-generated content
ii_prefix, ii_rel = sdh.schema_node.split_instance_route(ii) ii_prefix, ii_rel = sdh.schema_node.split_instance_route(ii)
......
...@@ -8,6 +8,7 @@ from colorlog import error, warning as warn, info ...@@ -8,6 +8,7 @@ from colorlog import error, warning as warn, info
from urllib.parse import parse_qs from urllib.parse import parse_qs
from typing import Dict, List, Optional from typing import Dict, List, Optional
from yangson.exceptions import YangsonException
from yangson.schemanode import NonexistentSchemaNode, ContainerNode, ListNode, GroupNode, LeafListNode, LeafNode from yangson.schemanode import NonexistentSchemaNode, ContainerNode, ListNode, GroupNode, LeafListNode, LeafNode
from yangson.instance import NonexistentInstance, InstanceValueError, RootNode from yangson.instance import NonexistentInstance, InstanceValueError, RootNode
from yangson.datatype import YangTypeError from yangson.datatype import YangTypeError
...@@ -124,7 +125,7 @@ def _get(ds: BaseDatastore, pth: str, username: str, yl_data: bool=False, stagin ...@@ -124,7 +125,7 @@ def _get(ds: BaseDatastore, pth: str, username: str, yl_data: bool=False, stagin
except InstanceValueError as e: except InstanceValueError as e:
warn(epretty(e)) warn(epretty(e))
http_resp = HttpResponse.empty(HttpStatus.BadRequest) http_resp = HttpResponse.empty(HttpStatus.BadRequest)
except (ConfHandlerFailedError, NoHandlerError, KnotError) as e: except (ConfHandlerFailedError, NoHandlerError, KnotError, YangsonException) as e:
error(epretty(e)) error(epretty(e))
http_resp = HttpResponse.empty(HttpStatus.InternalServerError) http_resp = HttpResponse.empty(HttpStatus.InternalServerError)
finally: finally:
...@@ -214,7 +215,7 @@ def create_get_staging_api(ds: BaseDatastore): ...@@ -214,7 +215,7 @@ def create_get_staging_api(ds: BaseDatastore):
else: else:
http_resp = _get(ds.nacm.nacm_ds, username, api_pth, staging=True) http_resp = _get(ds.nacm.nacm_ds, username, api_pth, staging=True)
else: else:
http_resp = _get(ds, username, api_pth, staging=True) http_resp = _get(ds, api_pth, username, staging=True)
return http_resp return http_resp
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment