Changed directory structure to bettery comply with Python packaging

parent 35b13f10
This diff is collapsed.
......@@ -6,10 +6,11 @@ import sys
import signal
from colorlog import error, info
from yaml.parser import ParserError
from yangson.enumerations import ContentType, ValidationScope
from . import usr_op_handlers, usr_state_data_handlers
from .rest_server import RestServer
from .config import CONFIG, load_config, print_config
from .config import CONFIG_GLOBAL, load_config, print_config
from .data import JsonDatastore
from .helpers import DataHelpers
from .handler_list import OP_HANDLERS, STATE_DATA_HANDLES, CONF_DATA_HANDLES
......@@ -39,7 +40,14 @@ def main():
config_file = arg
# Load configuration
try:
load_config(config_file)
except FileNotFoundError:
print("Configuration file does not exist")
sys.exit(1)
except ParserError as e:
print("Configuration syntax error: " + str(e))
sys.exit(1)
# Set logging level
log_level = {
......@@ -47,16 +55,16 @@ def main():
"warning": logging.WARNING,
"info": logging.INFO,
"debug": logging.INFO
}.get(CONFIG["GLOBAL"]["LOG_LEVEL"], logging.INFO)
}.get(CONFIG_GLOBAL["LOG_LEVEL"], logging.INFO)
logging.root.handlers.clear()
# Daemonize
if CONFIG["GLOBAL"]["LOGFILE"] not in ("-", "stdout"):
if CONFIG_GLOBAL["LOGFILE"] not in ("-", "stdout"):
# Setup basic logging
logging.basicConfig(
format="%(asctime)s %(levelname)-8s %(message)s",
level=log_level,
filename=CONFIG["GLOBAL"]["LOGFILE"]
filename=CONFIG_GLOBAL["LOGFILE"]
)
# Go to background
......@@ -105,7 +113,7 @@ def main():
print_config()
# Create pidfile
fl = os.open(CONFIG["GLOBAL"]["PIDFILE"], os.O_WRONLY + os.O_CREAT, 0o666)
fl = os.open(CONFIG_GLOBAL["PIDFILE"], os.O_WRONLY + os.O_CREAT, 0o666)
try:
os.lockf(fl, os.F_TLOCK, 0)
os.write(fl, str(os.getpid()).encode())
......@@ -117,7 +125,7 @@ def main():
# Set signal handlers
def sig_exit_handler(signum, frame):
os.close(fl)
os.unlink(CONFIG["GLOBAL"]["PIDFILE"])
os.unlink(CONFIG_GLOBAL["PIDFILE"])
info("Exiting.")
sys.exit(0)
......@@ -125,7 +133,7 @@ def main():
signal.signal(signal.SIGINT, sig_exit_handler)
# Load data model
datamodel = DataHelpers.load_data_model("data/", "data/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, "jetconf/example-data.json", "DNS data", with_nacm=False)
......
import os
import yaml
from yaml.parser import ParserError
from colorlog import error, warning as warn, info
from colorlog import info
CONFIG_GLOBAL = {
"TIMEZONE": "GMT",
......@@ -10,7 +9,8 @@ CONFIG_GLOBAL = {
"PIDFILE": "/tmp/jetconf.pid",
"PERSISTENT_CHANGES": True,
"LOG_LEVEL": "info",
"LOG_DBG_MODULES": ["*"]
"LOG_DBG_MODULES": ["*"],
"YANG_LIB_DIR": "yang-data/"
}
CONFIG_HTTP = {
......@@ -50,13 +50,12 @@ API_ROOT_STAGING_data = os.path.join(CONFIG_HTTP["API_ROOT_STAGING"], "data")
API_ROOT_ops = os.path.join(CONFIG_HTTP["API_ROOT"], "operations")
def load_config(filename: str):
def load_config(filename: str) -> bool:
global NACM_ADMINS
global API_ROOT_data
global API_ROOT_STAGING_data
global API_ROOT_ops
try:
with open(filename) as conf_fd:
conf_yaml = yaml.load(conf_fd)
for conf_key in CONFIG.keys():
......@@ -65,12 +64,6 @@ def load_config(filename: str):
except KeyError:
pass
except FileNotFoundError:
warn("Configuration file does not exist")
except ParserError as e:
error("Configuration syntax error: " + str(e))
exit()
# Shortcuts
NACM_ADMINS = CONFIG["NACM"]["ALLOWED_USERS"]
API_ROOT_data = os.path.join(CONFIG_HTTP["API_ROOT"], "data")
......
"""Python libknot interface."""
from colorlog import error
from datetime import datetime
from typing import Dict, Any, List, Union
from yangson.datamodel import DataModel
from yangson.instance import InstanceRoute, InstanceNode, EntryKeys, NonexistentInstance
from jetconf.knot_api import KnotInternalError
from .libknot.control import KnotCtl
from . import knot_api
from .helpers import DataHelpers, JsonNodeT
from .handler_list import StateDataHandlerList
......@@ -22,11 +20,10 @@ class StateNonexistentInstance(NonexistentInstance):
class StateNodeHandlerBase:
def __init__(self, data_model: DataModel, ctl: KnotCtl):
def __init__(self, data_model: DataModel):
self.data_model = data_model
self.sch_pth = None
self.schema_node = None
self.knotctl = ctl
self.member_handlers = {} # type: Dict[str, StateNodeHandlerBase]
def add_member_handler(self, member: str, handler: "StateNodeHandlerBase"):
......@@ -40,8 +37,8 @@ class StateNodeHandlerBase:
class ZoneSigningStateHandler(StateNodeHandlerBase):
def __init__(self, data_model: DataModel, ctl: KnotCtl):
super().__init__(data_model, ctl)
def __init__(self, data_model: DataModel):
super().__init__(data_model)
self.sch_pth = "/dns-server:dns-server-state/zone/dnssec-signing:dnssec-signing"
self.schema_node = data_model.get_data_node(self.sch_pth)
......@@ -76,8 +73,8 @@ class ZoneSigningStateHandler(StateNodeHandlerBase):
class ZoneStateHandler(StateNodeHandlerBase):
def __init__(self, data_model: DataModel, ctl: KnotCtl):
super().__init__(data_model, ctl)
def __init__(self, data_model: DataModel):
super().__init__(data_model)
self.sch_pth = "/dns-server:dns-server-state/zone"
self.schema_node = data_model.get_data_node(self.sch_pth)
......@@ -142,9 +139,9 @@ class ZoneStateHandler(StateNodeHandlerBase):
# Create handler hierarchy
def create_zone_state_handlers(handler_list: "StateDataHandlerList", dm: DataModel):
zssh = ZoneSigningStateHandler(dm, knot_api.KNOT)
handler_list.register_handler(zssh)
# zssh = ZoneSigningStateHandler(dm)
# handler_list.register_handler(zssh)
zsh = ZoneStateHandler(dm, knot_api.KNOT)
zsh = ZoneStateHandler(dm)
# zsh.add_member_handler("dnssec-signing:dnssec-signing", zssh)
handler_list.register_handler(zsh)
\ No newline at end of file
from setuptools import setup
from setuptools import setup, find_packages
import codecs
import os
......@@ -8,7 +8,7 @@ with codecs.open(os.path.join(here, 'README.rst'), encoding='utf-8') as readme:
setup(
name = "jetconf",
packages = ["jetconf"],
packages = find_packages(),
use_scm_version = True,
setup_requires=["setuptools_scm"],
description = "Pure Python implementation of RESTCONF server",
......
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