Commit 917597f8 authored by Spiros Koulouzis's avatar Spiros Koulouzis

add k8s output to TOSCA

parent 007e411c
......@@ -15,10 +15,6 @@
*/
package nl.uva.sne.drip.api.service;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
......@@ -26,8 +22,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -42,7 +36,6 @@ import nl.uva.sne.drip.api.rpc.DRIPCaller;
import nl.uva.sne.drip.api.v1.rest.ProvisionController;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployParameter;
import nl.uva.sne.drip.drip.commons.data.internal.Message;
import nl.uva.sne.drip.drip.commons.data.internal.MessageParameter;
import nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse;
......@@ -61,8 +54,6 @@ import nl.uva.sne.drip.commons.utils.DRIPLogHandler;
import nl.uva.sne.drip.commons.utils.TOSCAUtils;
import static nl.uva.sne.drip.commons.utils.TOSCAUtils.getVMsFromTopology;
import static nl.uva.sne.drip.commons.utils.TOSCAUtils.getVMsNodeNamesFromTopology;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest;
import org.apache.commons.codec.binary.Base64;
......
......@@ -247,12 +247,14 @@ public class TOSCAUtils {
List<String> toscaPortsList = (List<String>) properties.get("ports");
if (toscaPortsList != null) {
List< Map<String, Object>> portList = new ArrayList<>();
for (String portEntry : toscaPortsList) {
String[] portsArray = portEntry.split(":");
Map<String, Object> portMap = new HashMap();
portMap.put("containerPort", Integer.valueOf(portsArray[0]));
container.put("ports", portMap);
portList.add(portMap);
}
container.put("ports", portList);
}
List<Map<String, Object>> containersList = new ArrayList<>();
containersList.add(container);
......
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRFNU1Ea3lOVEUwTWpjME9Wb1hEVEk1TURreU1qRTBNamMwT1Zvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBSmU0CnNnc2I2ZEkvNk56WU5jbVZHY3FjamwxYVJTY3dQVG9YREhxWGRDZzZsUHlJWkRpcmNhRWlxS3dkcTE0RUF3c0UKQ0hZUjBUOWNoWWVkMFdmcHV4cGVzQWJ2RVBjRHNBbHFia21FaTN5VWZjYm5vb3JDUk56SWtNZWJhbWhNOGFIYwp6bFZpaTY1VHdoRXlKZGptd1MxRU5odTBJbktSNktOZHpIeTdhSk45dk5VY2JwZW5ON05KQkRCMmFwMTVNUmdUClVDUklQOHlneFU1V2V5NnA1SnJ1VHV1S1pLUVpxZm11cnBHb2tmQzJqOVdUTDZqQjdJcCthdEpWZFFNT2JJU04KRmM4Z0p5Q0huMUVPR0dwQXRIK1lsc3NpWnk2VFV6NEpLcXpSYmVwaVpUSVZNMUI5anh4alloSDVGNFR5UmllMgp6L0dwbCtDOFpzSXdSU2M3Z0wwQ0F3RUFBYU1qTUNFd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFBeWlqMzVDcTA1cWg5bjROYS8yNGJTYkh1aUEKdnMzUmVTSThISWZManhPNXVFMnJ6R3Y2bjBZMlVab1ZFemcrbldTdjVjNG81Qm1uTVQ2MkxNM1JYRDV0WW0yWAo0ZVI3QTk5d1RSYTcyY1lTYSs0emtPYVI3cisySUpDZndLZ0hEUzU2SFY2dkhwNWRZWHlUenlNK09MVVlMNnNECkx5eHZJSVlUTHZKQzIweE1aakFCQWR3UXM4eExKTE1zbEV1WDJUTXYwempxOWpFWHNDN2xXOXhJLzYzSU5nU2sKU2dDc0pONnY3ZUN0WUlHZWsrbndTengwL09vVXp2STFUd1ZGenFxS2Jwcm0rd2dQd1hITGtKSXBZeXg5SlM4Ywo0b2ZkMFBadE5kVUNDRXQ1R2w3b05PaUVkbU5JVmVqTVdDRWQxdlFLQ2VZejlzRk05WVQwUXlEakpTcz0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
server: https://10.103.0.7:6443
name: kubernetes
contexts:
- context:
cluster: kubernetes
user: kubernetes-admin
name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
user:
client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM4akNDQWRxZ0F3SUJBZ0lJRUgrWWpSQzJSUFF3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB4T1RBNU1qVXhOREkzTkRsYUZ3MHlNREE1TWpReE5ESTNOVFJhTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQTFlYnovM2dVQWQvai9uay8KWTlZUmNRS3VQMEFZT28zNlRsT2RiRlR5cHE1bXo4UGpOMlV2b1pZMkNlazhCSCtLVXhTbzRWdWphelNxM0N5VwpiOS9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0ZZejA9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
......@@ -21,12 +21,12 @@ from vm_info import VmInfo
import linecache
import sys
import logging
import time
# from drip_logging.drip_logging_handler import *
from os import listdir
from os.path import isfile, join
logger = logging.getLogger(__name__)
if not getattr(logger, 'handler_set', None):
logger.setLevel(logging.INFO)
......@@ -75,16 +75,34 @@ def install_manager(vm):
stdout.read()
# stdin, stdout, stderr = ssh.exec_command("sudo kubeadm init --apiserver-advertise-address=%s" % (vm.ip))
stdin, stdout, stderr = ssh.exec_command("sudo kubeadm init >> log 2>&1")
stdin, stdout, stderr = ssh.exec_command("sudo kubeadm init")
retstr = stdout.readlines()
stdin, stdout, stderr = ssh.exec_command("sudo cp /etc/kubernetes/admin.conf /tmp/")
stdin, stdout, stderr = ssh.exec_command("mkdir -p $HOME/.kube")
stdout.read()
stdin, stdout, stderr = ssh.exec_command("sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config")
stdout.read()
stdin, stdout, stderr = ssh.exec_command("sudo chown $(id -u):$(id -g) $HOME/.kube/config")
stdout.read()
stdin, stdout, stderr = ssh.exec_command("sudo sysctl net.bridge.bridge-nf-call-iptables=1")
retstr = stdout.readlines()
stdin, stdout, stderr = ssh.exec_command(
"kubectl apply -f \"https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')\"")
retstr = stdout.readlines()
stdin, stdout, stderr = ssh.exec_command(
"kubectl taint nodes --all node-role.kubernetes.io/master-")
retstr = stdout.readlines()
stdin, stdout, stderr = ssh.exec_command("sudo chown %s /tmp/admin.conf" % (vm.user))
stdout.read()
stdin, stdout, stderr = ssh.exec_command("sudo chgrp %s /tmp/admin.conf" % (vm.user))
stdout.read()
sftp.get("/tmp/admin.conf", file_path + "/admin.conf")
# sftp.get("/tmp/admin.conf", file_path + "/admin.conf")
logger.info("Finished kubernetes master installation on: " + (vm.ip))
except Exception as e:
global retry
......@@ -151,25 +169,32 @@ def deploy_on_master(deployment_file, vm):
k8s_file = deployment_file + "/" + f
sftp.put(k8s_file, f)
stdin, stdout, stderr = ssh.exec_command("kubectl create -f /tmp/k8s/ --kubeconfig /tmp/admin.conf >> log 2>&1")
stdin, stdout, stderr = ssh.exec_command("kubectl create -f /tmp/k8s/ >> log 2>&1")
s_out = stdout.read()
e_out = stderr.read()
print s_out
print e_out
time.sleep(2)
# cmd = 'kubectl get svc --all-namespaces -o go-template=\'{{range .items}}{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\\n"}}{{end}}{{end}}{{end}}\''
cmd = 'kubectl get svc --output json'
stdin, stdout, stderr = ssh.exec_command(cmd)
e_out = stderr.read()
json_output = stdout.read().splitlines()
# exposed_ports_str = ''
# for port in exposed_ports:
# exposed_ports_str += port + ','
# exposed_ports_str = exposed_ports_str[:-1]
except Exception as e:
# print '%s: %s' % (vm.ip, e)
logger.error(vm.ip + " " + str(e))
return "ERROR:" + vm.ip + " " + str(e)
ssh.close()
return "SUCCESS"
return json_output
def deploy(vm_list, deployment_file):
for i in vm_list:
if i.role == "master":
deploy_on_master(deployment_file, i)
return None
return deploy_on_master(deployment_file, i)
def run(vm_list, rabbitmq_host, owner):
......
......@@ -129,8 +129,8 @@ def handle_delivery(message):
compose_name = param["attributes"]["name"]
if manager_type == "kubernetes":
# ret = docker_kubernetes.run(vm_list, rabbitmq_host, owner)
docker_kubernetes.deploy(vm_list, k8s_folder)
ret = docker_kubernetes.run(vm_list, rabbitmq_host, owner)
ret = docker_kubernetes.deploy(vm_list, k8s_folder)
return ret
elif manager_type == "swarm":
ret = docker_engine.run(vm_list, rabbitmq_host, owner)
......@@ -166,7 +166,7 @@ def on_request(ch, method, props, body):
manager_type = param["value"]
break
if "ERROR" in ret:
if not ret and "ERROR" in ret:
res_name = "error"
elif manager_type == "ansible":
res_name = "ansible_output"
......@@ -174,6 +174,8 @@ def on_request(ch, method, props, body):
res_name = "scale_status"
elif manager_type == "swarm_info":
res_name = "swarm_info"
elif manager_type == "kubernetes":
res_name = "kubectl_get"
else:
res_name = "credential"
......@@ -186,7 +188,7 @@ def on_request(ch, method, props, body):
par["url"] = "null"
par["encoding"] = "UTF-8"
par["name"] = res_name
par["value"] = ret
par["value"] = base64.b64encode(ret)
par["attributes"] = "null"
response["parameters"].append(par)
......
......@@ -2,9 +2,7 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="slolved cap error">
<change beforePath="$PROJECT_DIR$/../drip-deployer/docker_kubernetes.sh" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-deployer/docker_kubernetes.sh" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/planner/basic_planner.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/basic_planner.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/easy-install.pth" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/prettytable.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/pyparsing.py" beforeDir="false" />
......@@ -84,7 +82,7 @@
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/rpc_server.py" />
<option name="PARAMETERS" value="test_local" />
<option name="PARAMETERS" value="localhost planner_queue" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
......
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