Commit 602c11f5 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Implemented winery service. gets topology template nodes and node parents

parent 46193571
......@@ -25,3 +25,6 @@
/drip_parser.tar.gz
/docs/playbooks/set_dockerhub_credentials.yml
/drip_planner2/src/planner/__pycache__/
/winery_service/nbproject/private/
/winery_service/src/winery/__pycache__/
/tosca_service/nbproject/private/
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python3.6</pydev_property>
</pydev_project>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>drip_planner2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python3.6</pydev_property>
</pydev_project>
java.lib.path=
main.file=__main__.py
platform.active=Python_3.6.6
python.lib.path=
src.dir=src
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.python.project</type>
<configuration>
<data xmlns="http://nbpython.dev.java.net/ns/php-project/1">
<name>tosca_service</name>
<sources>
<root id="src.dir"/>
</sources>
<tests/>
</data>
</configuration>
</project>
# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.
import json
import logging
import os
import os.path
from os.path import expanduser
import pika
from winery.service import *
import sys
import tempfile
import time
if __name__ == "__main__":
tosca_reposetory_api_base_url = "http://localhost:8080/winery"
namespace = "http%253A%252F%252Fsne.uva.nl%252Fservicetemplates"
servicetemplate_id = "wordpress_w1-wip1"
repo = Service(tosca_reposetory_api_base_url)
servicetemplates = repo.get_servicetemplates(namespace,servicetemplate_id)
tt= repo.get_topology_template(servicetemplates)
node_templates = repo.get_node_templates(tt)
parents = repo.get_parents(node_templates[1])
print(parents)
from setuptools import setup, find_packages
setup (
name='drip_planner2',
version='0.1',
packages=find_packages(),
# Declare your packages' dependencies here, for eg:
install_requires=['foo>=3'],
# Fill in these to make your Egg ready for upload to
# PyPI
author='S. Koulouzis',
author_email='',
#summary = 'Just another Python package for the cheese shop',
url='',
license='',
long_description='Long description of the package',
# could also include long_description, download_url, classifiers, etc.
)
\ No newline at end of file
import json
import operator
import pdb
import re
from toscaparser.tosca_template import ToscaTemplate
import toscaparser.utils.yamlparser
import urllib
import urllib.parse
class Service:
service_template_names = ['serviceTemplateOrNodeTypeOrNodeTypeImplementation']
topology_template_names = ['topologyTemplate']
node_template_names = ['nodeTemplates']
requirement_names = ['requirements']
type_names = ['type']
relationships_names = ['relationshipTemplates']
service_templates = None
topology_templates = []
node_templates = []
requirements = {}
def __init__(self, tosca_reposetory_api_base_url):
self.tosca_reposetory_api_base_url = tosca_reposetory_api_base_url
def get_servicetemplates(self,namespace, servicetemplate_id):
servicetemplate_url = self.tosca_reposetory_api_base_url + "/servicetemplates/" + namespace + "/" + servicetemplate_id + "/"
header = {'accept': 'application/json'}
req = urllib.request.Request(url=servicetemplate_url, headers=header, method='GET')
res = urllib.request.urlopen(req, timeout=5)
res_body = res.read()
self.dict_tpl = json.loads(res_body.decode("utf-8"))
return self.dict_tpl
def get_topology_template(self, dict_tpl):
if (not self.topology_templates):
self.topology_templates = self.find(dict_tpl['serviceTemplateOrNodeTypeOrNodeTypeImplementation'][0], self.topology_template_names)
return self.topology_templates
def get_node_templates(self, topology_templates):
if (not self.node_templates):
nodes = self.find(topology_templates,self.node_template_names)
self.node_templates = nodes
return self.node_templates
def get_parents(self,template):
node_type = template['type']
node = self.get_object(node_type)['serviceTemplateOrNodeTypeOrNodeTypeImplementation'][0]
return self.get_type_parents(node,None)
def get_type_parents(self,type,parents):
if 'derivedFrom' in type:
type_str = type['derivedFrom']['typeRef']
parent = self.get_object(type_str)['serviceTemplateOrNodeTypeOrNodeTypeImplementation'][0]
if(parents == None):
parents = []
parents.append(parent)
self.get_type_parents(parent,parents)
return parents
def get_object(self,type_str):
regex = r"\{(.*?)\}"
matches = re.finditer(regex, type_str, re.MULTILINE | re.DOTALL)
namespace = next(matches).group(1)
id = type_str.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()
return json.loads(res_body.decode("utf-8"))
def find(self, dict_obj, names):
if dict_obj:
for name in names:
if(name in dict_obj):
return dict_obj[name]
\ No newline at end of file
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