Commit 311272e2 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Try to use parser

parent 35812d5f
......@@ -18,7 +18,7 @@ RUN pip install numpy
RUN pip install networkx==1.10
RUN pip install flask
RUN pip install tosca-parser
RUN pip install pika
RUN pip install pika==0.11.2
RUN export LC_ALL="en_US.UTF-8"
RUN pip install paramiko
......
tosca_definitions_version: tosca_simple_yaml_1_0
imports:
- types/nodes.yaml
- types/interfaces.yaml
- indigo_custom_types: types/nodes.yaml
repositories:
docker_hub: https://hub.docker.com/
description: >
TOSCA example
topology_template:
node_templates:
wordpres:
type: tosca.nodes.Container.Application.Docker
wordpress:
type: tosca.nodes.SWITCH.Container.Application.Docker
requirements:
- service:
node: mysql
relationship:
type: tosca.relationships.ConnectsTo
artifacts:
my_image:
file: wordpress:latest
type: tosca.artifacts.Deployment.Image.Container.Docker
repository: docker_hub
properties:
ports:
- "8000:80"
environment:
WORDPRESS_DB_HOST: mysql-db:3306
WORDPRESS_DB_HOST: mysql:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
artifacts:
image:
type: tosca.artifacts.Deployment.Image.Container.Docker
file: wordpress:latest
repository: docker_hub
requirements:
- db:
node: mysql-db
relationship:
type: tosca.relationships.ConnectsTo
mysql-db:
type: tosca.nodes.Container.Application.Docker
mysql:
type: tosca.nodes.SWITCH.Container.Application.Docker
properties:
volumes:
- db_data:/var/lib/mysql
......@@ -47,3 +45,9 @@ topology_template:
type: tosca.artifacts.Deployment.Image.Container.Docker
file: mysql:5.7
repository: docker_hub
......@@ -2,9 +2,12 @@ tosca_definitions_version: tosca_simple_yaml_1_0
node_types:
tosca.nodes.Container.Application.Docker:
derived_from: tosca.nodes.Container
tosca.nodes.SWITCH.Container.Application.Docker:
derived_from: tosca.nodes.Container.Application.Docker
description: description of container
capabilities:
service:
type: tosca.capabilities.Container.Docker
properties:
ports:
description: ports to be forwarded
......@@ -26,106 +29,12 @@ node_types:
description: volume
type: list
required: false
capabilities:
service:
type: tosca.capabilities.Container.Docker
requirements:
- service:
capability: tosca.capabilities.Container.Docker
node: tosca.nodes.SWITCH.Container.Application.Docker
relationship: tosca.relationships.ConnectsTo
- host:
capability: tosca.capabilities.Container.Orchestrator.Docker
node: tosca.nodes.Container.Orchestrator.Docker
capability: tosca.capabilities.Compute
node: tosca.nodes.Compute
relationship: tosca.relationships.HostedOn
tosca.nodes.Container.Orchestrator.Docker.Swarm:
derived_from: tosca.nodes.Container.Orchestrator.Docker
description: The swarm Docker Orchestrator
interfaces:
Ansible:
type: tosca.interfaces.Ansible
tosca.nodes.Container.Orchestrator.Docker:
derived_from: tosca.nodes.Container.Orchestrator
description: Docker Orchestrator
capabilities:
host:
type: tosca.capabilities.Container.Orchestrator.Docker
requirements:
- host:
capability: tosca.capabilities.Compute.Cluster
node: tosca.nodes.Compute.VM.Cluster
relationship: tosca.relationships.HostedOn
tosca.nodes.Compute.VM.Cluster:
derived_from:
description: A cluster of VM able
properties:
vms:
description: a list of VMs in the cluster. At lest one of them must be the master
type: list
required: true
capabilities:
host:
type: tosca.capabilities.Compute.Cluster
tosca.nodes.Compute.VM:
derived_from: tosca.nodes.Compute
description: VM
properties:
name:
description: host name
type: string
required: true
user_names:
description: list of user name
type: list
required: true
id:
description: vm id
type: string
required: true
num_of_cpu:
description: number of cpu
type: int
required: true
mem_size:
description: ram size in MB
type: int
required: true
disk_size:
description: disk size in MB
type: int
required: true
ip_addresses:
description: available IP addresses
type: int
required: true
role:
description: available IP addresses
type: string
required: true
os_type:
description: OS example: Ubuntu 16.04
type: string
required: true
capabilities:
host:
type: tosca.capabilities.Compute
tosca.nodes.Compute.VM.ExoGENI:
derived_from: tosca.nodes.Compute.VM
description: VM
properties:
domain:
description: site where the VM is hosted, example: RENCI (Chapel Hill, NC USA) XO Rack
type: string
required: true
state:
description: the state of the VM, running, paused, stopped
type: string
required: true
ssh_key_pair_id:
description: the id of the ssh key
type: string
required: true
capabilities:
host:
type: tosca.capabilities.Scale
tosca_definitions_version: tosca_simple_yaml_1_1
policy_types:
tosca.policies.root:
description: From 'http://docs.oasis-open.org/tosca/TOSCA/v1.0/os/TOSCA-v1.0-os.html#_Toc356403653': Non-functional behavior or quality-of-services are defined in TOSCA by means of policies. A Policy can express such diverse things like monitoring behavior, payment conditions, scalability, or continuous availability.
A Node Template can be associated with a set of Policies collectively expressing the non-functional behavior or quality-of-services that each instance of the Node Template will expose. Each Policy specifies the actual properties of the non-functional behavior, like the concrete payment information (payment period, currency, amount etc) about the individual instances of the Node Template.
Policy Templates provide actual values of properties of the types defined by Policy Types. For example, a Policy Template for monthly payments for US customers will set the “payment period” property to “monthly” and the “currency” property to “US$”, leaving the “amount” property open. The “amount” property will be set when the corresponding Policy Template is used for a Policy within a Node Template. Thus, a Policy Template defines the invariant properties of a Policy, while the Policy sets the variant properties resulting from the actual usage of a Policy Template in a Node Template.
tosca.policies.Requirement.Network.connection:
description: Connection Requirement
derived_from: tosca.policies.Root
properties:
ip:
type: string
description: IP and Netmask (e.g. 10.0.0.1/8) that should be reachable from the container.
tosca.policies.Requirement.Location:
description: Location Requirement
derived_from: tosca.policies.Root
properties:
desired_lat:
type: double
description: desired latitude coordinates of container
desired_lon:
type: double
description: desired longitude coordinates of container
min_distance:
type: double
description: the minimum accepted distance from the desired location
tosca.policies.Requirement.Network.Bandwidth:
description: Bandwidth Requirement
derived_from: tosca.policies.Root
properties:
download_speed:
type: integer
description: max download speed in bit/s
upload_speed:
type: integer
description: max upload speed bit/s
target:
type: string
description: target host or IP to download or upload data
tosca.policies.Container.Scale:
description: spawn new container instance when a specified metric is grater or less than a threshold
derived_from: tosca.policies.Root
properties:
threshold:
type: double
description: threshold to spawn new container
condition:
type: string
description: grater (gt) or less (lt) than the set threshold
metric_name:
type: string
description: the metric to monitor
node_name:
type: string
description: the container to scale (should be type tosca.nodes.Container)
tosca.policies.VM.Scale:
description: spawn new container instance when a specified metric is grater or less than a threshold
derived_from: tosca.policies.Root
properties:
threshold:
type: double
description: threshold to spawn new container
condition:
type: string
description: grater (gt) or less (lt) than the set threshold
metric_name:
type: string
description: the metric to monitor
node_name:
type: string
description: the container to scale (should be type tosca.nodes.VM)
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/drip_planner2.iml" filepath="$PROJECT_DIR$/.idea/drip_planner2.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/../Dockerfiles/planner/Dockerfile" beforeDir="false" afterPath="$PROJECT_DIR$/../Dockerfiles/planner/Dockerfile" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../TOSCA/application_example.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../TOSCA/application_example.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../TOSCA/types/nodes.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../TOSCA/types/nodes.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/planner/basic_planner.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/basic_planner.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/rpc_server.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/rpc_server.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/rpc_server.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="152">
<caret line="113" selection-start-line="113" selection-end-line="118" selection-end-column="92" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/planner/basic_planner.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="81">
<caret line="19" selection-start-line="19" selection-end-line="19" />
<folding>
<element signature="e#0#11#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$USER_HOME$/.local/lib/python3.6/site-packages/toscaparser/elements/nodetype.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="774">
<caret line="92" column="41" selection-start-line="92" selection-start-column="41" selection-end-line="92" selection-end-column="41" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$USER_HOME$/.local/lib/python3.6/site-packages/toscaparser/nodetemplate.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="378">
<caret line="60" selection-start-line="60" selection-end-line="60" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$USER_HOME$/.local/lib/python3.6/site-packages/toscaparser/tpl_relationship_graph.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="162">
<caret line="18" selection-start-line="18" selection-end-line="18" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$USER_HOME$/.local/lib/python3.6/site-packages/toscaparser/topology_template.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="414">
<caret line="59" selection-start-line="59" selection-end-line="59" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$USER_HOME$/.local/lib/python3.6/site-packages/toscaparser/tosca_template.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="747">
<caret line="100" selection-start-line="100" selection-end-line="100" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="ProjectConfigurationFiles">
<option name="files">
<list>
<option value="$PROJECT_DIR$/.idea/vcs.xml" />
</list>
</option>
</component>
<component name="ProjectFrameBounds">
<option name="x" value="33" />
<option name="y" value="13" />
<option name="width" value="922" />
<option name="height" value="526" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="drip_planner2" type="b2602c69:ProjectViewProjectNode" />
<item name="drip_planner2" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="drip_planner2" type="b2602c69:ProjectViewProjectNode" />
<item name="drip_planner2" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="drip_planner2" type="b2602c69:ProjectViewProjectNode" />
<item name="drip_planner2" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="planner" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
</panes>
</component>
<component name="PropertiesComponent">
<property name="full.screen.before.presentation.mode" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="preferences.lookFeel" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager" selected="Python.rpc_server">
<configuration name="basic_planner" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="drip_planner2" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/src/planner" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/planner/basic_planner.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="rpc_server" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="drip_planner2" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/src" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/rpc_server.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.rpc_server" />
<item itemvalue="Python.basic_planner" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="" />
<created>1561727727309</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1561727727309</updated>
</task>
<servers />
</component>
<component name="ToolWindowManager">
<frame x="33" y="13" width="922" height="526" extended-state="0" />
<layout>
<window_info content_ui="combo" id="Project" order="0" weight="0.14317425" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.32984293" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.46596858" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Version Control" order="7" />
<window_info anchor="bottom" id="Terminal" order="8" />
<window_info anchor="bottom" id="Event Log" order="9" side_tool="true" />
<window_info anchor="bottom" id="Python Console" order="10" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout>
<layout-to-restore>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.14317425" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.32984293" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.46596858" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Version Control" order="7" />
<window_info anchor="bottom" id="Terminal" order="8" />
<window_info anchor="bottom" id="Event Log" order="9" side_tool="true" />
<window_info anchor="bottom" id="Python Console" order="10" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout-to-restore>
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$USER_HOME$/.local/lib/python3.6/site-packages/toscaparser/elements/nodetype.py</url>
<line>64</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/rpc_server.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="152">
<caret line="113" selection-start-line="113" selection-end-line="118" selection-end-column="92" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/planner/basic_planner.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="81">
<caret line="19" selection-start-line="19" selection-end-line="19" />
<folding>
<element signature="e#0#11#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/.local/lib/python3.6/site-packages/toscaparser/elements/nodetype.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="774">
<caret line="92" column="41" selection-start-line="92" selection-start-column="41" selection-end-line="92" selection-end-column="41" />
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/.local/lib/python3.6/site-packages/toscaparser/nodetemplate.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="378">
<caret line="60" selection-start-line="60" selection-end-line="60" />
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/.local/lib/python3.6/site-packages/toscaparser/tpl_relationship_graph.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="162">
<caret line="18" selection-start-line="18" selection-end-line="18" />
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/.local/lib/python3.6/site-packages/toscaparser/topology_template.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="414">
<caret line="59" selection-start-line="59" selection-end-line="59" />
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/.local/lib/python3.6/site-packages/toscaparser/tosca_template.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="747">
<caret line="100" selection-start-line="100" selection-end-line="100" />
</state>
</provider>
</entry>
</component>
</project>
\ No newline at end of file
......@@ -3,20 +3,26 @@ import operator
import pdb
import re
from toscaparser.tosca_template import ToscaTemplate
from toscaparser.topology_template import TopologyTemplate
import toscaparser.utils.yamlparser
import urllib
import urllib.parse
import sys
import pdb
class BasicPlanner:
def __init__(self, path):
dict_tpl = toscaparser.utils.yamlparser.load_yaml(path)
# print(dict_tpl)
node_templates = dict_tpl['topology_template']['node_templates']
# print(node_templates)
requirements = self.get_all_requirements(node_templates)
self.template = ToscaTemplate(path)
print("Description:"+self.template.description)
for node in self.template.nodetemplates:
print("Node: "+node.name+" Type:"+node.type+" Req: "+str(node.requirements))
# print(node.get_properties().keys())
# print(node.get_capabilities().keys)
......@@ -43,13 +49,13 @@ class BasicPlanner:
return node
def get_all_requirements(self, node_templates):
requirements = {}
for node_template_name in node_templates:
node_template = node_templates[node_template_name]
node_type = node_template['type']
if 'requirements' in node_template:
requirements = node_template['requirements']
print(requirements)
# all_requirements = self.get_super_types_requirements(node_type, None)
requirements[node_template_name] = node_template['requirements']
self.get_super_types_requirements(node_type, None)
# id = node_template['id']
# req = self.get_requirements(node_template)
# if(req):
......@@ -118,58 +124,12 @@ class BasicPlanner:
all_relationships.append(rel)
return all_relationships
def get_super_types(self, type_qName, supertypes):
if (supertypes == None):
supertypes = []
regex = r"\{(.*?)\}"
matches = re.finditer(regex, type_qName, re.MULTILINE | re.DOTALL)
namespace = next(matches).group(1)
id = type_qName.replace("{" + namespace + "}", "")
header = {'accept': 'application/json'}
#winery needs it double percent-encoded
encoded_namespace = urllib.parse.quote(namespace, safe='')
encoded_namespace = urllib.parse.quote(encoded_namespace, safe='')
type_name = namespace.rsplit('/', 1)[-1]
servicetemplate_url = self.tosca_reposetory_api_base_url + "/" + type_name + "/" + encoded_namespace + "/" + id + "/"
req = urllib.request.Request(url=servicetemplate_url, headers=header, method='GET')
res = urllib.request.urlopen(req, timeout=5)
res_body = res.read()
component = json.loads(res_body.decode("utf-8"))
if component:
comp = component['serviceTemplateOrNodeTypeOrNodeTypeImplementation'][0]
supertypes.append(comp)
if 'derivedFrom' in comp:
return self.get_super_types(comp['derivedFrom']['typeRef'], supertypes)
else:
return supertypes
def get_super_types(self, type, supertypes):
print(type)
def get_super_types_requirements(self, type_qName, requirements):
if (requirements == None):
requirements = []
regex = r"\{(.*?)\}"
matches = re.finditer(regex, type_qName, re.MULTILINE | re.DOTALL)
namespace = next(matches).group(1)
id = type_qName.replace("{" + namespace + "}", "")
header = {'accept': 'application/json'}
#winery needs it double percent-encoded
encoded_namespace = urllib.parse.quote(namespace, safe='')
encoded_namespace = urllib.parse.quote(encoded_namespace, safe='')
type_name = namespace.rsplit('/', 1)[-1]
servicetemplate_url = self.tosca_reposetory_api_base_url + "/" + type_name + "/" + encoded_namespace + "/" + id + "/"
req = urllib.request.Request(url=servicetemplate_url, headers=header, method='GET')
res = urllib.request.urlopen(req, timeout=5)
res_body = res.read()
component = json.loads(res_body.decode("utf-8"))
for c in component['serviceTemplateOrNodeTypeOrNodeTypeImplementation']:
if 'requirementDefinitions' in c and 'requirementDefinition' in c['requirementDefinitions']:
for req in c['requirementDefinitions']['requirementDefinition']:
requirements.append(req['requirementType'])
if 'derivedFrom' in c and c['derivedFrom'] and c['derivedFrom']['type']:
return self.get_super_types_requirements(c['derivedFrom']['type'], requirements)
return requirements
def get_super_types_requirements(self, node_type, requirements):
print(node_type)
def get_service_template(self, dict_tpl):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment