Changed directory structure to bettery comply with Python packaging

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