Commit bf5ff439 authored by Pavel Spirek's avatar Pavel Spirek

Version bump

parent 5deb7174
PROJECT = jetconf PROJECT = jetconf
VERSION = 0.2.3 VERSION = 0.2.4
.PHONY = tags deps install-deps test .PHONY = tags deps install-deps test
tags: tags:
......
...@@ -325,54 +325,51 @@ class BaseDatastore: ...@@ -325,54 +325,51 @@ class BaseDatastore:
# Notify data observers about change in datastore # Notify data observers about change in datastore
def run_conf_edit_handler(self, ii: InstanceRoute, ch: DataChange): def run_conf_edit_handler(self, ii: InstanceRoute, ch: DataChange):
try: sch_pth_list = list(filter(lambda n: isinstance(n, MemberName), ii))
sch_pth_list = list(filter(lambda n: isinstance(n, MemberName), ii))
if ch.change_type == ChangeType.CREATE:
if ch.change_type == ChangeType.CREATE: # Get target member name
# Get target member name input_member_name_fq = tuple(ch.input_data.keys())[0]
input_member_name_fq = tuple(ch.input_data.keys())[0] input_member_name_ns, input_member_name = input_member_name_fq.split(":", maxsplit=1)
input_member_name_ns, input_member_name = input_member_name_fq.split(":", maxsplit=1) # Append it to ii
# Append it to ii sch_pth_list.append(MemberName(input_member_name, None))
sch_pth_list.append(MemberName(input_member_name, None))
sch_pth = DataHelpers.ii2str(sch_pth_list)
sch_pth = DataHelpers.ii2str(sch_pth_list) sn = self.get_schema_node(sch_pth)
sn = self.get_schema_node(sch_pth)
if sn is None:
if sn is None: return
return
h = CONF_DATA_HANDLES.get_handler(str(id(sn)))
h = CONF_DATA_HANDLES.get_handler(str(id(sn))) if h is not None:
if h is not None: info("handler for actual data node triggered")
info("handler for actual data node triggered") if isinstance(h, ConfDataObjectHandler):
if isinstance(h, ConfDataObjectHandler): if ch.change_type == ChangeType.CREATE:
if ch.change_type == ChangeType.CREATE: h.create(ii, ch)
h.create(ii, ch) elif ch.change_type == ChangeType.REPLACE:
elif ch.change_type == ChangeType.REPLACE: h.replace(ii, ch)
h.replace(ii, ch) elif ch.change_type == ChangeType.DELETE:
elif ch.change_type == ChangeType.DELETE: h.delete(ii, ch)
h.delete(ii, ch) if isinstance(h, ConfDataListHandler):
if isinstance(h, ConfDataListHandler): if ch.change_type == ChangeType.CREATE:
if ch.change_type == ChangeType.CREATE: h.create_item(ii, ch)
h.create_item(ii, ch) elif ch.change_type == ChangeType.REPLACE:
elif ch.change_type == ChangeType.REPLACE: h.replace_item(ii, ch)
h.replace_item(ii, ch) elif ch.change_type == ChangeType.DELETE:
elif ch.change_type == ChangeType.DELETE: h.delete_item(ii, ch)
h.delete_item(ii, ch) else:
else: sn = sn.parent
while sn is not None:
h = CONF_DATA_HANDLES.get_handler(str(id(sn)))
if h is not None and isinstance(h, ConfDataObjectHandler):
info("handler for superior data node triggered, replace")
# print(h.schema_path)
# print(h.__class__.__name__)
h.replace(ii, ch)
if h is not None and isinstance(h, ConfDataListHandler):
info("handler for superior data node triggered, replace_item")
h.replace_item(ii, ch)
sn = sn.parent sn = sn.parent
while sn is not None:
h = CONF_DATA_HANDLES.get_handler(str(id(sn)))
if h is not None and isinstance(h, ConfDataObjectHandler):
info("handler for superior data node triggered, replace")
# print(h.schema_path)
# print(h.__class__.__name__)
h.replace(ii, ch)
if h is not None and isinstance(h, ConfDataListHandler):
info("handler for superior data node triggered, replace_item")
h.replace_item(ii, ch)
sn = sn.parent
except NonexistentInstance:
warn("Cannnot notify {}, parent container removed".format(ii))
# Get data node, evaluate NACM if required # Get data node, evaluate NACM if required
def get_node_rpc(self, rpc: RpcInfo, staging=False) -> InstanceNode: def get_node_rpc(self, rpc: RpcInfo, staging=False) -> InstanceNode:
......
import json
from yangson.datamodel import DataModel from yangson.datamodel import DataModel
from yangson.instance import InstanceRoute
module_dir = "../yang-data/" MODULE_DIR = "yang-data"
yang_library_file = "../yang-data/yang-library-data.json" YANG_LIBRARY = "yang-library-data.json"
DATA_FILE = "data.json"
with open(yang_library_file) as ylfile: with open(YANG_LIBRARY) as ylfile:
yl = ylfile.read() yl = ylfile.read()
dm = DataModel(yl, [module_dir]) dm = DataModel(yl, [MODULE_DIR])
with open(DATA_FILE, "rt") as fp:
with open("data.json", "rt") as fp:
json_data = dm.from_raw(json.load(fp)) json_data = dm.from_raw(json.load(fp))
json_data.validate()
print("end")
handler_sn = dm.get_data_node("/dns-server:dns-server-state/zone")
handler_generated = [
{
'domain': 'example.com',
'class': 'IN',
'server-role': 'master',
'serial': 2010111201
}
]
cooked_val = handler_sn.from_raw(handler_generated)
ii_str_abs = "/dns-server:dns-server-state/zone=example.com/class"
ii_abs = dm.parse_resource_id(ii_str_abs)
print("Absolute II: {}".format(ii_abs))
ii_rel = InstanceRoute(ii_abs[2:])
print("Relative II (hardcoded for now): {}".format(ii_rel))
handler_n = handler_sn.orphan_instance(cooked_val)
n_desired = handler_n.goto(ii_rel)
# crashes here
print(n_desired.value)
n = handler_n[0]
print(n.value)
for i in n:
print(i)
print(type(i))
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