Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
9551f6d6
Commit
9551f6d6
authored
Oct 04, 2019
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
split methods to util and set node properties to default
parent
6606fbe8
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
206 additions
and
98 deletions
+206
-98
planner.py
drip_planner2/src/planner/planner.py
+89
-89
spec_service.py
drip_planner2/src/planner/spec_service.py
+4
-5
rpc_server.py
drip_planner2/src/rpc_server.py
+6
-4
tosca.py
drip_planner2/src/utils/tosca.py
+107
-0
No files found.
drip_planner2/src/planner/planner.py
View file @
9551f6d6
This diff is collapsed.
Click to expand it.
drip_planner2/src/planner/spec_service.py
View file @
9551f6d6
class
SpecService
:
class
SpecService
:
def
__init__
(
self
,
props
):
def
__init__
(
self
,
conf
):
self
.
properties
=
props
self
.
configuration
=
conf
def
get_vm_username
(
self
):
def
get_property
(
self
,
prop_key
):
return
"vm_user"
return
None
\ No newline at end of file
drip_planner2/src/rpc_server.py
View file @
9551f6d6
...
@@ -15,6 +15,7 @@ import tempfile
...
@@ -15,6 +15,7 @@ import tempfile
import
time
import
time
import
logging
import
logging
import
base64
import
base64
from
utils
import
tosca
as
tosca_util
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
# if not getattr(logger, 'handler_set', None):
# if not getattr(logger, 'handler_set', None):
...
@@ -127,10 +128,11 @@ if __name__ == "__main__":
...
@@ -127,10 +128,11 @@ if __name__ == "__main__":
tosca_file_path
=
"../../TOSCA/application_example.yaml"
tosca_file_path
=
"../../TOSCA/application_example.yaml"
# planner = BasicPlanner(tosca_file_path)
# planner = BasicPlanner(tosca_file_path)
planner
=
Planner
(
tosca_file_path
)
planner
=
Planner
(
tosca_file_path
)
planner
.
resolve_requirements
()
required_nodes
=
planner
.
resolve_requirements
()
planner
.
set_infrastructure_specifications
()
required_nodes
=
planner
.
set_infrastructure_specifications
(
required_nodes
)
template
=
planner
.
get_tosca_template
()
planner
.
add_required_nodes_to_template
(
required_nodes
)
# logger.info("template ----: \n" + template)
template
=
tosca_util
.
get_tosca_template_as_yml
(
planner
.
template
)
logger
.
info
(
"template ----:
\n
"
+
template
)
else
:
else
:
logger
.
info
(
"Input args: "
+
sys
.
argv
[
0
]
+
' '
+
sys
.
argv
[
1
]
+
' '
+
sys
.
argv
[
2
])
logger
.
info
(
"Input args: "
+
sys
.
argv
[
0
]
+
' '
+
sys
.
argv
[
1
]
+
' '
+
sys
.
argv
[
2
])
channel
=
init_chanel
(
sys
.
argv
)
channel
=
init_chanel
(
sys
.
argv
)
...
...
drip_planner2/src/utils/tosca.py
0 → 100644
View file @
9551f6d6
from
toscaparser.nodetemplate
import
NodeTemplate
from
utils.TOSCA_parser
import
TOSCAParser
node_type_key_names_to_remove
=
[
'capabilities'
,
'requirements'
,
'derived_from'
]
def
get_node_type_name
(
node
):
if
isinstance
(
node
,
NodeTemplate
):
node_type
=
node
.
type
elif
isinstance
(
node
,
dict
):
node_type
=
next
(
iter
(
node
))
return
node_type
def
get_node_requirements
(
node
):
if
isinstance
(
node
,
NodeTemplate
):
node_requirements
=
node
.
requirements
elif
isinstance
(
node
,
dict
):
node_type_name
=
get_node_type_name
(
node
)
if
'requirements'
not
in
node
[
node_type_name
]:
node
[
node_type_name
][
'requirements'
]
=
{}
node_requirements
=
node
[
node_type_name
][
'requirements'
]
return
node_requirements
def
get_parent_type
(
node
):
if
isinstance
(
node
,
NodeTemplate
):
parent_type
=
node
.
parent_type
elif
isinstance
(
node
,
dict
):
parent_type
=
node
[
node_type_name
][
'derived_from'
]
return
parent_type
def
get_node_type_requirements
(
type_name
,
all_nodes
):
def_type
=
all_nodes
[
type_name
]
if
'requirements'
in
def_type
.
keys
():
return
def_type
[
'requirements'
]
return
None
def
get_parent_type_requirements
(
node
,
all_nodes
):
if
isinstance
(
node
,
NodeTemplate
):
if
node
.
parent_type
and
node
.
parent_type
.
requirements
:
parent_type_requirements
=
node
.
parent_type
.
requirements
else
:
parent_type_requirements
=
{}
elif
isinstance
(
node
,
dict
):
node_type_name
=
get_node_type_name
(
node
)
parent_type_requirements
=
get_node_type_requirements
(
node_type_name
,
all_nodes
)
return
parent_type_requirements
def
get_node_types_with_interface
(
nodes
):
node_types_with_interface
=
[]
for
node_name
in
nodes
:
if
'interfaces'
in
nodes
[
node_name
]
.
keys
()
and
'tosca.nodes.Root'
!=
node_name
:
node_types_with_interface
.
append
(
node_name
)
return
node_types_with_interface
def
node_type_2_node_template
(
node_type
):
nodetemplate_dict
=
{}
type_name
=
next
(
iter
(
node_type
))
node_type_array
=
type_name
.
split
(
"."
)
name
=
node_type_array
[
len
(
node_type_array
)
-
1
]
.
lower
()
nodetemplate_dict
[
name
]
=
node_type
[
next
(
iter
(
node_type
))]
.
copy
()
nodetemplate_dict
[
name
][
'type'
]
=
type_name
for
name_to_remove
in
node_type_key_names_to_remove
:
if
name_to_remove
in
nodetemplate_dict
[
name
]:
nodetemplate_dict
[
name
]
.
pop
(
name_to_remove
)
if
'type'
in
node_type
[
next
(
iter
(
node_type
))]:
node_type
[
next
(
iter
(
node_type
))]
.
pop
(
'type'
)
return
NodeTemplate
(
name
,
nodetemplate_dict
,
node_type
)
def
get_tosca_template_as_yml
(
template
):
tp
=
TOSCAParser
()
yaml_str
=
tp
.
tosca_template2_yaml
(
template
)
return
yaml_str
def
contains_node_type
(
node_types_list
,
node_type_name
):
if
node_types_list
is
None
:
return
False
for
node_type
in
node_types_list
:
if
isinstance
(
node_type
,
NodeTemplate
):
type_name
=
node_type
.
type
elif
isinstance
(
node_type
,
dict
):
type_name
=
next
(
iter
(
node_type
))
if
type_name
==
node_type_name
:
return
True
return
False
def
get_node_properties
(
node
):
node_type_name
=
get_node_type_name
(
node
)
return
node
[
node_type_name
][
'properties'
]
def
set_node_properties
(
node
,
properties
):
node_type_name
=
get_node_type_name
(
node
)
node
[
node_type_name
][
'properties'
]
=
properties
return
node
\ No newline at end of file
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