Reworked state data generation architecture, bug fixes, typing improvements, ...

parent a2676e5d
module ietf-yang-library {
namespace "urn:ietf:params:xml:ns:yang:ietf-yang-library";
prefix "yanglib";
import ietf-yang-types { prefix yang; }
import ietf-inet-types { prefix inet; }
organization
"IETF NETCONF (Network Configuration) Working Group";
contact
"WG Web: <http://tools.ietf.org/wg/netconf/>
WG List: <mailto:netconf@ietf.org>
WG Chair: Mehmet Ersue
<mailto:mehmet.ersue@nsn.com>
WG Chair: Mahesh Jethanandani
<mailto:mjethanandani@gmail.com>
Editor: Andy Bierman
<mailto:andy@yumaworks.com>
Editor: Martin Bjorklund
<mailto:mbj@tail-f.com>
Editor: Kent Watsen
<mailto:kwatsen@juniper.net>";
description
"This module contains monitoring information about the YANG
modules and submodules that are used within a YANG-based
server.
Copyright (c) 2015 IETF Trust and the persons identified as
authors of the code. All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, is permitted pursuant to, and subject
to the license terms contained in, the Simplified BSD License
set forth in Section 4.c of the IETF Trust's Legal Provisions
Relating to IETF Documents
(http://trustee.ietf.org/license-info).
This version of this YANG module is part of RFC XXXX; see
the RFC itself for full legal notices.";
// RFC Ed.: replace XXXX with actual RFC number and remove this
// note.
// RFC Ed.: remove this note
// Note: extracted from draft-ietf-netconf-yang-library-00.txt
// RFC Ed.: update the date below with the date of RFC publication
// and remove this note.
revision 2015-01-30 {
description
"Initial revision.";
reference
"RFC XXXX: YANG Module Library.";
}
typedef revision-identifier {
type string {
pattern '\d{4}-\d{2}-\d{2}';
}
description
"Represents a specific date in YYYY-MM-DD format.
TBD: make pattern more precise to exclude leading zeros.";
}
grouping module {
description
"The module data structure is represented as a grouping
so it can be reused in configuration or another monitoring
data structure.";
grouping common-leafs {
description
"Common parameters for YANG modules and submodules.";
leaf name {
type yang:yang-identifier;
description "The YANG module or submodule name.";
}
leaf revision {
type union {
type revision-identifier;
type string { length 0; }
}
description
"The YANG module or submodule revision date.
An empty string is used if no revision statement
is present in the YANG module or submodule.";
}
leaf schema {
type inet:uri;
description
"Contains a URL that represents the YANG schema
resource for this module or submodule.
This leaf will only be present if there is a URL
available for retrieval of the schema for this entry.";
}
}
list module {
key "name revision";
description
"Each entry represents one module currently
supported by the server.";
uses common-leafs;
leaf namespace {
type inet:uri;
mandatory true;
description
"The XML namespace identifier for this module.";
}
leaf-list feature {
type yang:yang-identifier;
description
"List of YANG feature names from this module that are
supported by the server.";
}
leaf-list deviation {
type yang:yang-identifier;
description
"List of YANG deviation module names used by this
server to modify the conformance of the module
associated with this entry.";
}
leaf conformance {
type boolean;
mandatory true;
description
"If 'true', then the server is claiming conformance to
the YANG module identified in this entry.
If 'false', then the server is not claiming any
conformance for the YANG module identified by this
entry. The module may be needed for reusable definitions
such as extensions, features, identifies, typedefs,
or groupings.";
}
container submodules {
description
"Contains information about all the submodules used
by the parent module entry";
list submodule {
key "name revision";
description
"Each entry represents one submodule within the
parent module.";
uses common-leafs;
}
}
} // list module
} // grouping module
container modules {
config false;
description
"Contains YANG module monitoring information.";
leaf module-set-id {
type string;
description
"Contains a server-specific identifier representing
the current set of modules and submodules. The
server MUST change the value of this leaf if the
information represented by the 'module' list instances
has changed.";
}
uses module;
}
}
{
"ietf-yang-library:modules-state": {
"module-set-id": "-TO-BE-INVENTED-",
"module-set-id": "e595da11ace92c0d881995fa7e56bbe86f1f48e9",
"module": [
{
"name": "dns-parameters",
......@@ -51,7 +51,7 @@
},
{
"name": "ietf-yang-library",
"revision": "2016-02-01",
"revision": "2016-06-21",
"namespace": "urn:ietf:params:xml:ns:yang:ietf-yang-library",
"conformance-type": "implement"
},
......
......@@ -6,26 +6,27 @@ import sys
from colorlog import info, warning as warn, error
from importlib import import_module
from yangson.instance import InstancePath, NonexistentInstance, ObjectValue, EntryKeys
from . import usr_op_handlers, usr_state_data_handlers
from yangson.constants 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
from .nacm import NacmConfig
from .data import JsonDatastore, BaseDataListener, SchemaNode, PathFormat, ChangeType, DataChange, ConfHandlerResult
from .helpers import DataHelpers, ErrorHelpers
from .handler_list import OP_HANDLERS, STATE_DATA_HANDLES, CONF_DATA_HANDLES
from .knot_api import KNOT, KnotConfig, SOARecord, KnotError, ARecord
from .knot_api import knot_api_init, KnotConfig, SOARecord, KnotError, ARecord
epretty = ErrorHelpers.epretty
def knot_connect():
info("Connecting to KNOT socket")
KNOT.knot_connect()
knot_api.KNOT.knot_connect()
def knot_disconnect():
info("Disonnecting from KNOT socket")
KNOT.knot_disconnect()
knot_api.KNOT.knot_disconnect()
class KnotConfServerListener(BaseDataListener):
......@@ -36,11 +37,11 @@ class KnotConfServerListener(BaseDataListener):
base_ii = self._ds.parse_ii(base_ii_str, PathFormat.URL)
base_nv = self._ds.get_node(self._ds.get_data_root(), base_ii).value
KNOT.begin()
knot_api.KNOT.begin()
KNOT.set_item(section="server", item="comment", data=base_nv.get("description"))
KNOT.set_item(section="server", item="async-start", data=base_nv.get("knot-dns:async-start"))
KNOT.set_item(section="server", item="nsid", data=base_nv.get("nsid-identity", {}).get("nsid"))
knot_api.KNOT.set_item(section="server", item="comment", data=base_nv.get("description"))
knot_api.KNOT.set_item(section="server", item="async-start", data=base_nv.get("knot-dns:async-start"))
knot_api.KNOT.set_item(section="server", item="nsid", data=base_nv.get("nsid-identity", {}).get("nsid"))
listen_endpoints = base_nv.get("listen-endpoint") or []
......@@ -50,15 +51,15 @@ class KnotConfServerListener(BaseDataListener):
if ep.get("port"):
ep_str += "@" + str(ep["port"])
ep_str_list.append(ep_str)
KNOT.set_item_list(section="server", item="listen", data=ep_str_list)
knot_api.KNOT.set_item_list(section="server", item="listen", data=ep_str_list)
KNOT.set_item(section="server", item="rundir", data=base_nv.get("filesystem-paths", {}).get("run-time-dir"))
KNOT.set_item(section="server", item="pidfile", data=base_nv.get("filesystem-paths", {}).get("pid-file"))
KNOT.set_item(section="server", item="tcp-workers", data=base_nv.get("resources", {}).get("knot-dns:tcp-workers"))
KNOT.set_item(section="server", item="udp-workers", data=base_nv.get("resources", {}).get("knot-dns:udp-workers"))
KNOT.set_item(section="server", item="rate-limit-table-size", data=base_nv.get("response-rate-limiting", {}).get("table-size"))
knot_api.KNOT.set_item(section="server", item="rundir", data=base_nv.get("filesystem-paths", {}).get("run-time-dir"))
knot_api.KNOT.set_item(section="server", item="pidfile", data=base_nv.get("filesystem-paths", {}).get("pid-file"))
knot_api.KNOT.set_item(section="server", item="tcp-workers", data=base_nv.get("resources", {}).get("knot-dns:tcp-workers"))
knot_api.KNOT.set_item(section="server", item="udp-workers", data=base_nv.get("resources", {}).get("knot-dns:udp-workers"))
knot_api.KNOT.set_item(section="server", item="rate-limit-table-size", data=base_nv.get("response-rate-limiting", {}).get("table-size"))
KNOT.commit()
knot_api.KNOT.commit()
return ConfHandlerResult.OK
......@@ -69,21 +70,21 @@ class KnotConfLogListener(BaseDataListener):
base_ii = self._ds.parse_ii(base_ii_str, PathFormat.URL)
base_nv = self._ds.get_node(self._ds.get_data_root(), base_ii).value
KNOT.begin()
KNOT.set_item(section="log", data=None)
knot_api.KNOT.begin()
knot_api.KNOT.set_item(section="log", data=None)
for logitem in base_nv:
tgt = logitem.get("target")
if tgt is None:
continue
KNOT.set_item(section="log", item="target", data=tgt)
KNOT.set_item(section="log", identifier=tgt, item="comment", data=logitem.get("description"))
KNOT.set_item(section="log", identifier=tgt, item="server", data=logitem.get("server"))
KNOT.set_item(section="log", identifier=tgt, item="zone", data=logitem.get("zone"))
KNOT.set_item(section="log", identifier=tgt, item="any", data=logitem.get("any"))
knot_api.KNOT.set_item(section="log", item="target", data=tgt)
knot_api.KNOT.set_item(section="log", identifier=tgt, item="comment", data=logitem.get("description"))
knot_api.KNOT.set_item(section="log", identifier=tgt, item="server", data=logitem.get("server"))
knot_api.KNOT.set_item(section="log", identifier=tgt, item="zone", data=logitem.get("zone"))
knot_api.KNOT.set_item(section="log", identifier=tgt, item="any", data=logitem.get("any"))
KNOT.commit()
knot_api.KNOT.commit()
return ConfHandlerResult.OK
......@@ -100,41 +101,41 @@ class KnotConfZoneListener(BaseDataListener):
# zone_name = tuple(ii[len(base_ii)].keys.values())[0]
KNOT.begin()
knot_api.KNOT.begin()
domain = zone_nv.get("domain")
KNOT.set_item(section="zone", zone=domain, data=None)
KNOT.set_item(section="zone", item="domain", data=domain)
knot_api.KNOT.set_item(section="zone", zone=domain, data=None)
knot_api.KNOT.set_item(section="zone", item="domain", data=domain)
print("zn={}".format(domain))
KNOT.set_item(section="zone", zone=domain, item="comment", data=zone_nv.get("description"))
KNOT.set_item(section="zone", zone=domain, item="file", data=zone_nv.get("file"))
KNOT.set_item_list(section="zone", zone=domain, item="master", data=zone_nv.get("master"))
KNOT.set_item_list(section="zone", zone=domain, item="notify", data=zone_nv.get("notify", {}).get("recipient"))
KNOT.set_item_list(section="zone", zone=domain, item="acl", data=zone_nv.get("access-control-list"))
KNOT.set_item(section="zone", zone=domain, item="serial-policy", data=zone_nv.get("serial-update-method"))
knot_api.KNOT.set_item(section="zone", zone=domain, item="comment", data=zone_nv.get("description"))
knot_api.KNOT.set_item(section="zone", zone=domain, item="file", data=zone_nv.get("file"))
knot_api.KNOT.set_item_list(section="zone", zone=domain, item="master", data=zone_nv.get("master"))
knot_api.KNOT.set_item_list(section="zone", zone=domain, item="notify", data=zone_nv.get("notify", {}).get("recipient"))
knot_api.KNOT.set_item_list(section="zone", zone=domain, item="acl", data=zone_nv.get("access-control-list"))
knot_api.KNOT.set_item(section="zone", zone=domain, item="serial-policy", data=zone_nv.get("serial-update-method"))
anytotcp = zone_nv.get("any-to-tcp")
disable_any_str = str(not anytotcp) if isinstance(anytotcp, bool) else None
KNOT.set_item(section="zone", zone=domain, item="disable-any", data=disable_any_str)
knot_api.KNOT.set_item(section="zone", zone=domain, item="disable-any", data=disable_any_str)
KNOT.set_item(section="zone", zone=domain, item="max-journal-size", data=zone_nv.get("journal", {}).get("maximum-journal-size"))
KNOT.set_item(section="zone", zone=domain, item="zonefile-sync", data=zone_nv.get("journal", {}).get("zone-file-sync-delay"))
KNOT.set_item(section="zone", zone=domain, item="ixfr-from-differences", data=zone_nv.get("journal", {}).get("from-differences"))
knot_api.KNOT.set_item(section="zone", zone=domain, item="max-journal-size", data=zone_nv.get("journal", {}).get("maximum-journal-size"))
knot_api.KNOT.set_item(section="zone", zone=domain, item="zonefile-sync", data=zone_nv.get("journal", {}).get("zone-file-sync-delay"))
knot_api.KNOT.set_item(section="zone", zone=domain, item="ixfr-from-differences", data=zone_nv.get("journal", {}).get("from-differences"))
qms = zone_nv.get("query-module")
if qms is not None:
qm_str_list = list(map(lambda n: n["name"] + "/" + n["type"], qms))
else:
qm_str_list = None
KNOT.set_item_list(section="zone", zone=domain, item="module", data=qm_str_list)
knot_api.KNOT.set_item_list(section="zone", zone=domain, item="module", data=qm_str_list)
# dnssec-signing:dnssec-signing ?
KNOT.set_item(section="zone", zone=domain, item="semantic-checks", data=zone_nv.get("knot-dns:semantic-checks"))
knot_api.KNOT.set_item(section="zone", zone=domain, item="semantic-checks", data=zone_nv.get("knot-dns:semantic-checks"))
KNOT.commit()
knot_api.KNOT.commit()
return ConfHandlerResult.OK
......@@ -146,9 +147,9 @@ class KnotConfControlListener(BaseDataListener):
base_ii = self._ds.parse_ii(base_ii_str, PathFormat.URL)
base_nv = self._ds.get_node(self._ds.get_data_root(), base_ii).value
KNOT.begin()
KNOT.set_item(section="control", item="listen", data=base_nv.get("unix"))
KNOT.commit()
knot_api.KNOT.begin()
knot_api.KNOT.set_item(section="control", item="listen", data=base_nv.get("unix"))
knot_api.KNOT.commit()
return ConfHandlerResult.OK
......@@ -156,20 +157,20 @@ class KnotConfAclListener(BaseDataListener):
def _process_list_item(self, acl_nv: ObjectValue):
name = acl_nv.get("name")
print("name={}".format(name))
KNOT.set_item(section="acl", identifier=name, data=None)
KNOT.set_item(section="acl", item="id", data=name)
KNOT.set_item(section="acl", identifier=name, item="comment", data=acl_nv.get("description"))
KNOT.set_item_list(section="acl", identifier=name, item="key", data=acl_nv.get("key"))
KNOT.set_item_list(section="acl", identifier=name, item="action", data=acl_nv.get("operation"))
knot_api.KNOT.set_item(section="acl", identifier=name, data=None)
knot_api.KNOT.set_item(section="acl", item="id", data=name)
knot_api.KNOT.set_item(section="acl", identifier=name, item="comment", data=acl_nv.get("description"))
knot_api.KNOT.set_item_list(section="acl", identifier=name, item="key", data=acl_nv.get("key"))
knot_api.KNOT.set_item_list(section="acl", identifier=name, item="action", data=acl_nv.get("operation"))
netws = acl_nv.get("network")
if netws is not None:
addrs = list(map(lambda n: n["ip-prefix"], netws))
KNOT.set_item_list(section="acl", identifier=name, item="address", data=addrs)
knot_api.KNOT.set_item_list(section="acl", identifier=name, item="address", data=addrs)
action = acl_nv.get("action")
deny = "true" if action == "deny" else "false"
KNOT.set_item(section="acl", identifier=name, item="deny", data=deny)
knot_api.KNOT.set_item(section="acl", identifier=name, item="deny", data=deny)
def process(self, sn: SchemaNode, ii: InstancePath, ch: DataChange):
base_ii_str = self.schema_path
......@@ -177,8 +178,8 @@ class KnotConfAclListener(BaseDataListener):
base_ii = self._ds.parse_ii(base_ii_str, PathFormat.URL)
base_nv = self._ds.get_node(self._ds.get_data_root(), base_ii).value
KNOT.begin()
KNOT.set_item(section="acl", data=None)
knot_api.KNOT.begin()
knot_api.KNOT.set_item(section="acl", data=None)
if (len(ii) > len(base_ii)) and isinstance(ii[len(base_ii)], EntryKeys):
# Write only changed list item
......@@ -187,13 +188,13 @@ class KnotConfAclListener(BaseDataListener):
self._process_list_item(acl_nv)
else:
# Delete all list items from KNOT
KNOT.set_item(section="acl", data=None)
knot_api.KNOT.set_item(section="acl", data=None)
# Write whole list
for acl_nv in base_nv:
print("acl nv={}".format(acl_nv))
self._process_list_item(acl_nv)
KNOT.commit()
knot_api.KNOT.commit()
return ConfHandlerResult.OK
......@@ -207,15 +208,15 @@ class KnotZoneDataListener(BaseDataListener):
if (ii == base_ii) and (ch.change_type == ChangeType.CREATE):
name = ch.data["zone"]["name"]
print("--- Creating new zone \"{}\"".format(name))
KNOT.begin()
KNOT.set_item(section="zone", item="domain", data=name)
KNOT.commit()
knot_api.KNOT.begin()
knot_api.KNOT.set_item(section="zone", item="domain", data=name)
knot_api.KNOT.commit()
elif (len(ii) == (len(base_ii) + 2)) and isinstance(ii[len(base_ii) + 1], EntryKeys) and (ch.change_type == ChangeType.DELETE):
name = ii[len(base_ii) + 1].keys["name"]
print("--- Deleting zone \"{}\"".format(name))
KNOT.begin()
KNOT.zone_new(name)
KNOT.commit()
knot_api.KNOT.begin()
knot_api.KNOT.zone_new(name)
knot_api.KNOT.commit()
elif (len(ii) > len(base_ii)) and isinstance(ii[len(base_ii) + 1], EntryKeys):
zone_name = ii[len(base_ii) + 1].keys["name"]
print("--- Zone \"{}\" resource {}".format(zone_name, ch.change_type.name.lower()))
......@@ -224,7 +225,7 @@ class KnotZoneDataListener(BaseDataListener):
soa = ch.data.get("SOA")
if soa is not None:
print("writing soa {}".format(soa))
KNOT.begin_zone()
knot_api.KNOT.begin_zone()
soarr = SOARecord(zone_name)
soarr.mname = soa["mname"]
......@@ -235,23 +236,23 @@ class KnotZoneDataListener(BaseDataListener):
soarr.expire = soa["expire"]
soarr.minimum = soa["minimum"]
resp = KNOT.zone_add_record(zone_name, soarr)
resp = knot_api.KNOT.zone_add_record(zone_name, soarr)
print("resp_soa = {}".format(resp))
KNOT.commit_zone()
knot_api.KNOT.commit_zone()
rr = ch.data.get("rrset", {})
rtype = rr.get("type")
if rtype == "iana-dns-parameters:A":
KNOT.begin_zone()
knot_api.KNOT.begin_zone()
arr = ARecord(zone_name)
arr.owner = rr["owner"]
arr.address = rr["rdata"][0]["A"]["address"]
resp = KNOT.zone_add_record(zone_name, arr)
resp = knot_api.KNOT.zone_add_record(zone_name, arr)
print("resp_a = {}".format(resp))
KNOT.commit_zone()
knot_api.KNOT.commit_zone()
return ConfHandlerResult.OK
......@@ -267,11 +268,12 @@ def main():
# Datastore init
datastore = JsonDatastore(datamodel, "DNS data")
datastore.load("jetconf/example-data.json")
datastore.load_yl_data("data/yang-library-data.json")
nacmc = NacmConfig(datastore)
datastore.register_nacm(nacmc)
nacmc.set_ds(datastore)
datastore.get_data_root().validate()
datastore.get_data_root().validate(ContentType.config)
# Register schema listeners
CONF_DATA_HANDLES.register_handler(KnotConfServerListener(datastore, "/dns-server:dns-server/server-options"))
......@@ -279,7 +281,7 @@ def main():
CONF_DATA_HANDLES.register_handler(KnotConfZoneListener(datastore, "/dns-server:dns-server/zones/zone"))
CONF_DATA_HANDLES.register_handler(KnotConfControlListener(datastore, "/dns-server:dns-server/knot-dns:control-socket"))
CONF_DATA_HANDLES.register_handler(KnotConfAclListener(datastore, "/dns-server:dns-server/access-control-list"))
CONF_DATA_HANDLES.register_handler(KnotZoneDataListener(datastore, "/dns-zones:zones"))
CONF_DATA_HANDLES.register_handler(KnotZoneDataListener(datastore, "/dns-zones:zone-data"))
# Register op handlers
OP_HANDLERS.register_handler("generate-key", usr_op_handlers.sign_op_handler)
......@@ -288,8 +290,7 @@ def main():
usr_state_data_handlers.create_zone_state_handlers(STATE_DATA_HANDLES, datamodel)
# Initialize Knot control interface
global KNOT
KNOT = KnotConfig(CONFIG["KNOT"]["SOCKET"])
knot_api_init()
datastore.commit_begin_callback = knot_connect
datastore.commit_end_callback = knot_disconnect
......
......@@ -2,19 +2,22 @@ import json
from threading import Lock
from enum import Enum
from colorlog import error, warning as warn, info, debug
from typing import List, Any, Dict, TypeVar, Tuple, Set, Callable
from typing import List, Any, Dict, Callable
from yangson.schema import SchemaRoute, SchemaNode, NonexistentSchemaNode, ListNode, LeafListNode
from yangson.schema import SchemaNode, NonexistentSchemaNode, ListNode, LeafListNode
from yangson.datamodel import DataModel, InstancePath
from yangson.instance import \
InstanceNode, \
NonexistentInstance, \
InstanceTypeError, \
ArrayValue, \
ObjectValue, \
MemberName, \
EntryKeys, \
EntryIndex
from yangson.instance import (
InstanceNode,
NonexistentInstance,
InstanceTypeError,
ArrayValue,
ObjectValue,
MemberName,
EntryKeys,
EntryIndex,
InstanceIdParser,
ResourceIdParser
)
from .helpers import DataHelpers
......@@ -200,10 +203,11 @@ class BaseDatastore:
self.name = name
self.nacm = None # type: NacmConfig
self._data = None # type: InstanceNode
self._yang_lib_data = None # type: InstanceNode
self._dm = dm # type: DataModel
self._data_lock = Lock()
self._lock_username = None # type: str
self._usr_journals = {} # type: Dict[str, UsrChangeJournal]
self._usr_journals = {} # type: Dict[str, UsrChangeJournal]
self.commit_begin_callback = None # type: Callable
self.commit_end_callback = None # type: Callable
......@@ -238,9 +242,9 @@ class BaseDatastore:
# Parse Instance Identifier from string
def parse_ii(self, path: str, path_format: PathFormat) -> InstancePath:
if path_format == PathFormat.URL:
ii = self._dm.parse_resource_id(path)
ii = ResourceIdParser(path).parse()
else:
ii = self._dm.parse_instance_id(path)
ii = InstanceIdParser(path).parse()
return ii
......@@ -276,24 +280,33 @@ class BaseDatastore:
return n
# Get data node, evaluate NACM if required
def get_node_rpc(self, rpc: RpcInfo) -> InstanceNode:
def get_node_rpc(self, rpc: RpcInfo, yl_data=False) -> InstanceNode:
ii = self.parse_ii(rpc.path, rpc.path_format)
root = self._data
n = root.goto(ii)
sn = n.schema_node
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)
if sdh is not None:
root = sdh.update_node(ii, root).top()
self._data = root
else:
raise NoHandlerForStateDataError()
if yl_data:
root = self._yang_lib_data
else:
root = self._data
# n = root.goto(ii)
# sn = n.schema_node
sch_pth = str(InstancePath(filter(lambda n: isinstance(n, MemberName), ii)))
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)
if sdh is not None:
root_val = sdh.update_node(ii, root, True)
root = self._data.update_from_raw(root_val)
else:
raise NoHandlerForStateDataError()
self.commit_end_callback()
self._data = root
n = self._data.goto(ii)
n = root.goto(ii)
try:
with_defs = rpc.qs["with-defaults"][0]
......@@ -307,11 +320,11 @@ class BaseDatastore:
if self.nacm:
nrpc = self.nacm.get_user_nacm(rpc.username)
if nrpc.check_data_node_path(self._data, ii, Permission.NACM_ACCESS_READ) == Action.DENY:
if nrpc.check_data_node_path(root, ii, Permission.NACM_ACCESS_READ) == Action.DENY:
raise NacmForbiddenError()
else:
# Prun subtree data
n = nrpc.check_data_read_path(self._data, ii)
n = nrpc.check_data_read_path(root, ii)
try:
max_depth = int(rpc.qs["depth"][0])
......@@ -605,6 +618,11 @@ class JsonDatastore(BaseDatastore):
with open(filename, "rt") as fp:
self._data = self._dm.from_raw(json.load(fp))
def load_yl_data(self, filename: str):
self._yang_lib_data = None
with open(filename, "rt") as fp:
self._yang_lib_data = self._dm.from_raw(json.load(fp))
def save(self, filename: str):
with open(filename, "w") as jfd:
self.lock_data("json_save")
......
......@@ -257,90 +257,11 @@
]
}
},
"dns-server:dns-server-state": {
"server": {
"boot-time": "2015-05-21T08:02:14+02:00",
"config-time": "2015-06-25T16:22:07+02:00"
},
"zone": [
{
"domain": "example.com",
"class": "IN",
"serial": 2015060600,
"server-role": "slave",
"dnssec-signing:dnssec-signing": {
"key": [
{
"key-id": "d3a9fd3b36a6be275adea2b67c6e82b27ca30e90",
"key-tag": 30348,
"algorithm": "RSASHA256",
"size": 2048,
"flags": "zone-key secure-entry-point",
"created": "2015-06-18T18:02:45+02:00",
"publish": "2015-06-18T19:00:00+02:00",
"activate": "2015-06-20T10:00:00+02:00",
"retire": "2015-07-18T18:02:45+02:00",
"remove": "2015-07-25T00:00:00+02:00"
}
]
},
"statistics": {
"opcodes": {
"opcode-count": [
{
"opcode": "query",
"count": "1234"
},
{
"opcode": "iquery",
"count": "5678"
},
{
"opcode": "status",
"count": "9012"
},
{
"opcode": "notify",
"count": "3456"
}
]
},
"packets": {
"packet-count": [
{
"packet-type": "normal",
"count": "98765"
},
{
"packet-type": "axfr",
"count": "43210"
},
{
"packet-type": "ixfr",
"count"