Updated for new version of yangson

parent 1038e79c
......@@ -8,8 +8,8 @@ import signal
from colorlog import info, warning as warn, error
from importlib import import_module
from yangson.instance import InstancePath, NonexistentInstance, ObjectValue, EntryKeys
from yangson.constants import ContentType
from yangson.instance import InstanceRoute, NonexistentInstance, ObjectValue, EntryKeys
from yangson.enumerations import ContentType
from . import usr_op_handlers, usr_state_data_handlers, knot_api
from .rest_server import RestServer
from .config import CONFIG, load_config, print_config
......@@ -33,7 +33,7 @@ def knot_disconnect():
class KnotConfServerListener(BaseDataListener):
def process(self, sn: SchemaNode, ii: InstancePath, ch: DataChange):
def process(self, sn: SchemaNode, ii: InstanceRoute, ch: DataChange):
print("Change at sn \"{}\", dn \"{}\"".format(sn.name, ii))
base_ii_str = self.schema_path
......@@ -67,7 +67,7 @@ class KnotConfServerListener(BaseDataListener):
class KnotConfLogListener(BaseDataListener):
def process(self, sn: SchemaNode, ii: InstancePath, ch: DataChange):
def process(self, sn: SchemaNode, ii: InstanceRoute, ch: DataChange):
print("lChange at sn \"{}\", dn \"{}\"".format(sn.name, ii))
base_ii_str = self.schema_path
base_ii = self._ds.parse_ii(base_ii_str, PathFormat.URL)
......@@ -92,7 +92,7 @@ class KnotConfLogListener(BaseDataListener):
class KnotConfZoneListener(BaseDataListener):
def process(self, sn: SchemaNode, ii: InstancePath, ch: DataChange):
def process(self, sn: SchemaNode, ii: InstanceRoute, ch: DataChange):
print("zChange at sn \"{}\", dn \"{}\"".format(sn.name, ii))
base_ii_str = self.schema_path
base_ii = self._ds.parse_ii(base_ii_str, PathFormat.URL)
......@@ -143,7 +143,7 @@ class KnotConfZoneListener(BaseDataListener):
class KnotConfControlListener(BaseDataListener):
def process(self, sn: SchemaNode, ii: InstancePath, ch: DataChange):
def process(self, sn: SchemaNode, ii: InstanceRoute, ch: DataChange):
print("cChange at sn \"{}\", dn \"{}\"".format(sn.name, ii))
base_ii_str = self.schema_path
......@@ -175,7 +175,7 @@ class KnotConfAclListener(BaseDataListener):
deny = "true" if action == "deny" else "false"
knot_api.KNOT.set_item(section="acl", identifier=name, item="deny", data=deny)
def process(self, sn: SchemaNode, ii: InstancePath, ch: DataChange):
def process(self, sn: SchemaNode, ii: InstanceRoute, ch: DataChange):
base_ii_str = self.schema_path
print("aChange at sn \"{}\", dn \"{}\"".format(sn.name, ii))
base_ii = self._ds.parse_ii(base_ii_str, PathFormat.URL)
......@@ -202,7 +202,7 @@ class KnotConfAclListener(BaseDataListener):
class KnotZoneDataListener(BaseDataListener):
def process(self, sn: SchemaNode, ii: InstancePath, ch: DataChange):
def process(self, sn: SchemaNode, ii: InstanceRoute, ch: DataChange):
base_ii_str = self.schema_path
print("zdChange at sn \"{}\", dn \"{}\"".format(sn.name, ii))
base_ii = self._ds.parse_ii(base_ii_str, PathFormat.URL)
......
......@@ -5,7 +5,7 @@ from colorlog import error, warning as warn, info, debug
from typing import List, Any, Dict, Callable
from yangson.schema import SchemaNode, NonexistentSchemaNode, ListNode, LeafListNode
from yangson.datamodel import DataModel, InstancePath
from yangson.datamodel import DataModel
from yangson.instance import (
InstanceNode,
NonexistentInstance,
......@@ -16,7 +16,8 @@ from yangson.instance import (
EntryKeys,
EntryIndex,
InstanceIdParser,
ResourceIdParser
ResourceIdParser,
InstanceRoute
)
from .helpers import DataHelpers
......@@ -90,7 +91,7 @@ class BaseDataListener:
self.schema_path = sch_pth # type: str
self.schema_node = ds.get_schema_node(sch_pth) # type: SchemaNode
def process(self, sn: SchemaNode, ii: InstancePath, ch: "DataChange") -> ConfHandlerResult:
def process(self, sn: SchemaNode, ii: InstanceRoute, ch: "DataChange") -> ConfHandlerResult:
raise NotImplementedError("Not implemented in base class")
def __str__(self):
......@@ -219,6 +220,9 @@ class BaseDatastore:
def get_data_root(self) -> InstanceNode:
return self._data
def get_yl_data_root(self) -> InstanceNode:
return self._yang_lib_data
# Returns the root node of data tree
def get_data_root_staging(self, username: str) -> InstanceNode:
usr_journal = self._usr_journals.get(username)
......@@ -240,7 +244,7 @@ class BaseDatastore:
return sn
# Parse Instance Identifier from string
def parse_ii(self, path: str, path_format: PathFormat) -> InstancePath:
def parse_ii(self, path: str, path_format: PathFormat) -> InstanceRoute:
if path_format == PathFormat.URL:
ii = ResourceIdParser(path).parse()
else:
......@@ -249,11 +253,11 @@ class BaseDatastore:
return ii
# Notify data observers about change in datastore
def notify_edit(self, ii: InstancePath, ch: DataChange):
def notify_edit(self, ii: InstanceRoute, ch: DataChange):
try:
# n = self._data.goto(ii)
# sn = n.schema_node
sch_pth = str(InstancePath(filter(lambda n: isinstance(n, MemberName), ii)))
sch_pth = str(InstanceRoute(filter(lambda n: isinstance(n, MemberName), ii)))
sn = self.get_schema_node(sch_pth)
while sn is not None:
......@@ -275,7 +279,7 @@ class BaseDatastore:
warn("Cannnot notify {}, parent container removed".format(ii))
# Just get the node, do not evaluate NACM (needed for NACM)
def get_node(self, root: InstanceNode, ii: InstancePath) -> InstanceNode:
def get_node(self, root: InstanceNode, ii: InstanceRoute) -> InstanceNode:
n = root.goto(ii)
return n
......@@ -289,16 +293,15 @@ class BaseDatastore:
# n = root.goto(ii)
# sn = n.schema_node
sch_pth = str(InstancePath(filter(lambda n: isinstance(n, MemberName), ii)))
sch_pth_list = filter(lambda n: isinstance(n, MemberName), ii)
sch_pth = "".join([str(seg) for seg in sch_pth_list])
sn = self.get_schema_node(sch_pth)
if not yl_data:
if sn.state_roots():
self.commit_begin_callback()
for state_node_pth in sn.state_roots():
sn_pth_str = "".join(["/" + pth_seg for pth_seg in state_node_pth])
# print(sn_pth_str)
sdh = STATE_DATA_HANDLES.get_handler(sn_pth_str)
sdh = STATE_DATA_HANDLES.get_handler(state_node_pth)
if sdh is not None:
root_val = sdh.update_node(ii, root, True)
root = self._data.update_from_raw(root_val)
......
......@@ -13,7 +13,7 @@ from yangson.instance import \
ObjectValue, \
InstanceSelector, \
InstanceIdentifier, \
InstancePath, \
InstanceRoute, \
MemberName, \
EntryIndex, \
EntryKeys
......@@ -314,7 +314,7 @@ class UserNacm:
# config.update() always creates new structures instead of modifying ones
config.internal_data_lock.release()
def check_data_node_path(self, root: InstanceNode, ii: InstancePath, access: Permission, out_matching_rule: List[NacmRule]=None) -> Action:
def check_data_node_path(self, root: InstanceNode, ii: InstanceRoute, access: Permission, out_matching_rule: List[NacmRule]=None) -> Action:
if not self.nacm_enabled:
return Action.PERMIT
......@@ -359,7 +359,7 @@ class UserNacm:
return retval
def _check_data_read_path(self, node: InstanceNode, root: InstanceNode, ii: InstancePath) -> InstanceNode:
def _check_data_read_path(self, node: InstanceNode, root: InstanceNode, ii: InstanceRoute) -> InstanceNode:
# node = self.data.get_node(ii)
if isinstance(node.value, ObjectValue):
......@@ -399,7 +399,7 @@ class UserNacm:
return node
def check_data_read_path(self, root: InstanceNode, ii: InstancePath) -> InstanceNode:
def check_data_read_path(self, root: InstanceNode, ii: InstanceRoute) -> InstanceNode:
n = self.data.get_node(root, ii)
if not self.nacm_enabled:
return n
......
......@@ -143,5 +143,5 @@ def create_zone_state_handlers(handler_list: "StateDataHandlerList", dm: DataMod
handler_list.register_handler(zssh)
zsh = ZoneStateHandler(dm, knot_api.KNOT)
zsh.add_member_handler("dnssec-signing:dnssec-signing", zssh)
# zsh.add_member_handler("dnssec-signing:dnssec-signing", zssh)
handler_list.register_handler(zsh)
\ No newline at end of file
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