Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tosca2doc
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
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
CTI Tools
tosca2doc
Commits
929b5263
Commit
929b5263
authored
4 years ago
by
carignani
Browse files
Options
Downloads
Patches
Plain Diff
Prepare for release
parent
680e0ed8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
Readme.md
+8
-0
8 additions, 0 deletions
Readme.md
relaunch.sh
+2
-1
2 additions, 1 deletion
relaunch.sh
src/config.py
+18
-0
18 additions, 0 deletions
src/config.py
src/web_app.py
+32
-18
32 additions, 18 deletions
src/web_app.py
with
61 additions
and
19 deletions
.gitignore
+
1
−
0
View file @
929b5263
*.pyc
*.pyc
env
This diff is collapsed.
Click to expand it.
Readme.md
+
8
−
0
View file @
929b5263
# Tosca Import/Export
# Tosca Import/Export
## Create `env` file
cp env_example env
$EDITOR env # Customize SECRET
## Run with docker
## Run with docker
...
@@ -20,3 +24,7 @@ Install prerequisites
...
@@ -20,3 +24,7 @@ Install prerequisites
Run the web_app
Run the web_app
python src/web_app.py
python src/web_app.py
## Licensing
See LICENSE file.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
relaunch.sh
+
2
−
1
View file @
929b5263
#!/bin/bash
CNT
=
$(
docker ps |
grep
tosca-ie |
cut
-d
" "
-f1
)
CNT
=
$(
docker ps |
grep
tosca-ie |
cut
-d
" "
-f1
)
if
[
"
$CNT
"
!=
""
]
;
then
if
[
"
$CNT
"
!=
""
]
;
then
...
@@ -10,5 +11,5 @@ fi
...
@@ -10,5 +11,5 @@ fi
docker build
-t
tosca-ie-sample:latest
.
docker build
-t
tosca-ie-sample:latest
.
docker run
-d
-
t
-p
5000:5000
tosca-ie-sample
docker run
-d
-
-restart
unless-stopped
-t
-p
5000:5000
--env-file
./env
tosca-ie-sample
This diff is collapsed.
Click to expand it.
src/config.py
+
18
−
0
View file @
929b5263
'''
Configuration values
'''
import
os
def
env_or_false
(
key
):
'''
Lookup environment key, returns False is not present
'''
try
:
return
os
.
environ
[
key
]
except
KeyError
:
return
False
VERSION
=
"
0.0.4
"
VERSION
=
"
0.0.4
"
SECRET
=
env_or_false
(
"
TOSCAIE_SECRET
"
)
or
'
super_secret_key
'
This diff is collapsed.
Click to expand it.
src/web_app.py
+
32
−
18
View file @
929b5263
#!/bin/python3
#!/bin/python3
'''
Web app to offer a frontend to the doc2tosca and tosca2doc tools
'''
import
os
import
os
import
shutil
import
shutil
...
@@ -15,8 +19,8 @@ import doc2tosca
...
@@ -15,8 +19,8 @@ import doc2tosca
class
ReverseProxied
(
object
):
class
ReverseProxied
(
object
):
def
__init__
(
self
,
app
,
script_name
=
None
,
scheme
=
None
,
server
=
None
):
def
__init__
(
self
,
the_
app
,
script_name
=
None
,
scheme
=
None
,
server
=
None
):
self
.
app
=
app
self
.
app
=
the_
app
self
.
script_name
=
script_name
self
.
script_name
=
script_name
self
.
scheme
=
scheme
self
.
scheme
=
scheme
self
.
server
=
server
self
.
server
=
server
...
@@ -36,7 +40,6 @@ class ReverseProxied(object):
...
@@ -36,7 +40,6 @@ class ReverseProxied(object):
environ
[
'
HTTP_HOST
'
]
=
server
environ
[
'
HTTP_HOST
'
]
=
server
return
self
.
app
(
environ
,
start_response
)
return
self
.
app
(
environ
,
start_response
)
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
app
.
wsgi_app
=
ReverseProxied
(
app
.
wsgi_app
,
script_name
=
'
/tosca-ie
'
)
app
.
wsgi_app
=
ReverseProxied
(
app
.
wsgi_app
,
script_name
=
'
/tosca-ie
'
)
...
@@ -45,11 +48,15 @@ UPLOAD_FOLDER = '/tmp/upload'
...
@@ -45,11 +48,15 @@ UPLOAD_FOLDER = '/tmp/upload'
ALLOWED_EXTENSIONS
=
set
([
'
txt
'
,
'
yaml
'
,
'
docx
'
])
ALLOWED_EXTENSIONS
=
set
([
'
txt
'
,
'
yaml
'
,
'
docx
'
])
app
.
config
[
'
UPLOAD_FOLDER
'
]
=
UPLOAD_FOLDER
app
.
config
[
'
UPLOAD_FOLDER
'
]
=
UPLOAD_FOLDER
app
.
secret_key
=
'
super secret key
'
app
.
secret_key
=
config
.
SECRET
app
.
config
[
'
SESSION_TYPE
'
]
=
'
filesystem
'
app
.
config
[
'
SESSION_TYPE
'
]
=
'
filesystem
'
TOSCA_DEFS
=
[
'
VNFD
'
,
'
NSD
'
,
'
PNFD
'
]
TOSCA_DEFS
=
[
'
VNFD
'
,
'
NSD
'
,
'
PNFD
'
]
MISSING_MODULE_ERR_MSG
=
\
'
Error: some TOSCA module missing. Make sure to
\
upload definitions for NSD, VNFD, PNFD.
'
def
allowed_file
(
filename
):
def
allowed_file
(
filename
):
'''
'''
Check filename is in the list of allowed extensions
Check filename is in the list of allowed extensions
...
@@ -57,13 +64,16 @@ def allowed_file(filename):
...
@@ -57,13 +64,16 @@ def allowed_file(filename):
return
'
.
'
in
filename
and
\
return
'
.
'
in
filename
and
\
filename
.
rsplit
(
'
.
'
,
1
)[
1
].
lower
()
in
ALLOWED_EXTENSIONS
filename
.
rsplit
(
'
.
'
,
1
)[
1
].
lower
()
in
ALLOWED_EXTENSIONS
@app.route
(
"
/
"
)
@app.route
(
"
/
"
)
def
hello
():
def
hello
():
'''
'''
Render home page
Render home page
'''
'''
return
render_template
(
"
./home.html
"
,
VERSION
=
config
.
VERSION
,
doc_allowed_versions
=
doc2tosca
.
allowed_versions
)
return
render_template
(
"
./home.html
"
,
VERSION
=
config
.
VERSION
,
doc_allowed_versions
=
doc2tosca
.
allowed_versions
)
@app.route
(
"
/doc2tosca-info
"
)
@app.route
(
"
/doc2tosca-info
"
)
def
doc2tosca_info
():
def
doc2tosca_info
():
...
@@ -81,6 +91,9 @@ def tosca2doc_info():
...
@@ -81,6 +91,9 @@ def tosca2doc_info():
@app.route
(
"
/tosca2doc
"
,
methods
=
[
'
POST
'
])
@app.route
(
"
/tosca2doc
"
,
methods
=
[
'
POST
'
])
def
mk_tosca2doc
():
def
mk_tosca2doc
():
'''
Execute tosca2doc on the uploaded files
'''
if
'
file
'
not
in
request
.
files
:
if
'
file
'
not
in
request
.
files
:
flash
(
'
Error: No file uploaded.
'
)
flash
(
'
Error: No file uploaded.
'
)
...
@@ -94,12 +107,8 @@ def mk_tosca2doc():
...
@@ -94,12 +107,8 @@ def mk_tosca2doc():
if
tosca_def
in
uploaded_file
.
filename
or
\
if
tosca_def
in
uploaded_file
.
filename
or
\
tosca_def
.
lower
()
in
uploaded_file
.
filename
:
tosca_def
.
lower
()
in
uploaded_file
.
filename
:
found
=
True
found
=
True
#if uploaded_file:
# print "-------------------"
# print uploaded_file.read()
# print "-------------------"
if
not
found
:
if
not
found
:
flash
(
'
Error: some TOSCA module missing. Make sure to upload definitions for NSD, VNFD, PNFD.
'
)
flash
(
MISSING_MODULE_ERR_MSG
)
print
(
'
Error: TOSCA module missing.
'
)
print
(
'
Error: TOSCA module missing.
'
)
return
redirect
(
"
/tosca-ie
"
)
return
redirect
(
"
/tosca-ie
"
)
...
@@ -133,27 +142,29 @@ def mk_tosca2doc():
...
@@ -133,27 +142,29 @@ def mk_tosca2doc():
#return ("No content found")
#return ("No content found")
def
get_all_yaml_file_paths
(
directory
):
def
get_all_yaml_file_paths
(
directory
):
'''
Finds yaml files within a directory and sub directories and
returns the list of paths
'''
# initializing empty file paths list
file_paths
=
[]
file_paths
=
[]
# crawling through directory and subdirectories
for
root
,
_
,
files
in
os
.
walk
(
directory
):
for
root
,
directories
,
files
in
os
.
walk
(
directory
):
for
filename
in
files
:
for
filename
in
files
:
if
"
.yaml
"
in
filename
:
if
"
.yaml
"
in
filename
:
# join the two strings in order to form the full filepath.
filepath
=
os
.
path
.
join
(
root
,
filename
)
filepath
=
os
.
path
.
join
(
root
,
filename
)
file_paths
.
append
(
filepath
)
file_paths
.
append
(
filepath
)
print
(
filepath
)
# returning all file paths
return
file_paths
return
file_paths
@app.after_request
@app.after_request
def
after_request
(
response
):
def
after_request
(
response
):
'''
Clean up files created by doc2tosca
'''
if
request
.
path
!=
'
/doc2tosca
'
:
if
request
.
path
!=
'
/doc2tosca
'
:
return
response
return
response
if
g
.
get
(
'
tmp_dir
'
)
==
None
:
if
g
.
get
(
'
tmp_dir
'
)
is
None
:
return
response
return
response
shutil
.
rmtree
(
g
.
tmp_dir
,
ignore_errors
=
True
)
shutil
.
rmtree
(
g
.
tmp_dir
,
ignore_errors
=
True
)
print
(
"
Deleted {}
\n\n
"
.
format
(
g
.
tmp_dir
))
print
(
"
Deleted {}
\n\n
"
.
format
(
g
.
tmp_dir
))
...
@@ -161,6 +172,9 @@ def after_request(response):
...
@@ -161,6 +172,9 @@ def after_request(response):
@app.route
(
"
/doc2tosca
"
,
methods
=
[
'
POST
'
])
@app.route
(
"
/doc2tosca
"
,
methods
=
[
'
POST
'
])
def
mk_doc2tosca
():
def
mk_doc2tosca
():
'''
Executes doc2tosca on the uploaded file
'''
zip_fn
=
"
tosca_defs.zip
"
zip_fn
=
"
tosca_defs.zip
"
...
...
This diff is collapsed.
Click to expand it.
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