Commit 632cb1d3 authored by Spiros Koulouzis's avatar Spiros Koulouzis

generate ansible k8s

parent 9bd8d5fa
......@@ -32,6 +32,8 @@
- gnupg2
- software-properties-common
- python3-pip
- python-pip
- virtualenv
- name: Add Docker GPG apt Key
apt_key:
......
......@@ -27,6 +27,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.model.NodeTemplate;
import nl.uva.sne.drip.model.NodeTemplateMap;
import nl.uva.sne.drip.model.tosca.Credential;
......@@ -82,6 +84,7 @@ public class ToscaHelper {
FileUtils.writeByteArrayToFile(toscaTemplateFile, ymlStr.getBytes());
String resp = api.uploadToscaTemplate(toscaTemplateFile);
id = Integer.valueOf(resp);
Logger.getLogger(ToscaHelper.class.getName()).log(Level.FINE, "Uploaded ToscaTemplate to sure-tosca service got back id: " + id);
}
public List<Map<String, Object>> getProvisionInterfaceDefinitions(List<String> toscaInterfaceTypes) throws ApiException {
......@@ -214,7 +217,7 @@ public class ToscaHelper {
nodes.put(node.getName(), node.getNodeTemplate());
return toscaTemplate;
}
public Map<String, Object> getProvisionerInterfaceFromVMTopology(NodeTemplateMap vmTopologyMap) {
return (Map<String, Object>) vmTopologyMap.getNodeTemplate().getInterfaces().get("CloudsStorm");
}
......
......@@ -66,6 +66,7 @@ def write_inventory_file(tmp_path, vms):
print('ansible_ssh_private_key_file=' + ansible_ssh_private_key_file_path, file=k8s_hosts_file)
print('ansible_ssh_common_args=\'-o StrictHostKeyChecking=no\'', file=k8s_hosts_file)
print('ansible_ssh_user=' + ansible_ssh_user, file=k8s_hosts_file)
logger.info("Returning inventory file at: " + str(k8s_hosts_path))
return k8s_hosts_path
......@@ -87,15 +88,19 @@ def write_playbooks_from_tosca_interface(interfaces, tmp_path):
playbook_paths = []
for interface_name in interfaces:
playbook_paths = playbook_paths + write_playbooks(tmp_path, interfaces[interface_name])
logger.info("Returning playbook paths file at: " + str(playbook_paths))
return playbook_paths
def run(inventory_path, playbook_path):
logger.info("Executing playbook: " + str(playbook_path))
p = Popen(["ansible-playbook", "-i", inventory_path, playbook_path], stdin=PIPE, stdout=PIPE,
stderr=PIPE)
output, err = p.communicate()
print(output.decode('utf-8'))
print(err.decode('utf-8'))
# print(output.decode('utf-8'))
# print(err.decode('utf-8'))
logger.info("Playbook output: " + str(output.decode('utf-8')))
logger.info("Playbook err: " + str(err.decode('utf-8')))
rc = p.returncode
return output, err
......
from _ast import mod
import yaml
yaml.Dumper.ignore_aliases = lambda *args: True
......@@ -68,6 +70,11 @@ def write_ansible_k8s_files(tosca_template_json, tmp_path):
deployments = k8s_definitions['deployments']
i = 0
tasks = []
pip_task = {'name': 'install kubernetes'}
modules = ['setuptools', 'kubernetes', 'pkg_resources']
pip = {'name': modules}
pip_task['pip'] = pip
tasks.append(pip_task)
for services_def in services:
task = {'name': 'Create a Service object' + str(i)}
k8s = {'state': 'present', 'definition': services_def}
......
import logging
logger = logging.getLogger(__name__)
def get_interfaces(tosca_template_json):
node_templates = tosca_template_json['topology_template']['node_templates']
for node_name in node_templates:
if node_templates[node_name]['type'] == 'tosca.nodes.ARTICONF.Orchestrator.Kubernetes':
logger.info("Returning interfaces from tosca_template: " + str(node_templates[node_name]['interfaces']))
return node_templates[node_name]['interfaces']
......@@ -11,4 +17,5 @@ def get_vms(tosca_template_json):
for node_name in node_templates:
if node_templates[node_name]['type'] == 'tosca.nodes.ARTICONF.VM.Compute':
vms[node_name] = node_templates[node_name]
logger.info("Returning VMs from tosca_template: " + str(vms))
return vms
......@@ -111,6 +111,7 @@ public class DRIPService {
}
}
Logger.getLogger(ToscaHelper.class.getName()).log(Level.FINE, "Added credetials to ToscaTemplate");
return toscaTemplate;
}
......@@ -160,8 +161,10 @@ public class DRIPService {
private ToscaTemplate initExecution(String id) throws JsonProcessingException, NotFoundException, IOException, ApiException {
String ymlToscaTemplate = toscaTemplateService.findByID(id);
Logger.getLogger(DRIPService.class.getName()).log(Level.FINE,"Found ToscaTemplate with id: "+id);
ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(ymlToscaTemplate);
helper.uploadToscaTemplate(toscaTemplate);
return toscaTemplate;
}
......
......@@ -69,6 +69,7 @@ public class Consumer extends DefaultConsumer {
.build();
Message message = objectMapper.readValue(new String(body, "UTF-8"), Message.class);
logger.log(Level.INFO, "Got Request: '{'0'}'{0}", message.getToscaTemplate());
String tempInputDirPath = System.getProperty("java.io.tmpdir") + File.separator + "Input-" + Long.toString(System.nanoTime()) + File.separator;
File tempInputDir = new File(tempInputDirPath);
......
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