Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jetconf
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
9
Issues
9
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
labs
jetconf
Commits
5f2d8efd
Commit
5f2d8efd
authored
Jun 26, 2017
by
Pavel Spirek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Transactions are started implicitly
parent
712f331a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
25 deletions
+47
-25
jetconf/config.py
jetconf/config.py
+4
-4
jetconf/data.py
jetconf/data.py
+5
-2
jetconf/http_handlers.py
jetconf/http_handlers.py
+27
-9
jetconf/op_internal.py
jetconf/op_internal.py
+8
-7
jetconf/rest_server.py
jetconf/rest_server.py
+3
-3
No files found.
jetconf/config.py
View file @
5f2d8efd
...
...
@@ -20,7 +20,7 @@ CONFIG_HTTP = {
"DOC_ROOT"
:
"doc-root"
,
"DOC_DEFAULT_NAME"
:
"index.html"
,
"API_ROOT"
:
"/restconf"
,
"API_ROOT_
STAGING"
:
"/restconf_stag
ing"
,
"API_ROOT_
RUNNING"
:
"/restconf_runn
ing"
,
"SERVER_NAME"
:
"jetconf-h2"
,
"UPLOAD_SIZE_LIMIT"
:
1
,
"LISTEN_LOCALHOST_ONLY"
:
False
,
...
...
@@ -49,14 +49,14 @@ CONFIG = {
}
API_ROOT_data
=
os
.
path
.
join
(
CONFIG_HTTP
[
"API_ROOT"
],
"data"
)
API_ROOT_
STAGING_data
=
os
.
path
.
join
(
CONFIG_HTTP
[
"API_ROOT_STAG
ING"
],
"data"
)
API_ROOT_
RUNNING_data
=
os
.
path
.
join
(
CONFIG_HTTP
[
"API_ROOT_RUNN
ING"
],
"data"
)
API_ROOT_ops
=
os
.
path
.
join
(
CONFIG_HTTP
[
"API_ROOT"
],
"operations"
)
API_ROOT_ylv
=
os
.
path
.
join
(
CONFIG_HTTP
[
"API_ROOT"
],
"yang-library-version"
)
def
load_config
(
filename
:
str
)
->
bool
:
global
API_ROOT_data
global
API_ROOT_
STAG
ING_data
global
API_ROOT_
RUNN
ING_data
global
API_ROOT_ops
global
API_ROOT_ylv
...
...
@@ -70,7 +70,7 @@ def load_config(filename: str) -> bool:
# Shortcuts
API_ROOT_data
=
os
.
path
.
join
(
CONFIG_HTTP
[
"API_ROOT"
],
"data"
)
API_ROOT_
STAGING_data
=
os
.
path
.
join
(
CONFIG_HTTP
[
"API_ROOT_STAG
ING"
],
"data"
)
API_ROOT_
RUNNING_data
=
os
.
path
.
join
(
CONFIG_HTTP
[
"API_ROOT_RUNN
ING"
],
"data"
)
API_ROOT_ops
=
os
.
path
.
join
(
CONFIG_HTTP
[
"API_ROOT"
],
"operations"
)
API_ROOT_ylv
=
os
.
path
.
join
(
CONFIG_HTTP
[
"API_ROOT"
],
"yang-library-version"
)
...
...
jetconf/data.py
View file @
5f2d8efd
...
...
@@ -146,7 +146,7 @@ class UsrChangeJournal:
if
len
(
self
.
_journal
)
==
0
:
return
False
if
hash
(
ds
.
get_data_root
())
==
hash
(
self
.
get_root_head
()
):
if
hash
(
ds
.
get_data_root
())
==
hash
(
self
.
_root_origin
):
info
(
"Commiting new configuration (swapping roots)"
)
# Set new root
nr
=
self
.
get_root_head
()
...
...
@@ -380,7 +380,10 @@ class BaseDatastore:
try
:
root
=
self
.
get_data_root_staging
(
rpc
.
username
)
except
StagingDataException
:
root
=
self
.
_data
# root = self._data
info
(
"Starting transaction for user
\"
{}
\"
"
.
format
(
rpc
.
username
))
self
.
make_user_journal
(
rpc
.
username
,
None
)
root
=
self
.
get_data_root_staging
(
rpc
.
username
)
else
:
root
=
self
.
_data
...
...
jetconf/http_handlers.py
View file @
5f2d8efd
...
...
@@ -13,7 +13,7 @@ from yangson.exceptions import YangsonException, NonexistentSchemaNode, SchemaEr
from
yangson.schemanode
import
ContainerNode
,
ListNode
,
GroupNode
,
LeafListNode
,
LeafNode
from
yangson.instance
import
NonexistentInstance
,
InstanceValueError
,
RootNode
from
.config
import
CONFIG_GLOBAL
,
CONFIG_HTTP
,
CONFIG_NACM
,
API_ROOT_data
,
API_ROOT_
STAG
ING_data
,
API_ROOT_ops
from
.config
import
CONFIG_GLOBAL
,
CONFIG_HTTP
,
CONFIG_NACM
,
API_ROOT_data
,
API_ROOT_
RUNN
ING_data
,
API_ROOT_ops
from
.helpers
import
CertHelpers
,
DateTimeHelpers
,
ErrorHelpers
,
LogHelpers
,
SSLCertT
from
.errors
import
BackendError
from
.nacm
import
NacmForbiddenError
...
...
@@ -312,19 +312,19 @@ def create_get_api(ds: BaseDatastore):
info
(
"[{}] api_get: {}"
.
format
(
username
,
headers
[
":path"
]))
api_pth
=
headers
[
":path"
][
len
(
API_ROOT_data
):]
http_resp
=
_get
(
ds
,
headers
,
api_pth
,
username
)
http_resp
=
_get
(
ds
,
headers
,
api_pth
,
username
,
staging
=
True
)
return
http_resp
return
get_api_closure
def
create_get_
stag
ing_api
(
ds
:
BaseDatastore
):
def
create_get_
runn
ing_api
(
ds
:
BaseDatastore
):
def
get_staging_api_closure
(
headers
:
OrderedDict
,
data
:
Optional
[
str
],
client_cert
:
SSLCertT
)
->
HttpResponse
:
username
=
CertHelpers
.
get_field
(
client_cert
,
"emailAddress"
)
info
(
"[{}] api_get_staging: {}"
.
format
(
username
,
headers
[
":path"
]))
api_pth
=
headers
[
":path"
][
len
(
API_ROOT_
STAG
ING_data
):]
http_resp
=
_get
(
ds
,
headers
,
api_pth
,
username
,
staging
=
Tru
e
)
api_pth
=
headers
[
":path"
][
len
(
API_ROOT_
RUNN
ING_data
):]
http_resp
=
_get
(
ds
,
headers
,
api_pth
,
username
,
staging
=
Fals
e
)
return
http_resp
return
get_staging_api_closure
...
...
@@ -390,7 +390,13 @@ def _post(ds: BaseDatastore, pth: str, username: str, data: str) -> HttpResponse
ds
.
lock_data
(
username
)
try
:
new_root
=
ds
.
create_node_rpc
(
ds
.
get_data_root_staging
(
rpc1
.
username
),
rpc1
,
json_data
)
try
:
staging_root
=
ds
.
get_data_root_staging
(
rpc1
.
username
)
except
StagingDataException
:
info
(
"Starting transaction for user
\"
{}
\"
"
.
format
(
rpc1
.
username
))
ds
.
make_user_journal
(
rpc1
.
username
,
None
)
staging_root
=
ds
.
get_data_root_staging
(
rpc1
.
username
)
new_root
=
ds
.
create_node_rpc
(
staging_root
,
rpc1
,
json_data
)
ds
.
add_to_journal_rpc
(
ChangeType
.
CREATE
,
rpc1
,
json_data
,
*
new_root
)
http_resp
=
HttpResponse
.
empty
(
HttpStatus
.
Created
)
except
NacmForbiddenError
as
e
:
...
...
@@ -414,7 +420,7 @@ def _post(ds: BaseDatastore, pth: str, username: str, data: str) -> HttpResponse
ERRTAG_OPNOTSUPPORTED
,
exception
=
e
)
except
(
InstanceValueError
,
StagingDataException
,
YangsonException
,
ValueError
)
as
e
:
except
(
InstanceValueError
,
YangsonException
,
ValueError
)
as
e
:
http_resp
=
HttpResponse
.
error
(
HttpStatus
.
BadRequest
,
RestconfErrType
.
Protocol
,
...
...
@@ -482,7 +488,13 @@ def _put(ds: BaseDatastore, pth: str, username: str, data: str) -> HttpResponse:
ds
.
lock_data
(
username
)
try
:
new_root
=
ds
.
update_node_rpc
(
ds
.
get_data_root_staging
(
rpc1
.
username
),
rpc1
,
json_data
)
try
:
staging_root
=
ds
.
get_data_root_staging
(
rpc1
.
username
)
except
StagingDataException
:
info
(
"Starting transaction for user
\"
{}
\"
"
.
format
(
rpc1
.
username
))
ds
.
make_user_journal
(
rpc1
.
username
,
None
)
staging_root
=
ds
.
get_data_root_staging
(
rpc1
.
username
)
new_root
=
ds
.
update_node_rpc
(
staging_root
,
rpc1
,
json_data
)
ds
.
add_to_journal_rpc
(
ChangeType
.
REPLACE
,
rpc1
,
json_data
,
*
new_root
)
http_resp
=
HttpResponse
.
empty
(
HttpStatus
.
NoContent
,
status_in_body
=
False
)
except
NacmForbiddenError
as
e
:
...
...
@@ -554,7 +566,13 @@ def _delete(ds: BaseDatastore, pth: str, username: str) -> HttpResponse:
ds
.
lock_data
(
username
)
try
:
new_root
=
ds
.
delete_node_rpc
(
ds
.
get_data_root_staging
(
rpc1
.
username
),
rpc1
)
try
:
staging_root
=
ds
.
get_data_root_staging
(
rpc1
.
username
)
except
StagingDataException
:
info
(
"Starting transaction for user
\"
{}
\"
"
.
format
(
rpc1
.
username
))
ds
.
make_user_journal
(
rpc1
.
username
,
None
)
staging_root
=
ds
.
get_data_root_staging
(
rpc1
.
username
)
new_root
=
ds
.
delete_node_rpc
(
staging_root
,
rpc1
)
ds
.
add_to_journal_rpc
(
ChangeType
.
DELETE
,
rpc1
,
None
,
*
new_root
)
http_resp
=
HttpResponse
.
empty
(
HttpStatus
.
NoContent
,
status_in_body
=
False
)
except
NacmForbiddenError
as
e
:
...
...
jetconf/op_internal.py
View file @
5f2d8efd
...
...
@@ -9,11 +9,12 @@ class OpHandlersContainer:
self
.
ds
=
ds
def
jetconf_conf_start
(
self
,
rpc
:
RpcInfo
)
->
JsonNodeT
:
try
:
transaction_opts
=
rpc
.
op_input_args
[
"options"
]
except
(
TypeError
,
KeyError
):
transaction_opts
=
None
self
.
ds
.
make_user_journal
(
rpc
.
username
,
transaction_opts
)
# try:
# transaction_opts = rpc.op_input_args["options"]
# except (TypeError, KeyError):
# transaction_opts = None
# self.ds.make_user_journal(rpc.username, transaction_opts)
self
.
ds
.
make_user_journal
(
rpc
.
username
,
None
)
ret_data
=
{
"status"
:
"OK"
}
return
ret_data
...
...
@@ -32,7 +33,7 @@ class OpHandlersContainer:
return
ret_data
def
jetconf_conf_
drop
(
self
,
rpc
:
RpcInfo
)
->
JsonNodeT
:
def
jetconf_conf_
reset
(
self
,
rpc
:
RpcInfo
)
->
JsonNodeT
:
self
.
ds
.
drop_user_journal
(
rpc
.
username
)
ret_data
=
{
"status"
:
"OK"
}
return
ret_data
...
...
@@ -91,7 +92,7 @@ def register_op_handlers(ds: BaseDatastore):
op_handlers_obj
=
OpHandlersContainer
(
ds
)
OP_HANDLERS
.
register
(
op_handlers_obj
.
jetconf_conf_start
,
"jetconf:conf-start"
)
OP_HANDLERS
.
register
(
op_handlers_obj
.
jetconf_conf_status
,
"jetconf:conf-status"
)
OP_HANDLERS
.
register
(
op_handlers_obj
.
jetconf_conf_
drop
,
"jetconf:conf-drop
"
)
OP_HANDLERS
.
register
(
op_handlers_obj
.
jetconf_conf_
reset
,
"jetconf:conf-reset
"
)
OP_HANDLERS
.
register
(
op_handlers_obj
.
jetconf_conf_commit
,
"jetconf:conf-commit"
)
OP_HANDLERS
.
register
(
op_handlers_obj
.
jetconf_get_schema_digest
,
"jetconf:get-schema-digest"
)
OP_HANDLERS
.
register
(
op_handlers_obj
.
jetconf_get_list_length
,
"jetconf:get-list-length"
)
jetconf/rest_server.py
View file @
5f2d8efd
...
...
@@ -13,7 +13,7 @@ from h2.events import DataReceived, RequestReceived, RemoteSettingsChanged, Stre
from
.
import
http_handlers
as
handlers
from
.http_handlers
import
HttpResponse
,
HttpStatus
,
RestconfErrType
,
ERRTAG_MALFORMED
,
ERRTAG_OPNOTSUPPORTED
,
ERRTAG_REQLARGE
from
.config
import
CONFIG_HTTP
,
API_ROOT_data
,
API_ROOT_
STAG
ING_data
,
API_ROOT_ops
,
API_ROOT_ylv
from
.config
import
CONFIG_HTTP
,
API_ROOT_data
,
API_ROOT_
RUNN
ING_data
,
API_ROOT_ops
,
API_ROOT_ylv
from
.data
import
BaseDatastore
from
.helpers
import
SSLCertT
,
LogHelpers
...
...
@@ -260,14 +260,14 @@ class RestServer:
api_get_root
=
handlers
.
api_root_handler
api_get_ylv
=
handlers
.
api_ylv_handler
api_get
=
handlers
.
create_get_api
(
datastore
)
api_get_
st
=
handlers
.
create_get_stag
ing_api
(
datastore
)
api_get_
run
=
handlers
.
create_get_runn
ing_api
(
datastore
)
api_post
=
handlers
.
create_post_api
(
datastore
)
api_put
=
handlers
.
create_put_api
(
datastore
)
api_delete
=
handlers
.
create_api_delete
(
datastore
)
api_op
=
handlers
.
create_api_op
(
datastore
)
self
.
http_handlers
.
register
(
lambda
m
,
p
:
(
m
==
"GET"
)
and
(
p
.
startswith
(
API_ROOT_data
)),
api_get
)
self
.
http_handlers
.
register
(
lambda
m
,
p
:
(
m
==
"GET"
)
and
(
p
.
startswith
(
API_ROOT_
STAGING_data
)),
api_get_st
)
self
.
http_handlers
.
register
(
lambda
m
,
p
:
(
m
==
"GET"
)
and
(
p
.
startswith
(
API_ROOT_
RUNNING_data
)),
api_get_run
)
self
.
http_handlers
.
register
(
lambda
m
,
p
:
(
m
==
"GET"
)
and
(
p
==
API_ROOT_ylv
),
api_get_ylv
)
self
.
http_handlers
.
register
(
lambda
m
,
p
:
(
m
==
"GET"
)
and
(
p
==
CONFIG_HTTP
[
"API_ROOT"
]),
api_get_root
)
self
.
http_handlers
.
register
(
lambda
m
,
p
:
(
m
==
"POST"
)
and
(
p
.
startswith
(
API_ROOT_data
)),
api_post
)
...
...
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