Commit 3b41ac2a authored by Spiros Koulouzis's avatar Spiros Koulouzis

check if input is tosca create warning and parse as yml

parent 0e20afdd
topology_template:
node_templates:
"6be727ce-5fa1-4e6d-9a37-438d0ec94ff0":
artifacts:
"inputdistributor.cardiff_image":
type: "tosca.artifacts.Deployment.Image.Container.Docker"
file: null
repository: SWITCH_docker_hub
requirements:
- host:
node_filter:
capabilities:
host:
cpu_frequency: 1GHz
mem_size: 1GB
num_cpus: 1
disk_size: 1GB
os:
os_version: 16.04
distribution: ubuntu
type: linux
architecture: x86_64
type: "Switch.nodes.Application.Container.Docker.PEDRO.SANTOS_InputDistributor.Cardiff"
properties:
scaling_mode: single
QoS:
packet_loss: 0
response_time: 30ms
out_ports:
"24ba657c-8a18-4c7f-aed9-9498d88a85d2":
type: out
port: " 1 "
multicastAddrPort: 3000
inPort: 2000
in_ports:
"92aa59bd-2c48-4f25-a27f-1412dd2cc849":
type: in
port: " inPort "
waitingTime: 5
multicastAddrIP: "225.2.2.0"
ports_mapping:
port_mapping_0:
host_port: "${inPort}"
container_port: "${inPort}"
"573924ff-c075-4dfc-95c4-489e0a189040":
artifacts:
"inputdistributor.cardiff_image":
type: "tosca.artifacts.Deployment.Image.Container.Docker"
file: null
repository: SWITCH_docker_hub
requirements:
- host:
node_filter:
capabilities:
host:
cpu_frequency: 1GHz
mem_size: 1GB
num_cpus: 1
disk_size: 1GB
os:
os_version: 16.04
distribution: ubuntu
type: linux
architecture: x86_64
type: "Switch.nodes.Application.Container.Docker.PEDRO.SANTOS_InputDistributor.Cardiff"
properties:
scaling_mode: single
QoS:
packet_loss: 0
response_time: 30ms
out_ports:
"030029d5-63ef-472f-9697-df1380505281":
type: out
port: " 1 "
multicastAddrPort: 3000
inPort: 2000
in_ports:
"40974a48-8bcb-48ba-80a6-4d3c5f26f502":
type: in
port: " inPort "
waitingTime: 5
multicastAddrIP: "225.2.2.2"
ports_mapping:
port_mapping_0:
host_port: "${multicastAddrPort}"
container_port: "${multicastAddrPort}"
"8bc5abcb-ae55-4f82-adc6-21d4a2475381":
type: "Switch.nodes.Application.Connection"
properties:
latency: 20ms
bandwidth: 1Gb
target:
netmask: ""
component_name: "8b5621b5-fbe9-4f4a-b68a-57b00cb07b6a"
port_name: "52d0aa2c-0775-44b1-857e-006817a3d637"
address: ""
source:
netmask: ""
component_name: "573924ff-c075-4dfc-95c4-489e0a189040"
port_name: "030029d5-63ef-472f-9697-df1380505281"
address: ""
"f9a17d09-d8bd-4f95-962a-3d86d71d1332":
type: "Switch.nodes.Application.Connection"
properties:
latency: 20ms
bandwidth: 1Gb
target:
netmask: ""
component_name: "8bffa661-cfa4-49df-ad83-7eba8498b405"
port_name: "2e50ce74-9396-4058-8402-997d196c9fd7"
address: ""
source:
netmask: ""
component_name: "573924ff-c075-4dfc-95c4-489e0a189040"
port_name: "030029d5-63ef-472f-9697-df1380505281"
address: ""
"a52c6766-6805-4c62-ab71-e2353388d4d5":
type: "Switch.nodes.Application.Connection"
properties:
latency: 20ms
bandwidth: 1Gb
target:
netmask: ""
component_name: "432dc3f6-4d1c-4092-a365-7837ef92279c"
port_name: "7c36b4c1-58e1-4011-b00f-7641e09b2e5a"
address: ""
source:
netmask: ""
component_name: "8b5621b5-fbe9-4f4a-b68a-57b00cb07b6a"
port_name: "88d8db9a-7621-440c-8c80-370a2020b810"
address: ""
"bce936d3-fee5-4217-9c44-710e78c94a70":
type: "Switch.nodes.Application.Connection"
properties:
latency: 20ms
bandwidth: 1Gb
target:
netmask: ""
component_name: "8b5621b5-fbe9-4f4a-b68a-57b00cb07b6a"
port_name: "a75bc9ef-b485-4db7-8226-9c3d76ae8a9e"
address: ""
source:
netmask: ""
component_name: "6be727ce-5fa1-4e6d-9a37-438d0ec94ff0"
port_name: "24ba657c-8a18-4c7f-aed9-9498d88a85d2"
address: ""
"8b5621b5-fbe9-4f4a-b68a-57b00cb07b6a":
requirements:
- host:
node_filter:
capabilities:
host:
cpu_frequency: 3Ghz
mem_size: 1GB
num_cpus: 1
disk_size: 1GB
os:
os_version: 16.04
distribution: ubuntu
type: linux
architecture: x86_64
type: "Switch.nodes.Application.Container.Docker.PEDRO.SANTOS_Switcher.Cardiff"
properties:
scaling_mode: single
QoS:
packet_loss: 0
response_time: 30ms
switcherOutAddrIP: "226.2.2.2"
multicastAddrPort: 3000
multicastAddrPort2: 3002
in_ports:
"a75bc9ef-b485-4db7-8226-9c3d76ae8a9e":
type: in
port: " switcherREST "
"62bdc6c5-b179-4661-bda7-a5f94ee17247":
type: in
port: " 3 "
"52d0aa2c-0775-44b1-857e-006817a3d637":
type: in
port: " 2 "
waitingTime: 5
multicastAddrIP: "225.2.2.0"
switcherOutAddrPort: 6000
multicastAddrIP2: "225.2.2.2"
switcherREST: 8008
out_ports:
"88d8db9a-7621-440c-8c80-370a2020b810":
type: out
port: " 1 "
ports_mapping:
port_mapping_0:
host_port: "${switcherREST}"
container_port: "${switcherREST}"
videoWidth: 176
videoHeight: 100
"5a7c790f-e0cd-4eae-9145-85d2d9aadc66":
type: "Switch.nodes.Application.Connection"
properties:
latency: 20ms
bandwidth: 1Gb
target:
netmask: ""
component_name: "7855f235-7cd8-4091-8acc-f1df70bae6e2"
port_name: "4e52e9f4-19d2-4b32-96ee-67bd5775ab93"
address: ""
source:
netmask: ""
component_name: "8b5621b5-fbe9-4f4a-b68a-57b00cb07b6a"
port_name: "88d8db9a-7621-440c-8c80-370a2020b810"
address: ""
"7855f235-7cd8-4091-8acc-f1df70bae6e2":
requirements:
- host:
node_filter:
capabilities:
host:
cpu_frequency: 3GHz
mem_size: 1GB
num_cpus: 2
disk_size: 1GB
os:
os_version: 16.04
distribution: ubuntu
type: linux
architecture: x86_64
type: "Switch.nodes.Application.Container.Docker.PEDRO.SANTOS_ProxyTranscoder"
properties:
scaling_mode: single
QoS:
packet_loss: 0
response_time: 30ms
out_ports:
"60eea86c-64ed-48da-b991-6bf7c49c861c":
type: out
port: " outPort "
multicastAddrPort: 3000
in_ports:
"4e52e9f4-19d2-4b32-96ee-67bd5775ab93":
type: in
port: " 1 "
multicastAddrIP: "225.2.2.0"
ports_mapping:
port_mapping_0:
host_port: 8085
container_port: 80
"849ea5ba-9938-46aa-8d3d-d525f5d87102":
type: "Switch.nodes.Application.Connection"
properties:
latency: 20ms
bandwidth: 1Gb
target:
netmask: ""
component_name: "58ed77c3-8397-4e27-a4ab-0be0fee0569c"
port_name: "6f14898d-007d-419c-a41b-02099611f77f"
address: ""
source:
netmask: ""
component_name: "6be727ce-5fa1-4e6d-9a37-438d0ec94ff0"
port_name: "24ba657c-8a18-4c7f-aed9-9498d88a85d2"
address: ""
"8bffa661-cfa4-49df-ad83-7eba8498b405":
requirements:
- host:
node_filter:
capabilities:
host:
cpu_frequency: 3GHz
mem_size: 1GB
num_cpus: 2
disk_size: 1GB
os:
os_version: 16.04
distribution: ubuntu
type: linux
architecture: x86_64
type: "Switch.nodes.Application.Container.Docker.PEDRO.SANTOS_ProxyTranscoder"
properties:
scaling_mode: single
QoS:
packet_loss: 0
response_time: 30ms
out_ports:
"4bd7ba2b-6f49-4648-9c9c-cdd118e011f3":
type: out
port: " outPort "
multicastAddrPort: 3000
in_ports:
"2e50ce74-9396-4058-8402-997d196c9fd7":
type: in
port: " 1 "
multicastAddrIP: "225.2.2.0"
ports_mapping:
port_mapping_0:
host_port: 8081
container_port: 80
"58ed77c3-8397-4e27-a4ab-0be0fee0569c":
requirements:
- host:
node_filter:
capabilities:
host:
cpu_frequency: 3GHz
mem_size: 1GB
num_cpus: 2
disk_size: 1GB
os:
os_version: 16.04
distribution: ubuntu
type: linux
architecture: x86_64
type: "Switch.nodes.Application.Container.Docker.PEDRO.SANTOS_ProxyTranscoder"
properties:
scaling_mode: single
QoS:
packet_loss: 0
response_time: 30ms
out_ports:
"1e8c4827-5dcc-40c6-840b-f14f09f9ae28":
type: out
port: " outPort "
multicastAddrPort: 3000
in_ports:
"6f14898d-007d-419c-a41b-02099611f77f":
type: in
port: " 1 "
multicastAddrIP: "225.2.2.2"
ports_mapping:
port_mapping_0:
host_port: 8082
container_port: 80
"432dc3f6-4d1c-4092-a365-7837ef92279c":
requirements:
- host:
node_filter:
capabilities:
host:
cpu_frequency: 3GHz
mem_size: 1GB
num_cpus: 2
disk_size: 1GB
os:
os_version: 16.04
distribution: ubuntu
type: linux
architecture: x86_64
type: "Switch.nodes.Application.Container.Docker.PEDRO.SANTOS_OutputTranscoder.Cardiff"
properties:
OutIP: "192.168.1.194"
QoS:
packet_loss: 0
response_time: 30ms
out_ports:
"78fec7a2-e803-4e4a-b5e2-b0afcdb7d3f1":
type: out
port: " outPort "
scaling_mode: single
OutPort: 4000
in_ports:
"7c36b4c1-58e1-4011-b00f-7641e09b2e5a":
type: in
port: " 1 "
ports_mapping:
port_mapping_0:
host_port: "${OutPort}"
container_port: "${OutPort}"
videoWidth: 176
videoHeight: 100
artifact_types:
"tosca.artifacts.Deployment.Image.Container.Docker":
derived_from: "tosca.artifacts.Deployment.Image"
description: "MOG use case"
node_types:
"Switch.nodes.Application.Container.Docker.PEDRO.SANTOS.MOG_Input_Distributor":
properties:
Input_RTP_TS_Port:
default: 2000
type: string
Waiting_Time:
default: 5
type: string
Output_Uncompressed_Video_Multicast_Address:
default: "225.2.2.0"
type: string
Output_Uncompressed_Video_Multicast_Port:
default: "3000 waiting time Waiting time (in seconds) for Input Distributor to receive TS stream 5 switcherOutAddrIP Multicast IP address where Video Switcher"
type: string
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Container.Docker.PEDRO.SANTOS_ProxyTranscoder":
properties:
multicastAddrPort:
default: 3000
type: "Switch.datatypes.port"
multicastAddrIP:
default: "225.2.2.0"
type: "Switch.datatypes.Network.Multicast"
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Container.Docker.VLAD_THE_IMPALER_RTUSensorDataAcquisition":
properties:
name:
required: false
type: string
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Constraint":
requirements:
- monitor_server_endpoint:
node: "Switch.nodes.Application.Container.Docker.MonitoringServer"
capability: "tosca.capabilities.Node"
relationship: "tosca.relationships.DependsOn"
properties:
QoS:
type: "Switch.datatypes.QoS.AppComponent"
derived_from: "tosca.nodes.Root"
"Switch.nodes.Compute":
artifacts:
gateway_image:
type: "tosca.artifacts.Deployment.Image.Container.Docker"
repository: SWITCH_docker_hub
file: "/???"
derived_from: "tosca.nodes.Compute"
"Switch.nodes.Application.Container.Docker.PEDRO.SANTOS_InputDistributor":
properties:
inPort:
default: 2000
type: "Switch.datatypes.port"
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Container.Docker.BEIA_V1_RTUSensorDataAcquisitions":
derived_from: "Switch.nodes.Application.Container.Docker"
"tosca.groups.Root":
"Switch.nodes.Application.Container.Docker.PEDRO.SANTOS_InputDistributor.Cardiff":
properties:
multicastAddrPort:
default: 3000
type: "Switch.datatypes.port"
multicastAddrIP:
default: "225.2.2.0"
type: "Switch.datatypes.Network.Multicast"
inPort:
default: 2000
type: "Switch.datatypes.port"
waitingTime:
default: 5
type: integer
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Container.Docker.BEIA_Gateway":
properties:
Name:
default: BEIA_Gateway
type: string
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Container.Docker.BEIA_RTUSensorDataAcquisition":
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Requirement":
properties:
host:
type: "Switch.datatypes.hw.host"
os:
type: "Switch.datatypes.hw.os"
derived_from: "tosca.nodes.Root"
"Switch.nodes.Application.Container.Docker.BEIA_RTUSensorData":
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Container.Docker.MOG_InputDistributor":
properties:
waitingTime:
default: 5
type: integer
multicastAddrIP:
default: "255.2.2.0"
type: string
multicastAddrPort:
default: 3000
type: integer
videoWidth:
default: 170
type: integer
inPort:
default: 2000
type: integer
videoHeight:
default: 100
type: integer
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Connection":
properties:
source:
type: "Switch.datatypes.Application.Connection.EndPoint"
bandwidth:
type: integer
multicast:
type: "Switch.datatypes.Network.Multicast"
jitter:
required: false
type: integer
target:
type: "Switch.datatypes.Application.Connection.EndPoint"
latency:
required: false
type: integer
QoS:
type: "Switch.datatypes.QoS.AppComponent"
derived_from: "tosca.nodes.Root"
"Switch.nodes.Application.Container.Docker":
properties:
in_ports:
entry_schema:
type: "Switch.datatypes.port"
required: false
type: map
dockers:
required: false
type: string
QoS:
required: false
type: "Switch.datatypes.QoS.AppComponent"
name:
required: false
type: string
out_ports:
entry_schema:
type: "Switch.datatypes.port"
required: false
type: map
ports_mapping:
entry_schema:
type: "Switch.datatypes.port_mapping"
type: map
scaling_mode:
required: false
type: string
ethernet_port:
entry_schema:
type: "Switch.datatypes.ethernet_port"
required: false
type: list
derived_from: "tosca.nodes.Container.Application"
"Switch.nodes.Application.Container.Docker.BEIA_V1_RTUSensorDataAcquisition":
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.ExternalComponent":
derived_from: "tosca.nodes.Root"
"Switch.nodes.Application.Container.Docker.PEDRO.SANTOS.MOG_Switcher":
properties:
Input_A_Uncompressed_Video_Multicast_Address:
default: "225.2.2.0"
type: string
Input_Video_Width:
default: 176
type: string
Input_B_Uncompressed_Video_Multicast_Port:
default: 3002
type: string
Input_B_Uncompressed_Video_Multicast_Address:
default: "225.2.2.1"
type: string
port:
default: 23
type: integer
Output_Uncompressed_Video_Multicast_Address:
default: "226.2.2.2"
type: string
Output_REST_PORT:
default: 8008
type: string
Output_Uncompressed_Video_Multicast_Port:
default: 6000
type: string
Input_Video_Height:
default: 100
type: string
Input_A_Uncompressed_Video_Multicast_Port:
default: 3000
type: string
Waiting_Time:
default: 5
type: string
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.DST":
properties:
dave:
type: string
derived_from: "tosca.nodes.Root"
"Switch.nodes.Application.Container.Docker.BEIA_V1_NotificationServer":
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Container.Docker.LOKSORR_Bb":
properties:
bb:
type: string
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Container.Docker.BEIA_RTUSensorDataManagement":
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Container.Docker.BEIA_NotificationServer":
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Component":
derived_from: "tosca.nodes.Root"
"Switch.nodes.Network":
derived_from: "tosca.nodes.network.Network"
"Switch.nodes.Application.Container.Docker.PEDRO.SANTOS_Input":
properties:
port2:
default: 24
type: integer
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Container.Docker.BEIA_V1_Monitoring":
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Container.Docker.UL_JitsiMeet_docker":
properties:
ips:
type: string
deploy:
type: string
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Container.Docker.BEIA_Acquisition":
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Container.Docker.BEIA_DB":
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.Application.Container.Docker.BEIA_V1_DatabaseServer":
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.VirtualNetwork":
artifacts:
"switcher.cardiff_image":
type: "tosca.artifacts.Deployment.Image.Container.Docker"
repository: SWITCH_docker_hub
file: null
properties:
subnet:
default: "192.168.10.0"
type: string
netmask:
default: "255.255.255.0"
type: string
name:
type: string
derived_from: "tosca.nodes.Root"
"Switch.nodes.Application.Container.Docker.PEDRO.SANTOS_Switcher.Cardiff":
properties:
waitingTime:
default: 5
type: integer
multicastAddrIP:
default: "225.2.2.0"
type: "Switch.datatypes.Network.Multicast"
switcherREST:
default: switcherREST
type: "Switch.datatypes.port"
switcherOutAddrPort:
default: 6000
type: "Switch.datatypes.port"
multicastAddrIP2:
default: "225.2.2.2"
type: "Switch.datatypes.Network.Multicast"
switcherOutAddrIP:
default: "226.2.2.2"
type: "Switch.datatypes.Network.Multicast"
multicastAddrPort:
default: 3000
type: "Switch.datatypes.port"
videoWidth:
default: 176
type: integer
multicastAddrPort2:
default: 3002
type: "Switch.datatypes.port"
videoHeight:
default: 100
type: integer
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.EventListener":
derived_from: "tosca.nodes.Root"
"Switch.nodes.MonitoringAgent":
properties:
agent_id:
default: null
type: string
probes:
entry_schema:
type: "Switch.datatypes.monitoring.probe"
type: map
derived_from: "tosca.nodes.Root"
"Switch.nodes.Application.Container.Docker.BEIA_V1_TelemetryGateway":
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.AdaptationPolicy":
derived_from: "tosca.nodes.Root"
"Switch.nodes.Application.Container.Docker.MonitoringServer":
properties:
ports_mapping:
entry_schema:
type: "Switch.datatypes.port_mapping"
type: map
derived_from: "Switch.nodes.Application.Container.Docker"
"Switch.nodes.MessagePasser":
derived_from: "tosca.nodes.Root"
"Switch.nodes.Application.Container.Docker.PEDRO.SANTOS_OutputTranscoder.Cardiff":
properties:
OutIP:
default: "192.168.1.194"
type: "Switch.datatypes.Network.Multicast"
videoWidth:
default: 176
type: integer
OutPort:
default: 4000
type: "Switch.datatypes.port"
videoHeight:
default: 100
type: integer
derived_from: "Switch.nodes.Application.Container.Docker"
repositories:
SWITCH_docker_hub:
url: "https://github.com/switch-project"
credential:
token_type: "X-Auth-Token"
token: 604bbe45ac7143a79e14f3158df67091
protocol: xauth
description: "switch repository in GitHub"
data_types:
"Switch.datatypes.monitoring.metric.threshold":
properties:
operator:
type: string
value:
type: integer
derived_from: "tosca.datatypes.Root"
"Switch.datatypes.port":
properties:
type:
type: string
port:
type: string
derived_from: "tosca.datatypes.Root"
"Switch.datatypes.Application.Connection.EndPoint":
properties:
netmask:
type: string
component_name:
type: string
port_name:
type: string
address:
type: string
derived_from: "tosca.datatypes.Root"
"Switch.datatypes.monitoring.probe":
properties:
active:
type: boolean
path:
required: false
type: string
static:
type: boolean
name:
type: string
metrics:
entry_schema:
type: "Switch.datatypes.monitoring.metric"
type: map
derived_from: "tosca.datatypes.Root"
"Switch.datatypes.hw.host":
properties:
cpu_frequency:
type: float
mem_size:
type: integer
num_cpus:
type: integer
disk_size:
type: integer
derived_from: "tosca.datatypes.Root"
"Switch.datatypes.ethernet_port":
properties:
subnet_name:
type: string
name:
type: string
address:
type: string
derived_from: "tosca.datatypes.Root"
"Switch.datatypes.hw.os":
properties:
os_version:
type: string
distribution:
type: string
type:
type: string
architecture:
type: string
derived_from: "tosca.datatypes.Root"
"Switch.datatypes.QoS.AppComponent":
properties:
response_time:
type: integer
derived_from: "tosca.datatypes.Root"
"Switch.datatypes.Application.Connection.Multicast":
properties:
multicastAddrPort:
type: string
multicastAddrIP:
type: string
derived_from: "tosca.datatypes.Root"
"Switch.datatypes.Network.Multicast":
properties:
multicastAddrPort:
type: string
multicastAddrIP:
type: string
derived_from: "tosca.datatypes.Root"
"Switch.datatypes.port_mapping":
properties:
host_port:
type: integer
container_port:
type: integer
derived_from: "tosca.datatypes.Root"
"Switch.datatypes.monitoring.metric":
properties:
thresholds:
entry_schema:
type: "Switch.datatypes.monitoring.metric.threshold"
required: false
type: map
type:
type: string
name:
type: string
unit:
required: false
type: string
derived_from: "tosca.datatypes.Root"
tosca_definitions_version: tosca_simple_yaml_1_0
\ No newline at end of file
...@@ -10,6 +10,7 @@ import tempfile ...@@ -10,6 +10,7 @@ import tempfile
import time import time
import json import json
from transformer.docker_compose_transformer import * from transformer.docker_compose_transformer import *
from os.path import expanduser
...@@ -69,12 +70,14 @@ def handle_delivery(message): ...@@ -69,12 +70,14 @@ def handle_delivery(message):
return "response" return "response"
if __name__ == "__main__": if __name__ == "__main__":
print sys.argv home = expanduser("~")
channel = init_chanel(sys.argv) transformer = DockerComposeTransformer(home+"/workspace/DRIP/docs/input_tosca_files/MOG_cardif.yml")
global queue_name transformer.getnerate_compose()
queue_name = sys.argv[2] # print sys.argv
# channel = init_chanel(sys.argv)
start(channel) # global queue_name
# queue_name = sys.argv[2]
# start(channel)
# try: # try:
## for node in tosca.nodetemplates: ## for node in tosca.nodetemplates:
## print "Name %s Type: %s " %(node.name,node.type) ## print "Name %s Type: %s " %(node.name,node.type)
......
...@@ -6,55 +6,104 @@ import toscaparser.utils.yamlparser ...@@ -6,55 +6,104 @@ import toscaparser.utils.yamlparser
class DockerComposeTransformer: class DockerComposeTransformer:
def __init__(self, tosca_file_path): def __init__(self, tosca_file_path):
yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(tosca_file_path) self.yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(tosca_file_path)
self.tt = ToscaTemplate(path=None, yaml_dict_tpl=yaml_dict_tpl) self.errors =[]
self.wornings = []
self.tt = None
try:
self.tt = ToscaTemplate(path=None, yaml_dict_tpl=self.yaml_dict_tpl)
except:
self.wornings.append("Not a valid tosca file")
self.DOCKER_TYPE = 'Switch.nodes.Application.Container.Docker' self.DOCKER_TYPE = 'Switch.nodes.Application.Container.Docker'
def getnerate_compose(self): def getnerate_compose(self):
if self.tt:
analize_tosca()
else:
self.analyze_yaml()
def analyze_yaml(self):
node_types = self.yaml_dict_tpl['node_types']
docker_types = []
for node_type_key in node_types:
if node_types[node_type_key] and 'derived_from' in node_types[node_type_key].keys():
if node_types[node_type_key]['derived_from'] == self.DOCKER_TYPE:
docker_types.append(node_type_key)
node_templates = self.yaml_dict_tpl['topology_template']['node_templates']
services = {}
for node_template_key in node_templates:
# print node_templates[node_template_key]
for docker_type in docker_types:
if docker_type in node_templates[node_template_key]['type']:
if 'artifacts' in node_templates[node_template_key]:
artifacts = node_templates[node_template_key]['artifacts']
key = next(iter(artifacts))
docker_file = artifacts[key]['file']
services['name'] = docker_file
services['image'] = docker_file
services['id'] = node_template_key
if 'properties' in node_templates[node_template_key]:
properties = node_templates[node_template_key]['properties']
environment = []
for prop in properties:
if not isinstance(properties[prop],dict):
environment.append(prop+"="+str(properties[prop]))
services['environment'] = environment
if 'ports_mapping' in properties:
ports_mappings = properties['ports_mapping']
key = next(iter(ports_mappings))
host_port = ports_mappings[key]['host_port']
if not isinstance(host_port, (int, long, float, complex)):
host_port_var = host_port.replace('${','').replace('}','')
host_port = properties[host_port_var]
container_port = ports_mappings[key]['container_port']
if not isinstance(container_port, (int, long, float, complex)):
container_port_var = container_port.replace('${','').replace('}','')
container_port = properties[container_port_var]
ports = []
ports.append(str(host_port)+':'+str(container_port))
services['ports'] = ports
print services
def analize_tosca():
dockers = [] dockers = []
print dir(self.tt.topology_template) # print dir(self.tt.topology_template)
print dir(self.tt.outputs) # print dir(self.tt.outputs)
print dir(self.tt.nested_tosca_tpls_with_topology) # print dir(self.tt.nested_tosca_tpls_with_topology)
print dir(self.tt.nested_tosca_templates_with_topology) # print dir(self.tt.nested_tosca_templates_with_topology)
print dir(self.tt.inputs) # print dir(self.tt.inputs)
print dir(self.tt.input_path) # print dir(self.tt.input_path)
print dir(self.tt.graph) # print dir(self.tt.graph)
for node in self.tt.nodetemplates: for node in self.tt.nodetemplates:
if node.parent_type.type == self.DOCKER_TYPE: if node.parent_type.type == self.DOCKER_TYPE:
dockers.append(node) # dockers.append(node)
print "Name %s Type: %s Parent: %s" %(node.name,node.type,node.parent_type.type) # print dir(node)
print "Name %s Type: %s" %(node.name,node.type)
service = {}
service['name'] = node.type
# print dir(node.get_properties_objects())
# topology_template = parsed_json_value['topology_template'] # for prop_obj in node.get_properties_objects():
# node_templates = topology_template["node_templates"] # print dir(prop_obj)
# # print "Name %s Type: %s Val: %s" %(prop_obj.name,prop_obj.type,prop_obj.value)
# response = {} # print (node.templates.keys())
# current_milli_time = lambda: int(round(time.time() * 1000)) docker_file = ""
# response["creationDate"] = current_milli_time() for temp in node.templates:
# response["parameters"] = [] print "\t template: %s" %(temp)
# if 'artifacts' in node.templates[temp]:
# for nodes in node_templates: key = next(iter(node.templates[temp]['artifacts']))
# if "Switch.nodes.Application.Container.Docker." in node_templates[nodes]['type']: if 'file' in node.templates[temp]['artifacts'][key]:
# node_keys = node_templates[nodes].keys() docker_file = node.templates[temp]['artifacts'][key]['file']
# if 'artifacts' in node_keys: print "\t\tdocker_file: %s"%(docker_file)
# artifact_key = next(iter(node_templates[nodes]['artifacts']))
# artifact_keys = node_templates[nodes]['artifacts'][artifact_key].keys() if docker_file:
# if 'file' in artifact_keys: container_name = docker_file.split("/")[1]
# docker = node_templates[nodes]['artifacts'][artifact_key]['file'] if ':' in container_name:
# elif 'docker_image' in artifact_keys: container_name = container_name.split(':')[0]
# docker = node_templates[nodes]['artifacts']['docker_image']['file'] # print container_name
# result = {} service ['container_name'] = container_name
# parameter = {} # print "Name %s Type: %s Val: %s" %(prop_obj.name,prop_obj.type,prop_obj.value)
# result['name'] = nodes # service ['container_name'] =
# result['size'] = 'Medium'
# result['docker'] = docker
# parameter['value'] = str(json.dumps(result))
# parameter['attributes'] = 'null'
# parameter["url"] = "null"
# parameter["encoding"] = "UTF-8"
# response["parameters"].append(parameter)
# print ("Output message: %s" % json.dumps(response))
# return json.dumps(response)
\ 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