Commit 6c4561c2 authored by Spiros Koulouzis's avatar Spiros Koulouzis

try to start ansible task

parent 1b7baef7
......@@ -36,7 +36,7 @@ topology_template:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/k8s_dashboard.yaml"
create:
inputs:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/k8s_install.yml"
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/install_k8s.yaml"
delete:
inputs:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/k8s_delete.yaml"
......
......@@ -36,7 +36,7 @@ topology_template:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/k8s_dashboard.yaml"
create:
inputs:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/k8s_install.yml"
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/install_k8s.yaml"
delete:
inputs:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/k8s_delete.yaml"
......
......@@ -66,7 +66,7 @@ topology_template:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/k8s_dashboard.yaml"
create:
inputs:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/k8s_install.yml"
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/install_k8s.yaml"
delete:
inputs:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/k8s_delete.yaml"
......
......@@ -9,7 +9,7 @@ topology_template:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/k8s_dashboard.yaml"
create:
inputs:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/k8s_install.yml"
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/install_k8s.yaml"
delete:
inputs:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/k8s_delete.yaml"
......
......@@ -135,7 +135,7 @@ node_types:
create:
inputs:
repository: https://github.com/skoulouzis/playbooks.git
playbook: k8s_install.yml
playbook: install_k8s.yaml
configure:
inputs:
repository: https://github.com/skoulouzis/playbooks.git
......
......@@ -5,7 +5,7 @@ requests==2.23.0
wheel==0.34.2
pyyaml==5.3.1
matplotlib==3.2.1
# ansible==2.9.6
certifi==2019.11.28
six==1.14.0
python_dateutil==2.8.1
......
import base64
import logging
import os
from time import sleep
import yaml
from service.semaphore_helper import SemaphoreHelper
yaml.Dumper.ignore_aliases = lambda *args : True
logger = logging.getLogger(__name__)
if not getattr(logger, 'handler_set', None):
......@@ -30,14 +32,14 @@ class AnsibleService:
orchestartor = nodes_pair[1]
desired_state = None
interfaces = orchestartor.node_template.interfaces
if 'current_state' in orchestartor.attributes:
current_state = orchestartor.attributes['current_state']
if 'desired_state' in orchestartor.attributes:
desired_state = orchestartor.attributes['desired_state']
if 'current_state' in orchestartor.node_template.attributes:
current_state = orchestartor.node_template.attributes['current_state']
if 'desired_state' in orchestartor.node_template.attributes:
desired_state = orchestartor.node_template.attributes['desired_state']
if desired_state:
project_id = self.semaphore_helper.create_project(orchestartor.name)
inventory_contents = self.build_yml_inventory(vms)
inventory_contents = yaml.dump( self.build_yml_inventory(vms),default_flow_style=False)
private_key = self.get_private_key(vms)
key_id = self.semaphore_helper.create_ssh_key(orchestartor.name, project_id, private_key)
inventory_id = self.semaphore_helper.create_inventory(orchestartor.name, project_id, key_id,inventory_contents)
......@@ -48,16 +50,49 @@ class AnsibleService:
git_url = inputs['repository']
playbook_name = inputs['playbook']
# repository_id = self.semaphore_helper.create_repository(orchestartor.name, project_id, key_id, git_url)
# template_id = self.semaphore_helper.create_template(project_id, key_id, inventory_id, repository_id, playbook_name)
# task_id = self.semaphore_helper.execute_task(project_id, template_id, playbook_name)
repository_id = self.semaphore_helper.create_repository(orchestartor.name, project_id, key_id, git_url)
template_id = self.semaphore_helper.create_template(project_id, key_id, inventory_id, repository_id, playbook_name)
task_id = self.semaphore_helper.execute_task(project_id, template_id, playbook_name)
for x in range(0, 3):
task = self.semaphore_helper.get_task(project_id,task_id)
print(task)
sleep(0.5)
pass
def get_path(self,file_name):
tosca_path = "../../../ansible_playbooks"
input_tosca_file_path = tosca_path + '/' + file_name
if not os.path.exists(input_tosca_file_path):
tosca_path = "../../ansible_playbooks"
input_tosca_file_path = tosca_path + '/' + file_name
return input_tosca_file_path
def build_yml_inventory(self, vms):
# loader = DataLoader()
# inventory = InventoryManager(loader=loader)
# variable_manager = VariableManager()
# with open(r'/home/alogo/Downloads/inventory.yaml') as file:
# # The FullLoader parameter handles the conversion from YAML
# # scalar values to Python the dictionary format
# data = yaml.load(file)
inventory = {}
all = {}
vars = {'ansible_ssh_common_args':'-o StrictHostKeyChecking=no'}
vars['ansible_ssh_user'] = vms[0].node_template.properties['user_name']
children = {}
for vm in vms:
attributes = vm.node_template.attributes
role = attributes['role']
public_ip = attributes['public_ip']
if role not in children:
hosts = {}
else:
hosts = children[role]
hosts[public_ip] = vars
children[role] = hosts
# inventory.add_group(role)
# inventory.add_host(public_ip,group=role)
all['children'] = children
inventory['all'] = all
return inventory
def get_private_key(self, vms):
private_key = vms[0].node_template.attributes['user_key_pair']['keys']['private_key']
return base64.b64decode(private_key).decode('utf-8').replace(r'\n', '\n')
......@@ -96,3 +96,6 @@ class SemaphoreHelper:
self.project_api.project_project_id_tasks_post(project_id, task)
tasks = self.project_api.project_project_id_tasks_get(project_id)
return tasks[len(tasks) - 1].id
def get_task(self,project_id,task_id):
return self.project_api.project_project_id_tasks_task_id_get(project_id,task_id)
{"toscaTemplate": {"description": "TOSCA example", "imports": [{"nodes": "https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/nodes.yaml"}, {"data": "https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/data.yml"}, {"capabilities": "https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/capabilities.yaml"}, {"policies": "https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/policies.yaml"}, {"interfaces": "https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/interfaces.yml"}], "tosca_definitions_version": "tosca_simple_yaml_1_0", "topology_template": {"node_templates": {"compute": {"interfaces": {"Standard": {"create": "dumy.yaml"}}, "properties": {"disk_size": "10000 MB", "mem_size": "1000 MB", "num_cores": 1, "os": "Ubuntu 18.04", "user_name": "vm_user"}, "type": "tosca.nodes.ARTICONF.VM.Compute"}, "compute_1": {"interfaces": {"Standard": {"create": "dumy.yaml"}}, "properties": {"disk_size": "10000 MB", "mem_size": "1000 MB", "num_cores": 1, "os": "Ubuntu 18.04", "user_name": "vm_user"}, "type": "tosca.nodes.ARTICONF.VM.Compute"}, "kubernetes": {"interfaces": {"Standard": {"configure": {"inputs": {"playbook": "k8s_dashboard.yaml", "repository": "https://github.com/skoulouzis/playbooks.git"}}, "create": {"inputs": {"playbook": "k8s_install.yml", "repository": "https://github.com/skoulouzis/playbooks.git"}}, "delete": {"inputs": {"playbook": "k8s_delete.yaml", "repository": "https://github.com/skoulouzis/playbooks.git"}}}}, "requirements": [{"host": {"capability": "tosca.capabilities.ARTICONF.VM.topology", "node": "topology", "relationship": "tosca.relationships.HostedOn"}}], "type": "tosca.nodes.ARTICONF.docker.Orchestrator.Kubernetes"}, "topology": {"artifacts": {"provisioned_files": {"required": false, "type": "string"}}, "interfaces": {"CloudsStorm": {"delete": {"inputs": {"code_type": "SEQ", "object_type": "SubTopology"}}, "hscale": {"inputs": {"code_type": "SEQ", "object_type": "SubTopology"}}, "provision": {"inputs": {"code_type": "SEQ", "object_type": "SubTopology"}}, "start": {"inputs": {"code_type": "SEQ", "object_type": "SubTopology"}}, "stop": {"inputs": {"code_type": "SEQ", "object_type": "SubTopology"}}}}, "properties": {"domain": "Frankfurt", "provider": "EC2"}, "requirements": [{"vm": {"capability": "tosca.capabilities.ARTICONF.VM", "node": "compute", "relationship": "tosca.relationships.DependsOn"}}, {"vm": {"capability": "tosca.capabilities.ARTICONF.VM", "node": "compute_1", "relationship": "tosca.relationships.DependsOn"}}], "type": "tosca.nodes.ARTICONF.VM.topology"}, "ws-pema": {"artifacts": {"image": {"file": "alogo53/ws-pema-lifewatch", "repository": "docker_hub", "type": "tosca.artifacts.Deployment.Image.Container.Docker"}}, "properties": {"ports": ["30001:8080"]}, "requirements": [{"host": {"capability": "tosca.capabilities.ARTICONF.docker.Orchestrator", "node": "kubernetes", "relationship": "tosca.relationships.HostedOn"}}], "type": "tosca.nodes.ARTICONF.Container.Application.Docker"}}}}, "creationDate": 1585660828105}
{"toscaTemplate": {"description": "TOSCA example", "imports": [{"nodes": "https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/nodes.yaml"}, {"data": "https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/data.yml"}, {"capabilities": "https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/capabilities.yaml"}, {"policies": "https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/policies.yaml"}, {"interfaces": "https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/interfaces.yml"}], "tosca_definitions_version": "tosca_simple_yaml_1_0", "topology_template": {"node_templates": {"compute": {"interfaces": {"Standard": {"create": "dumy.yaml"}}, "properties": {"disk_size": "10000 MB", "mem_size": "1000 MB", "num_cores": 1, "os": "Ubuntu 18.04", "user_name": "vm_user"}, "type": "tosca.nodes.ARTICONF.VM.Compute"}, "compute_1": {"interfaces": {"Standard": {"create": "dumy.yaml"}}, "properties": {"disk_size": "10000 MB", "mem_size": "1000 MB", "num_cores": 1, "os": "Ubuntu 18.04", "user_name": "vm_user"}, "type": "tosca.nodes.ARTICONF.VM.Compute"}, "kubernetes": {"interfaces": {"Standard": {"configure": {"inputs": {"playbook": "k8s_dashboard.yaml", "repository": "https://github.com/skoulouzis/playbooks.git"}}, "create": {"inputs": {"playbook": "install_k8s.yaml", "repository": "https://github.com/skoulouzis/playbooks.git"}}, "delete": {"inputs": {"playbook": "k8s_delete.yaml", "repository": "https://github.com/skoulouzis/playbooks.git"}}}}, "requirements": [{"host": {"capability": "tosca.capabilities.ARTICONF.VM.topology", "node": "topology", "relationship": "tosca.relationships.HostedOn"}}], "type": "tosca.nodes.ARTICONF.docker.Orchestrator.Kubernetes"}, "topology": {"artifacts": {"provisioned_files": {"required": false, "type": "string"}}, "interfaces": {"CloudsStorm": {"delete": {"inputs": {"code_type": "SEQ", "object_type": "SubTopology"}}, "hscale": {"inputs": {"code_type": "SEQ", "object_type": "SubTopology"}}, "provision": {"inputs": {"code_type": "SEQ", "object_type": "SubTopology"}}, "start": {"inputs": {"code_type": "SEQ", "object_type": "SubTopology"}}, "stop": {"inputs": {"code_type": "SEQ", "object_type": "SubTopology"}}}}, "properties": {"domain": "Frankfurt", "provider": "EC2"}, "requirements": [{"vm": {"capability": "tosca.capabilities.ARTICONF.VM", "node": "compute", "relationship": "tosca.relationships.DependsOn"}}, {"vm": {"capability": "tosca.capabilities.ARTICONF.VM", "node": "compute_1", "relationship": "tosca.relationships.DependsOn"}}], "type": "tosca.nodes.ARTICONF.VM.topology"}, "ws-pema": {"artifacts": {"image": {"file": "alogo53/ws-pema-lifewatch", "repository": "docker_hub", "type": "tosca.artifacts.Deployment.Image.Container.Docker"}}, "properties": {"ports": ["30001:8080"]}, "requirements": [{"host": {"capability": "tosca.capabilities.ARTICONF.docker.Orchestrator", "node": "kubernetes", "relationship": "tosca.relationships.HostedOn"}}], "type": "tosca.nodes.ARTICONF.Container.Application.Docker"}}}}, "creationDate": 1585660828105}
{"owner":"user","creationDate":1585660972026,"toscaTemplate":{"tosca_definitions_version":"tosca_simple_yaml_1_0","tosca_default_namespace":null,"template_name":null,"topology_template":{"description":null,"inputs":null,"node_templates":{"compute":{"properties":{"disk_size":"10000 MB","mem_size":"1000 MB","num_cores":1,"os":"Ubuntu 18.04","user_name":"vm_user"},"interfaces":{"Standard":{"create":"dumy.yaml"}},"type":"tosca.nodes.ARTICONF.VM.Compute"},"compute_1":{"properties":{"disk_size":"10000 MB","mem_size":"1000 MB","num_cores":1,"os":"Ubuntu 18.04","user_name":"vm_user"},"interfaces":{"Standard":{"create":"dumy.yaml"}},"type":"tosca.nodes.ARTICONF.VM.Compute"},"kubernetes":{"requirements":[{"host":{"capability":"tosca.capabilities.ARTICONF.VM.topology","node":"topology","relationship":"tosca.relationships.HostedOn"}}],"interfaces":{"Standard":{"configure":{"inputs":{"playbook":"k8s_dashboard.yaml","repository":"https://github.com/skoulouzis/playbooks.git"}},"create":{"inputs":{"playbook":"k8s_install.yml","repository":"https://github.com/skoulouzis/playbooks.git"}},"delete":{"inputs":{"playbook":"k8s_delete.yaml","repository":"https://github.com/skoulouzis/playbooks.git"}}}},"type":"tosca.nodes.ARTICONF.docker.Orchestrator.Kubernetes"},"topology":{"properties":{"domain":"Frankfurt","provider":"EC2"},"requirements":[{"vm":{"capability":"tosca.capabilities.ARTICONF.VM","node":"compute","relationship":"tosca.relationships.DependsOn"}},{"vm":{"capability":"tosca.capabilities.ARTICONF.VM","node":"compute_1","relationship":"tosca.relationships.DependsOn"}}],"interfaces":{"CloudsStorm":{"delete":{"inputs":{"code_type":"SEQ","object_type":"SubTopology"}},"hscale":{"inputs":{"code_type":"SEQ","object_type":"SubTopology"}},"provision":{"inputs":{"code_type":"SEQ","object_type":"SubTopology"}},"start":{"inputs":{"code_type":"SEQ","object_type":"SubTopology"}},"stop":{"inputs":{"code_type":"SEQ","object_type":"SubTopology"}}}},"type":"tosca.nodes.ARTICONF.VM.topology","attributes":{"credential":{"cloud_provider_name":"EC2","keys":{"aws_access_key_id":"XXXXXXXXXXXX"},"token":"XXXXXXXXXXXXX","token_type":"access_key"},"desired_state":"RUNNING"},"artifacts":{"provisioned_files":{"required":false,"type":"string"}}},"ws-pema":{"properties":{"ports":["30001:8080"]},"requirements":[{"host":{"capability":"tosca.capabilities.ARTICONF.docker.Orchestrator","node":"kubernetes","relationship":"tosca.relationships.HostedOn"}}],"type":"tosca.nodes.ARTICONF.Container.Application.Docker","artifacts":{"image":{"file":"alogo53/ws-pema-lifewatch","repository":"docker_hub","type":"tosca.artifacts.Deployment.Image.Container.Docker"}}}},"relationship_templates":null,"outputs":null,"groups":null,"substitution_mappings":null,"policies":null},"template_author":null,"template_version":null,"description":"TOSCA example","imports":[{"nodes":"https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/nodes.yaml"},{"data":"https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/data.yml"},{"capabilities":"https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/capabilities.yaml"},{"policies":"https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/policies.yaml"},{"interfaces":"https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/interfaces.yml"}],"dsl_definitions":null,"node_types":null,"relationship_types":null,"relationship_templates":null,"capability_types":null,"artifact_types":null,"data_types":null,"interface_types":null,"policy_types":null,"group_types":null,"repositories":null}}
{"owner":"user","creationDate":1585660972026,"toscaTemplate":{"tosca_definitions_version":"tosca_simple_yaml_1_0","tosca_default_namespace":null,"template_name":null,"topology_template":{"description":null,"inputs":null,"node_templates":{"compute":{"properties":{"disk_size":"10000 MB","mem_size":"1000 MB","num_cores":1,"os":"Ubuntu 18.04","user_name":"vm_user"},"interfaces":{"Standard":{"create":"dumy.yaml"}},"type":"tosca.nodes.ARTICONF.VM.Compute"},"compute_1":{"properties":{"disk_size":"10000 MB","mem_size":"1000 MB","num_cores":1,"os":"Ubuntu 18.04","user_name":"vm_user"},"interfaces":{"Standard":{"create":"dumy.yaml"}},"type":"tosca.nodes.ARTICONF.VM.Compute"},"kubernetes":{"requirements":[{"host":{"capability":"tosca.capabilities.ARTICONF.VM.topology","node":"topology","relationship":"tosca.relationships.HostedOn"}}],"interfaces":{"Standard":{"configure":{"inputs":{"playbook":"k8s_dashboard.yaml","repository":"https://github.com/skoulouzis/playbooks.git"}},"create":{"inputs":{"playbook":"install_k8s.yaml","repository":"https://github.com/skoulouzis/playbooks.git"}},"delete":{"inputs":{"playbook":"k8s_delete.yaml","repository":"https://github.com/skoulouzis/playbooks.git"}}}},"type":"tosca.nodes.ARTICONF.docker.Orchestrator.Kubernetes"},"topology":{"properties":{"domain":"Frankfurt","provider":"EC2"},"requirements":[{"vm":{"capability":"tosca.capabilities.ARTICONF.VM","node":"compute","relationship":"tosca.relationships.DependsOn"}},{"vm":{"capability":"tosca.capabilities.ARTICONF.VM","node":"compute_1","relationship":"tosca.relationships.DependsOn"}}],"interfaces":{"CloudsStorm":{"delete":{"inputs":{"code_type":"SEQ","object_type":"SubTopology"}},"hscale":{"inputs":{"code_type":"SEQ","object_type":"SubTopology"}},"provision":{"inputs":{"code_type":"SEQ","object_type":"SubTopology"}},"start":{"inputs":{"code_type":"SEQ","object_type":"SubTopology"}},"stop":{"inputs":{"code_type":"SEQ","object_type":"SubTopology"}}}},"type":"tosca.nodes.ARTICONF.VM.topology","attributes":{"credential":{"cloud_provider_name":"EC2","keys":{"aws_access_key_id":"XXXXXXXXXXXX"},"token":"XXXXXXXXXXXXX","token_type":"access_key"},"desired_state":"RUNNING"},"artifacts":{"provisioned_files":{"required":false,"type":"string"}}},"ws-pema":{"properties":{"ports":["30001:8080"]},"requirements":[{"host":{"capability":"tosca.capabilities.ARTICONF.docker.Orchestrator","node":"kubernetes","relationship":"tosca.relationships.HostedOn"}}],"type":"tosca.nodes.ARTICONF.Container.Application.Docker","artifacts":{"image":{"file":"alogo53/ws-pema-lifewatch","repository":"docker_hub","type":"tosca.artifacts.Deployment.Image.Container.Docker"}}}},"relationship_templates":null,"outputs":null,"groups":null,"substitution_mappings":null,"policies":null},"template_author":null,"template_version":null,"description":"TOSCA example","imports":[{"nodes":"https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/nodes.yaml"},{"data":"https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/data.yml"},{"capabilities":"https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/capabilities.yaml"},{"policies":"https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/policies.yaml"},{"interfaces":"https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/interfaces.yml"}],"dsl_definitions":null,"node_types":null,"relationship_types":null,"relationship_templates":null,"capability_types":null,"artifact_types":null,"data_types":null,"interface_types":null,"policy_types":null,"group_types":null,"repositories":null}}
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7 (semaphore-python-client-generated)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 2.7 (semaphore-python-client-generated)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
......
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