Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jetconf
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
7
Issues
7
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
labs
jetconf
Commits
4075e1e8
Unverified
Commit
4075e1e8
authored
Dec 06, 2016
by
Pavel Spirek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor code structure changes
parent
9eaed9f0
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
58 additions
and
983 deletions
+58
-983
data/example-config.yaml
data/example-config.yaml
+25
-0
data/example-data.json.bak
data/example-data.json.bak
+0
-959
jetconf/__main__.py
jetconf/__main__.py
+27
-10
jetconf/config.py
jetconf/config.py
+2
-1
jetconf/data.py
jetconf/data.py
+3
-1
jetconf/knot_api.py
jetconf/knot_api.py
+0
-1
jetconf/nacm.py
jetconf/nacm.py
+0
-1
jetconf/usr_conf_data_handlers.py
jetconf/usr_conf_data_handlers.py
+0
-1
jetconf/usr_op_handlers.py
jetconf/usr_op_handlers.py
+1
-9
No files found.
data/config.yaml
→
data/
example-
config.yaml
View file @
4075e1e8
...
...
@@ -2,24 +2,24 @@ GLOBAL:
TIMEZONE
:
"
Europe/Prague"
LOGFILE
:
"
-"
PIDFILE
:
"
/tmp/jetconf.pid"
PERSISTENT_CHANGES
:
fals
e
LOG_LEVEL
:
"
debug
"
PERSISTENT_CHANGES
:
tru
e
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"
data/example-data.json.bak
deleted
100644 → 0
View file @
9eaed9f0
This diff is collapsed.
Click to expand it.
jetconf/__main__.py
View file @
4075e1e8
...
...
@@ -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
option
s 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
handl
ers
# Create and register state data
node listen
ers
usr_state_data_handlers
.
create_zone_state_handlers
(
STATE_DATA_HANDLES
,
datamodel
)
# Initialize Knot control interface
...
...
jetconf/config.py
View file @
4075e1e8
...
...
@@ -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
=
{
...
...
jetconf/data.py
View file @
4075e1e8
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:"
)
...
...
jetconf/knot_api.py
View file @
4075e1e8
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
...
...
jetconf/nacm.py
View file @
4075e1e8
...
...
@@ -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
...
...
jetconf/usr_conf_data_handlers.py
View file @
4075e1e8
from
colorlog
import
info
,
warning
as
warn
,
error
from
typing
import
List
,
Dict
,
Union
,
Any
from
yangson.instance
import
InstanceRoute
,
ObjectValue
,
EntryKeys
,
MemberName
...
...
jetconf/usr_op_handlers.py
View file @
4075e1e8
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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment