diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..3cc515f3180b1550bff02a2a42879e5ff8eeaed3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.idea +*.tar.gz +icgparser/doml/*domlx +output_files_example/* +output_files_* \ No newline at end of file diff --git a/.gitignore b/.gitignore index eb26650f87babce819c1f2dc67e5951b26e85f38..e51cffd218b5c8e033b772620e1ea7203613f0e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ .idea *.tar.gz icgparser/doml/*domlx -output_files_generated/nginx_openstack/terraform/* -output_files_generated/nginx_openstack/ansible/* +output_files_generated/* # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/controller/Orchestrator.py b/controller/Orchestrator.py index 29af7c8d74636e1378a9e841a66edc12a922916c..07978363c7d083bc23c15dbd78feab70d9036cf0 100644 --- a/controller/Orchestrator.py +++ b/controller/Orchestrator.py @@ -1,5 +1,6 @@ import json import logging +import os import tarfile import time import uuid @@ -48,6 +49,7 @@ def choose_plugin(parameters, template_generated_folder): def save_file(data, file_path, output_extensions="json"): logging.debug(f"Saving data: {data} at {file_path}") logging.info(f"Saving data at: {file_path}") + os.makedirs(os.path.dirname(file_path), exist_ok=True) file = open(file_path, "w") if isinstance(data, dict) and output_extensions == "YAML": logging.info("Converting python dict into yaml data") diff --git a/icgparser/doml/v1/nginx-openstack_v1.domlx b/icgparser/doml/v1/nginx-openstack_v1.domlx index e10fe0e6891f622a91b3b530fe9f82aa4e7e6d03..1b352ff3b631d2a21a9b4d9570f882b60b02a261 100644 --- a/icgparser/doml/v1/nginx-openstack_v1.domlx +++ b/icgparser/doml/v1/nginx-openstack_v1.domlx @@ -7,13 +7,12 @@ </application> <infrastructure name="infra"> <nodes xsi:type="infra:AutoScalingGroup" name="ag" deploymentNetwork="//@infrastructure/@networks.0"> - <machineDefinition name="vm1" os="ubuntu-20.04.3" credentials="//@infrastructure/@credentials.0" group="//@infrastructure/@groups.0" generatedFrom="//@infrastructure/@generators.0"> + <machineDefinition name="vm1" os="Ubuntu-Focal-20.04-Daily-2022-04-19" credentials="//@infrastructure/@credentials.0" group="//@infrastructure/@groups.0"> <ifaces name="i1" endPoint="16.0.0.1" belongsTo="//@infrastructure/@networks.0" associated="//@infrastructure/@groups.0"/> </machineDefinition> </nodes> <networks name="net1" protocol="tcp/ip" addressRange="16.0.0.0/24" connectedIfaces="//@infrastructure/@nodes.0/@machineDefinition/@ifaces.0"/> - <generators xsi:type="infra:VMImage" name="v_img" generatedVMs="//@infrastructure/@nodes.0/@machineDefinition"/> - <credentials xsi:type="infra:KeyPair" name="ssh_key" user="ubuntu" keyfile="/home/user1/.ssh/openstack.key" algorithm="RSA" bits="4096"/> + <credentials xsi:type="infra:KeyPair" name="ssh_key" user="ubuntu"/> <groups xsi:type="infra:SecurityGroup" name="sg" groupedNodes="//@infrastructure/@nodes.0/@machineDefinition" ifaces="//@infrastructure/@nodes.0/@machineDefinition/@ifaces.0"> <rules name="icmp" protocol="icmp" fromPort="-1" toPort="-1"> <cidr>0.0.0.0/0</cidr> @@ -34,11 +33,7 @@ <vms name="concrete_vm" maps="//@infrastructure/@nodes.0/@machineDefinition"> <annotations xsi:type="commons:SProperty" key="vm_name" value="nginx-host"/> <annotations xsi:type="commons:SProperty" key="vm_flavor" value="small"/> - <annotations xsi:type="commons:SProperty" key="vm_key_name" value="user1"/> </vms> - <vmImages name="concrete_vm_image" maps="//@infrastructure/@generators.0"> - <annotations xsi:type="commons:SProperty" key="name" value="ubuntu-20.04.3"/> - </vmImages> <networks name="concrete_net" maps="//@infrastructure/@networks.0"> <annotations xsi:type="commons:SProperty" key="name" value="ostack2"/> </networks> diff --git a/input_file_generated/ir.json b/input_file_generated/ir.json index d5cd04e6a65f89bd5e63e1606e537b5bbc5187d7..da327c87fed30ec8ed80fc98faa55b25629b2a2d 100644 --- a/input_file_generated/ir.json +++ b/input_file_generated/ir.json @@ -50,10 +50,7 @@ ], "credentials": [ { - "algorithm": "RSA", - "bits": 4096, "infra_element_name": "ssh_key", - "keyfile": "/home/user1/.ssh/openstack.key", "user": "ubuntu" } ], @@ -66,17 +63,9 @@ } ], "provider": "openstack", - "vmImages": [ - { - "infra_element_name": "v_img", - "kind": "SCRIPT", - "name": "concrete_vm_image" - } - ], "vms": [ { "credentials": "ssh_key", - "generatedFrom": "v_img", "group": "sg", "i1": { "associated": "sg", @@ -86,9 +75,8 @@ }, "infra_element_name": "vm1", "name": "concrete_vm", - "os": "ubuntu-20.04.3", + "os": "Ubuntu-Focal-20.04-Daily-2022-04-19", "vm_flavor": "small", - "vm_key_name": "user1", "vm_name": "nginx-host" } ] @@ -101,7 +89,6 @@ "name": "nginx", "node": { "credentials": "ssh_key", - "generatedFrom": "v_img", "group": "sg", "i1": { "associated": "sg", @@ -111,9 +98,8 @@ }, "infra_element_name": "vm1", "name": "concrete_vm", - "os": "ubuntu-20.04.3", + "os": "Ubuntu-Focal-20.04-Daily-2022-04-19", "vm_flavor": "small", - "vm_key_name": "user1", "vm_name": "nginx-host" }, "source_code": "/usr/share/nginx/html/index.html" diff --git a/plugin/AnsiblePlugin.py b/plugin/AnsiblePlugin.py index 12daa4546d26bb6d61553e3c28aace8164ca36b0..1ff4b39d40e197d018e8faea9679cf108a0c6b41 100644 --- a/plugin/AnsiblePlugin.py +++ b/plugin/AnsiblePlugin.py @@ -4,7 +4,9 @@ from plugin.PluginException import PluginResourceNotFoundError def clean_operating_system_name(operating_system): - if "ubuntu" in operating_system: + operating_system_lower_case = operating_system.lower() + logging.info(f"AnsiblePlugin: extracting operating system from {operating_system}") + if "ubuntu" in operating_system_lower_case: return "ubuntu" else: raise PluginResourceNotFoundError(plugin_name="AnsiblePlugin", resource_name="operating system") diff --git a/plugin/TerraformPlugin.py b/plugin/TerraformPlugin.py index ef165cee4c9dc8bfe679fac968729fe120a23c95..ba5ec0079ac9167a2fff816f6288ed232ed4ec84 100644 --- a/plugin/TerraformPlugin.py +++ b/plugin/TerraformPlugin.py @@ -1,7 +1,14 @@ import logging +from distutils.dir_util import copy_tree + from plugin import TemplateUtils, PluginUtility +def store_monitoring_agents_folder(output_path): + logging.info(f"Adding monitoring agents folder in {output_path}") + copy_tree("templates/terraform/open_stack/agents_playbook", output_path) + + def create_files(parameters, output_path): language = "terraform" provider = parameters["provider"] @@ -36,6 +43,7 @@ def create_files(parameters, output_path): TemplateUtils.write_template(terraform_out_file, output_file_stored_path) config_file_stored_path = output_path + "/config.yaml" TemplateUtils.write_template(config_file, config_file_stored_path) + store_monitoring_agents_folder(output_path) logging.info("Terraform main file available at: {}".format(main_file_stored_path)) logging.info(f"Terraform output file available at {output_file_stored_path}") diff --git a/template-location.properties b/template-location.properties index abe02063bb68ba3860d633f6685d5cf6da33bd92..1506dfa9d1c1cc0e54e8942b22c207a5b004cae6 100644 --- a/template-location.properties +++ b/template-location.properties @@ -5,6 +5,7 @@ vms = templates/terraform/open_stack/virtual_machine.tpl vms_out = templates/terraform/open_stack/virtual_machine_out.tpl networks = templates/terraform/open_stack/network.tpl computingGroup = templates/terraform/open_stack/port_rule.tpl +credentials = templates/terraform/open_stack/ssh_key.tpl [terraform.azure] init = templates/terraform/azure/init.tpl diff --git a/templates/ansible/ubuntu/inventory.tpl b/templates/ansible/ubuntu/inventory.tpl index b82f86332dafcc4bcc65c3a2bb64256010a3eb6f..acec5a89685f5c002e41118258a62e140b2eb5ec 100644 --- a/templates/ansible/ubuntu/inventory.tpl +++ b/templates/ansible/ubuntu/inventory.tpl @@ -1,5 +1,5 @@ [{{ "servers_for_" ~ name }}] -instance_ip_{{ node.vm_name }} +{% raw %}{{ instance_ip_{% endraw %}{{ node.vm_name }} {% raw %}}}{% endraw %} [{{ "servers_for_" ~ name }}:vars] ansible_connection=ssh diff --git a/templates/terraform/open_stack/ssh_key.tpl b/templates/terraform/open_stack/ssh_key.tpl new file mode 100644 index 0000000000000000000000000000000000000000..b4362178deb60feaa89ad8aa9a57a3d4382a255e --- /dev/null +++ b/templates/terraform/open_stack/ssh_key.tpl @@ -0,0 +1,5 @@ +# Create ssh keys +resource "openstack_compute_keypair_v2" "{{ infra_element_name }}" { + name = "{{ user }}" + # public_key = "{{ user }}" +} \ No newline at end of file diff --git a/templates/terraform/open_stack/virtual_machine.tpl b/templates/terraform/open_stack/virtual_machine.tpl index 218d0f14e77165da00d82be5bf820da22cf85846..c283198470d544418c32607932c1dff0867c1f7f 100644 --- a/templates/terraform/open_stack/virtual_machine.tpl +++ b/templates/terraform/open_stack/virtual_machine.tpl @@ -3,7 +3,7 @@ resource "openstack_compute_instance_v2" "{{ infra_element_name }}" { name = "{{ vm_name }}" image_name = "{{ os }}" flavor_name = "{{ vm_flavor }}" - key_pair = openstack_compute_keypair_v2.{{ vm_key_name }}.name + key_pair = openstack_compute_keypair_v2.{{ credentials }}.name network { port = openstack_networking_port_v2.{{ i1.belongsTo }}.id } @@ -26,12 +26,6 @@ resource "openstack_compute_instance_v2" "{{ infra_element_name }}" { } -# Create ssh keys -resource "openstack_compute_keypair_v2" "{{ vm_key_name }}" { - name = "{{ vm_key_name }}" - # public_key = "{{ ssh_key_file }}" -} - # Create floating ip resource "openstack_networking_floatingip_v2" "{{infra_element_name ~ "_floating_ip"}}" { pool = "external" diff --git a/templates/terraform/open_stack/virtual_machine_out.tpl b/templates/terraform/open_stack/virtual_machine_out.tpl index e39fa9fbbcafa9fc0aa0e93f017fe6aafbc9e5f2..67de692d23e2e4aa6215cc85e6b1d20df344b09a 100644 --- a/templates/terraform/open_stack/virtual_machine_out.tpl +++ b/templates/terraform/open_stack/virtual_machine_out.tpl @@ -1,9 +1,9 @@ output "instance_server_public_key_{{ vm_key_name }}" { - value = openstack_compute_keypair_v2.{{ vm_key_name }}.public_key + value = openstack_compute_keypair_v2.{{ credentials }}.public_key } output "instance_server_private_key_{{ vm_key_name }}" { - value = openstack_compute_keypair_v2.{{ vm_key_name }}.private_key + value = openstack_compute_keypair_v2.{{ credentials }}.private_key } output "instance_ip_{{ vm_name }}" {