Commit 4075e1e8 authored by Pavel Spirek's avatar Pavel Spirek

Minor code structure changes

parent 9eaed9f0
......@@ -2,24 +2,24 @@ GLOBAL:
TIMEZONE: "Europe/Prague"
LOGFILE: "-"
PIDFILE: "/tmp/jetconf.pid"
PERSISTENT_CHANGES: false
LOG_LEVEL: "debug"
PERSISTENT_CHANGES: true
LOG_LEVEL: "info"
LOG_DBG_MODULES: ["usr_conf_data_handlers", "knot_api", "nacm", "data"]
DATA_JSON_FILE: "/home/pspirek/dev-sw/jetconf/data/example-data.json"
DATA_JSON_FILE: "/home/user/jetconf/data/example-data.json"
HTTP_SERVER:
DOC_ROOT: "/home/pspirek/dev-sw/jetconf/data/doc-root"
DOC_ROOT: "/home/user/jetconf/data/doc-root"
DOC_DEFAULT_NAME: "index.html"
API_ROOT: "/restconf"
SERVER_NAME: "jetconf-h2"
SERVER_SSL_CERT: "/home/pspirek/dev-sw/jetconf/data/server.crt"
SERVER_SSL_PRIVKEY: "/home/pspirek/dev-sw/jetconf/data/server.key"
CA_CERT: "/home/pspirek/dev-sw/jetconf/data/ca.pem"
SERVER_SSL_CERT: "/home/user/jetconf/data/server.crt"
SERVER_SSL_PRIVKEY: "/home/user/jetconf/data/server.key"
CA_CERT: "/home/user/jetconf/data/ca.pem"
DBG_DISABLE_CERTS: false
NACM:
ALLOWED_USERS: ["lojza@mail.cz"]
KNOT:
SOCKET: "/home/pspirek/knot-conf/knot.sock"
SOCKET: "/home/user/knot-conf/knot.sock"
This diff is collapsed.
......@@ -7,12 +7,16 @@ import signal
from colorlog import error, info
from yaml.parser import ParserError
from yangson.enumerations import ContentType, ValidationScope
from yangson.exception import YangsonException
from yangson.schema import SchemaError, SemanticError
from . import usr_op_handlers, usr_state_data_handlers
from .rest_server import RestServer
from .config import CONFIG_GLOBAL, load_config, print_config
from .data import JsonDatastore
from .helpers import DataHelpers
from .helpers import DataHelpers, ErrorHelpers
from .handler_list import OP_HANDLERS, STATE_DATA_HANDLES, CONF_DATA_HANDLES
from .knot_api import knot_global_init, knot_connect, knot_disconnect
from .usr_conf_data_handlers import (
......@@ -26,17 +30,17 @@ from .usr_conf_data_handlers import (
def main():
config_file = "jetconf/config.yaml"
config_file = "config.yaml"
# Parse command line arguments
try:
opts, args = getopt.getopt(sys.argv[1:], "c:")
except getopt.GetoptError:
print("Invalid argument detected. Possibles are: -c (config file)")
print("Invalid argument detected. Possible options are: -c (config file)")
sys.exit(1)
for opt, arg in opts:
if opt == '-c':
if opt == "-c":
config_file = arg
# Load configuration
......@@ -133,16 +137,29 @@ def main():
signal.signal(signal.SIGINT, sig_exit_handler)
# Load data model
datamodel = DataHelpers.load_data_model(CONFIG_GLOBAL["YANG_LIB_DIR"], CONFIG_GLOBAL["YANG_LIB_DIR"] + "yang-library-data.json")
datamodel = DataHelpers.load_data_model(
CONFIG_GLOBAL["YANG_LIB_DIR"],
CONFIG_GLOBAL["YANG_LIB_DIR"] + "yang-library-data.json"
)
# Datastore init
datastore = JsonDatastore(datamodel, CONFIG_GLOBAL["DATA_JSON_FILE"], "DNS data", with_nacm=False)
try:
datastore.load()
datastore.load_yl_data(CONFIG_GLOBAL["YANG_LIB_DIR"] + "yang-library-data.json")
except (FileNotFoundError, YangsonException) as e:
error("Could not load JSON datastore " + CONFIG_GLOBAL["DATA_JSON_FILE"])
error(ErrorHelpers.epretty(e))
sig_exit_handler(0, None)
try:
datastore.get_data_root().validate(ValidationScope.all, ContentType.config)
except (SchemaError, SemanticError) as e:
error("Validation of datastore failed")
error(ErrorHelpers.epretty(e))
sig_exit_handler(0, None)
# Register schema listeners
# Register configuration data node listeners
CONF_DATA_HANDLES.register_handler(KnotConfServerListener(datastore, "/dns-server:dns-server/server-options"))
CONF_DATA_HANDLES.register_handler(KnotConfLogListener(datastore, "/dns-server:dns-server/knot-dns:log"))
CONF_DATA_HANDLES.register_handler(KnotConfZoneListener(datastore, "/dns-server:dns-server/zones"))
......@@ -153,7 +170,7 @@ def main():
# Register op handlers
OP_HANDLERS.register_handler("generate-key", usr_op_handlers.sign_op_handler)
# Create and register state data handlers
# Create and register state data node listeners
usr_state_data_handlers.create_zone_state_handlers(STATE_DATA_HANDLES, datamodel)
# Initialize Knot control interface
......
......@@ -11,7 +11,8 @@ CONFIG_GLOBAL = {
"LOG_LEVEL": "info",
"LOG_DBG_MODULES": ["*"],
"YANG_LIB_DIR": "yang-data/",
"DATA_JSON_FILE": "data.json"
"DATA_JSON_FILE": "data.json",
"VALIDATE_TRANSACTIONS": True
}
CONFIG_HTTP = {
......
import json
from threading import Lock
from enum import Enum
from colorlog import error, warning as warn, info
......@@ -192,7 +193,8 @@ class UsrChangeJournal:
try:
# Validate syntax and semantics of new data
# nr.validate(ValidationScope.all, ContentType.config)
if CONFIG["GLOBAL"]["VALIDATE_TRANSACTIONS"] is True:
nr.validate(ValidationScope.all, ContentType.config)
new_data_valid = True
except (SchemaError, SemanticError) as e:
error("Data validation error:")
......
from enum import Enum
from typing import List, Union, Dict, Any, Optional
from threading import Lock
from colorlog import info
from .libknot.control import KnotCtl, KnotCtlType
from .config import CONFIG
......
......@@ -2,7 +2,6 @@ import collections
from io import StringIO
from threading import Lock
from enum import Enum
from colorlog import error, info
from typing import List, Set, Optional
......
from colorlog import info, warning as warn, error
from typing import List, Dict, Union, Any
from yangson.instance import InstanceRoute, ObjectValue, EntryKeys, MemberName
......
from typing import Dict, Any
JsonNodeT = Dict[str, Any]
def play_op_handler(input_args: JsonNodeT) -> JsonNodeT:
print("Playing song {} in playlist \"{}\"".format(input_args.get("song-number"), input_args.get("playlist")))
ret = {"status": "OK"}
return ret
from .helpers import JsonNodeT
def sign_op_handler(input_args: JsonNodeT) -> JsonNodeT:
......
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