Commit 74daed17 authored by Pavel Spirek's avatar Pavel Spirek

DS methods refactored to match new yangson api

parent e4f702ff
Pipeline #379 skipped
...@@ -47,7 +47,7 @@ def main(): ...@@ -47,7 +47,7 @@ def main():
OP_HANDLERS.register_handler("generate-key", usr_op_handlers.sign_op_handler) OP_HANDLERS.register_handler("generate-key", usr_op_handlers.sign_op_handler)
# Create and register state data handlers # Create and register state data handlers
usr_state_data_handlers.create_zone_state_handlers(STATE_DATA_HANDLES, datamodel) # usr_state_data_handlers.create_zone_state_handlers(STATE_DATA_HANDLES, datamodel)
# Create HTTP server # Create HTTP server
rest_srv = RestServer() rest_srv = RestServer()
......
This diff is collapsed.
...@@ -197,8 +197,8 @@ def _post(prot: "H2Protocol", data: bytes, stream_id: int, ds: BaseDatastore, pt ...@@ -197,8 +197,8 @@ def _post(prot: "H2Protocol", data: bytes, stream_id: int, ds: BaseDatastore, pt
ds.lock_data(username) ds.lock_data(username)
ins_pos = (query_string.get("insert") or [None])[0] ins_pos = (query_string.get("insert") or [None])[0]
point = (query_string.get("point") or [None])[0] point = (query_string.get("point") or [None])[0]
# ds.create_node_rpc(rpc1, json_data, insert=ins_pos, point=point) ds.create_node_rpc(ds.get_data_root(), rpc1, json_data, insert=ins_pos, point=point)
ds.add_to_journal_rpc(ChangeType.CREATE, rpc1, json_data) #ds.add_to_journal_rpc(ChangeType.CREATE, rpc1, json_data)
prot.send_empty(stream_id, "201", "Created") prot.send_empty(stream_id, "201", "Created")
except DataLockError as e: except DataLockError as e:
warn(epretty(e)) warn(epretty(e))
...@@ -263,8 +263,9 @@ def _put(prot: "H2Protocol", data: bytes, stream_id: int, ds: BaseDatastore, pth ...@@ -263,8 +263,9 @@ def _put(prot: "H2Protocol", data: bytes, stream_id: int, ds: BaseDatastore, pth
try: try:
ds.lock_data(username) ds.lock_data(username)
# ds.update_node_rpc(rpc1, json_data) nr = ds.update_node_rpc(ds.get_data_root(), rpc1, json_data)
ds.add_to_journal_rpc(ChangeType.REPLACE, rpc1, json_data) ds._data = nr
#ds.add_to_journal_rpc(ChangeType.REPLACE, rpc1, json_data)
prot.send_empty(stream_id, "204", "No Content", False) prot.send_empty(stream_id, "204", "No Content", False)
except DataLockError as e: except DataLockError as e:
warn(epretty(e)) warn(epretty(e))
......
...@@ -7,7 +7,7 @@ from colorlog import error, warning as warn, info, debug ...@@ -7,7 +7,7 @@ from colorlog import error, warning as warn, info, debug
from typing import List, Set from typing import List, Set
from yangson.instance import \ from yangson.instance import \
Instance, \ InstanceNode, \
NonexistentInstance, \ NonexistentInstance, \
ArrayValue, \ ArrayValue, \
ObjectValue, \ ObjectValue, \
...@@ -321,7 +321,7 @@ class UserNacm: ...@@ -321,7 +321,7 @@ class UserNacm:
return Action.PERMIT return Action.PERMIT
retval = None retval = None
data_node = self.data.get_data_root() # type: Instance data_node = self.data.get_data_root() # type: InstanceNode
nl = self.rule_tree.root nl = self.rule_tree.root
for isel in ii: for isel in ii:
...@@ -361,7 +361,7 @@ class UserNacm: ...@@ -361,7 +361,7 @@ class UserNacm:
return retval return retval
def _check_data_read_path(self, node: Instance, ii: InstanceIdentifier) -> Instance: def _check_data_read_path(self, node: InstanceNode, ii: InstanceIdentifier) -> InstanceNode:
# node = self.data.get_node(ii) # node = self.data.get_node(ii)
if isinstance(node.value, ObjectValue): if isinstance(node.value, ObjectValue):
...@@ -401,7 +401,7 @@ class UserNacm: ...@@ -401,7 +401,7 @@ class UserNacm:
return node return node
def check_data_read_path(self, ii: InstanceIdentifier) -> Instance: def check_data_read_path(self, ii: InstanceIdentifier) -> InstanceNode:
n = self.data.get_node(ii) n = self.data.get_node(ii)
if not self.nacm_enabled: if not self.nacm_enabled:
return n return n
......
...@@ -2,7 +2,7 @@ from datetime import datetime ...@@ -2,7 +2,7 @@ from datetime import datetime
from typing import Dict, Any from typing import Dict, Any
from yangson.datamodel import DataModel from yangson.datamodel import DataModel
from yangson.instance import InstanceIdentifier, Instance from yangson.instance import InstanceIdentifier, InstanceNode
from .libknot.control import KnotCtl from .libknot.control import KnotCtl
...@@ -18,7 +18,7 @@ class StateNodeHandlerBase: ...@@ -18,7 +18,7 @@ class StateNodeHandlerBase:
def add_member_handler(self, member: str, handler: "StateNodeHandlerBase"): def add_member_handler(self, member: str, handler: "StateNodeHandlerBase"):
self.member_handlers[member] = handler self.member_handlers[member] = handler
def update_node(self, node_ii: InstanceIdentifier, data_root: Instance) -> Instance: def update_node(self, node_ii: InstanceIdentifier, data_root: InstanceNode) -> InstanceNode:
pass pass
...@@ -28,7 +28,7 @@ class ZoneSigningStateHandler(StateNodeHandlerBase): ...@@ -28,7 +28,7 @@ class ZoneSigningStateHandler(StateNodeHandlerBase):
self.sch_pth = "/dns-server:dns-server-state/zone/dnssec-signing:dnssec-signing" self.sch_pth = "/dns-server:dns-server-state/zone/dnssec-signing:dnssec-signing"
self.schema_node = data_model.get_data_node(self.sch_pth) self.schema_node = data_model.get_data_node(self.sch_pth)
def update_node(self, node_ii: InstanceIdentifier, data_root: Instance) -> Instance: def update_node(self, node_ii: InstanceIdentifier, data_root: InstanceNode) -> InstanceNode:
print("zone_state_signing_handler, ii = {}".format(node_ii)) print("zone_state_signing_handler, ii = {}".format(node_ii))
zone_name = node_ii[2].keys.get("domain") zone_name = node_ii[2].keys.get("domain")
...@@ -61,7 +61,7 @@ class ZoneStateHandler(StateNodeHandlerBase): ...@@ -61,7 +61,7 @@ class ZoneStateHandler(StateNodeHandlerBase):
self.sch_pth = "/dns-server:dns-server-state/zone" self.sch_pth = "/dns-server:dns-server-state/zone"
self.schema_node = data_model.get_data_node(self.sch_pth) self.schema_node = data_model.get_data_node(self.sch_pth)
def update_node(self, node_ii: InstanceIdentifier, data_root: Instance) -> Instance: def update_node(self, node_ii: InstanceIdentifier, data_root: InstanceNode) -> InstanceNode:
print("zone_state_handler, ii = {}".format(node_ii)) print("zone_state_handler, ii = {}".format(node_ii))
# Request status of specific zone # Request status of specific zone
......
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