Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
controller
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TFS
controller
Commits
e156b3d3
Commit
e156b3d3
authored
10 months ago
by
Alberto Gonzalez Barneo
Committed by
Alberto Gonzalez Barneo
10 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Added folder app with some compoaspects gisters apps app with new component app register for qkd
parent
6c4ef63c
No related branches found
No related tags found
2 merge requests
!294
Release TeraFlowSDN 4.0
,
!265
Resolve: "(OPT) QKD Application Register (new component)"
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/service/rest_server/qkd_app/Resources.py
+72
-0
72 additions, 0 deletions
src/app/service/rest_server/qkd_app/Resources.py
src/app/service/rest_server/qkd_app/__init__.py
+16
-0
16 additions, 0 deletions
src/app/service/rest_server/qkd_app/__init__.py
with
88 additions
and
0 deletions
src/app/service/rest_server/qkd_app/Resources.py
0 → 100644
+
72
−
0
View file @
e156b3d3
import
uuid
,
json
from
flask
import
request
from
flask_restful
import
Resource
from
common.proto.context_pb2
import
Empty
from
common.proto.app_pb2
import
App
,
QKDAppTypesEnum
from
common.Constants
import
DEFAULT_CONTEXT_NAME
from
context.client.ContextClient
import
ContextClient
from
app.client.AppClient
import
AppClient
class
_Resource
(
Resource
):
def
__init__
(
self
)
->
None
:
super
().
__init__
()
self
.
context_client
=
ContextClient
()
self
.
app_client
=
AppClient
()
class
Index
(
_Resource
):
def
get
(
self
):
return
{
'
hello
'
:
'
world
'
}
class
CreateQKDApp
(
_Resource
):
# Optare: Post request for the QKD Node to call the TeraflowSDN. Example of requests below
def
post
(
self
):
app
=
request
.
get_json
()[
'
app
'
]
devices
=
self
.
context_client
.
ListDevices
(
Empty
())
devices
=
devices
.
devices
local_device
=
None
# This for-loop won't be necessary if we can garantee Device ID is the same as QKDN Id
for
device
in
devices
:
for
config_rule
in
device
.
device_config
.
config_rules
:
if
config_rule
.
custom
.
resource_key
==
'
__node__
'
:
value
=
json
.
loads
(
config_rule
.
custom
.
resource_value
)
qkdn_id
=
value
[
'
qkdn_id
'
]
if
app
[
'
local_qkdn_id
'
]
==
qkdn_id
:
local_device
=
device
break
# Optare: Todo: Verify that a service is present for this app
'''
requests.post(
'
http://10.211.36.220/app/create_qkd_app
'
, json={
'
app
'
: {
'
server_app_id
'
:
'
1
'
,
'
client_app_id
'
:[],
'
app_status
'
:
'
ON
'
,
'
local_qkdn_id
'
:
'
00000001-0000-0000-0000-000000000000
'
,
'
backing_qkdl_id
'
:[
'
00000003-0002-0000-0000-000000000000
'
]}})
requests.post(
'
http://10.211.36.220/app/create_qkd_app
'
, json={
'
app
'
: {
'
server_app_id
'
:
'
1
'
,
'
client_app_id
'
:[],
'
app_status
'
:
'
ON
'
,
'
local_qkdn_id
'
:
'
00000003-0000-0000-0000-000000000000
'
,
'
backing_qkdl_id
'
:[
'
00000003-0002-0000-0000-000000000000
'
]}})
'''
if
local_device
is
None
:
return
{
"
status
"
:
"
fail
"
}
external_app_src_dst
=
{
'
app_id
'
:
{
'
context_id
'
:
{
'
context_uuid
'
:
{
'
uuid
'
:
DEFAULT_CONTEXT_NAME
}},
'
app_uuid
'
:
{
'
uuid
'
:
''
}},
'
app_status
'
:
'
QKDAPPSTATUS_
'
+
app
[
'
app_status
'
],
'
app_type
'
:
QKDAppTypesEnum
.
QKDAPPTYPES_CLIENT
,
'
server_app_id
'
:
app
[
'
server_app_id
'
],
'
client_app_id
'
:
app
[
'
client_app_id
'
],
'
backing_qkdl_id
'
:
[{
'
qkdl_uuid
'
:
{
'
uuid
'
:
qkdl_id
}}
for
qkdl_id
in
app
[
'
backing_qkdl_id
'
]],
'
local_device_id
'
:
local_device
.
device_id
,
'
remote_device_id
'
:
{
'
device_uuid
'
:
{
'
uuid
'
:
''
}},
}
# Optare: This will call our internal RegisterApp which supports the creation of both internal and external app.
# Optare the verification for knowing if two parties are requesting the same app is done inside RegisterApp's function
self
.
app_client
.
RegisterApp
(
App
(
**
external_app_src_dst
))
# Optare: Todo: Communicate by SBI with both Nodes of the new App
return
{
"
status
"
:
"
success
"
}
This diff is collapsed.
Click to expand it.
src/app/service/rest_server/qkd_app/__init__.py
0 → 100644
+
16
−
0
View file @
e156b3d3
from
app.service.rest_server.RestServer
import
RestServer
from
.Resources
import
(
CreateQKDApp
,
Index
)
URL_PREFIX
=
'
/app
'
# Use 'path' type since some identifiers might contain char '/' and Flask is unable to recognize them in 'string' type.
RESOURCES
=
[
# (endpoint_name, resource_class, resource_url)
(
'
api.index
'
,
Index
,
'
/
'
),
(
'
api.register_qkd_app
'
,
CreateQKDApp
,
'
/create_qkd_app
'
),
]
def
register_qkd_app
(
app_server
:
RestServer
):
for
endpoint_name
,
resource_class
,
resource_url
in
RESOURCES
:
app_server
.
add_resource
(
resource_class
,
URL_PREFIX
+
resource_url
,
endpoint
=
endpoint_name
)
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment