Skip to content
Snippets Groups Projects
Commit 5a654fed authored by debora.benedetto@hpe.com's avatar debora.benedetto@hpe.com
Browse files
parents fd5ed27d 09defd3a
No related branches found
No related tags found
No related merge requests found
.idea
*.tar.gz
icgparser/doml/*domlx
output_files_example/*
output_files_*
\ No newline at end of file
.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__/
......
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")
......
......@@ -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>
......
......@@ -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"
......
......@@ -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")
......
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}")
......
......@@ -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
......
[{{ "servers_for_" ~ name }}]
instance_ip_{{ node.vm_name }}
{% raw %}{{ instance_ip_{% endraw %}{{ node.vm_name }} {% raw %}}}{% endraw %}
[{{ "servers_for_" ~ name }}:vars]
ansible_connection=ssh
......
# Create ssh keys
resource "openstack_compute_keypair_v2" "{{ infra_element_name }}" {
name = "{{ user }}"
# public_key = "{{ user }}"
}
\ No newline at end of file
......@@ -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"
......
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 }}" {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment