Commit f1c6b279 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Added environment for getting environment vars

parent 67f39af4
This diff is collapsed.
...@@ -82,7 +82,7 @@ def handle_delivery(message): ...@@ -82,7 +82,7 @@ def handle_delivery(message):
def test_local(): def test_local():
home = expanduser("~") home = expanduser("~")
transformer = DockerComposeTransformer(home+"/workspace/DRIP/docs/input_tosca_files/BEIA.yml") transformer = DockerComposeTransformer(home+"/workspace/DRIP/docs/input_tosca_files/Matej.BEIA.yml")
compose = transformer.getnerate_compose() compose = transformer.getnerate_compose()
print yaml.dump(compose) print yaml.dump(compose)
response = {} response = {}
......
...@@ -3,6 +3,17 @@ from toscaparser import * ...@@ -3,6 +3,17 @@ from toscaparser import *
from toscaparser.tosca_template import ToscaTemplate from toscaparser.tosca_template import ToscaTemplate
import toscaparser.utils.yamlparser import toscaparser.utils.yamlparser
import yaml import yaml
import logging
logger = logging.getLogger(__name__)
if not getattr(logger, 'handler_set', None):
logger.setLevel(logging.INFO)
h = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
h.setFormatter(formatter)
logger.addHandler(h)
logger.handler_set = True
class DockerComposeTransformer: class DockerComposeTransformer:
...@@ -50,7 +61,7 @@ class DockerComposeTransformer: ...@@ -50,7 +61,7 @@ class DockerComposeTransformer:
def get_enviroment_vars(self,properties): def get_enviroment_vars(self,properties):
environments = [] environments = []
for prop in properties: for prop in properties:
if prop == 'Environment_variables' or prop == 'Live_variables': if prop == 'Environment_variables' or prop == 'Live_variables' or prop =='Environment':
for var in properties[prop]: for var in properties[prop]:
environment ={} environment ={}
environment[var] = properties[prop][var] environment[var] = properties[prop][var]
...@@ -68,12 +79,12 @@ class DockerComposeTransformer: ...@@ -68,12 +79,12 @@ class DockerComposeTransformer:
for port_map_key in ports_mappings: for port_map_key in ports_mappings:
port_map = {} port_map = {}
host_port = ports_mappings[port_map_key]['host_port'] host_port = ports_mappings[port_map_key]['host_port']
if not isinstance(host_port, (int, long, float, complex)): if not isinstance(host_port, (int, long, float, complex)) and '$' in host_port:
host_port_var = host_port.replace('${','').replace('}','') host_port_var = host_port.replace('${','').replace('}','')
host_port = properties[host_port_var] host_port = properties[host_port_var]
container_port = ports_mappings[port_map_key]['container_port'] container_port = ports_mappings[port_map_key]['container_port']
if not isinstance(container_port, (int, long, float, complex)): if not isinstance(container_port, (int, long, float, complex)) and '$' in container_port:
container_port_var = container_port.replace('${','').replace('}','') container_port_var = container_port.replace('${','').replace('}','')
container_port = properties[container_port_var] container_port = properties[container_port_var]
port_map[host_port] = container_port port_map[host_port] = container_port
...@@ -82,12 +93,16 @@ class DockerComposeTransformer: ...@@ -82,12 +93,16 @@ class DockerComposeTransformer:
ports_mappings = properties['in_ports'] ports_mappings = properties['in_ports']
for port_map_key in ports_mappings: for port_map_key in ports_mappings:
port_map = {} port_map = {}
if 'host_port' in ports_mappings[port_map_key]:
host_port = ports_mappings[port_map_key]['host_port'] host_port = ports_mappings[port_map_key]['host_port']
container_port = None
if 'container_port' in ports_mappings[port_map_key]:
container_port = ports_mappings[port_map_key]['container_port'] container_port = ports_mappings[port_map_key]['container_port']
if 'protocol' in ports_mappings[port_map_key]: if 'protocol' in ports_mappings[port_map_key]:
protocol = ports_mappings[port_map_key]['protocol'] protocol = ports_mappings[port_map_key]['protocol']
if protocol: if protocol:
container_port=container_port+'/'+protocol container_port=container_port+'/'+protocol
if container_port:
port_map[host_port] = container_port port_map[host_port] = container_port
port_maps.append(port_map) port_maps.append(port_map)
if 'out_ports' in properties: if 'out_ports' in properties:
...@@ -110,6 +125,7 @@ class DockerComposeTransformer: ...@@ -110,6 +125,7 @@ class DockerComposeTransformer:
return node['requirements'] return node['requirements']
def get_volumes(self,requirements): def get_volumes(self,requirements):
if requirements:
volumes = [] volumes = []
for req in requirements: for req in requirements:
if 'volume' in req: if 'volume' in req:
...@@ -145,6 +161,7 @@ class DockerComposeTransformer: ...@@ -145,6 +161,7 @@ class DockerComposeTransformer:
properties = self.get_properties(node_templates[node_template_key]) properties = self.get_properties(node_templates[node_template_key])
environment = self.get_enviroment_vars(properties) environment = self.get_enviroment_vars(properties)
if environment:
service['environment'] = environment service['environment'] = environment
port_maps = self.get_port_map(properties) port_maps = self.get_port_map(properties)
......
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