Commit fb608589 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Merge origin/package into package

parents 1304b264 00a13b34
#! /usr/bin/env python
# Copyright 2017 --Yang Hu--
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__author__ = 'Yang Hu'
import paramiko, os
import threading
def install_engine(vm):
try:
print "%s: ====== Start Docker Engine Installing ======" % (vm.ip)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(vm.ip, username=vm.user, key_filename=vm.key)
sftp = ssh.open_sftp()
sftp.chdir('/tmp/')
file_path = os.path.dirname(os.path.abspath(__file__))
install_script = file_path + "/" + "docker_engine.sh"
sftp.put(install_script, "engine_setup.sh")
stdin, stdout, stderr = ssh.exec_command("sudo sh /tmp/engine_setup.sh")
stdout.read()
print "%s: ========= Docker Engine Installed =========" % (vm.ip)
except Exception as e:
print '%s: %s' % (vm.ip, e)
return "ERROR:"+vm.ip+" "+str(e)
ssh.close()
return "SUCCESS"
def run(vm_list):
for i in vm_list:
ret = install_engine(i)
if "ERROR" in ret: return ret
return "SUCCESS"
\ No newline at end of file
#! /bin/bash
sudo apt-get remove docker docker-engine
sudo apt-get update
sudo apt-get -y install linux-image-extra-$(uname -r) linux-image-extra-virtual
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get -y install docker-ce
...@@ -71,19 +71,26 @@ def install_worker(join_cmd, vm): ...@@ -71,19 +71,26 @@ def install_worker(join_cmd, vm):
print '%s: %s' % (vm.ip, e) print '%s: %s' % (vm.ip, e)
return "ERROR:"+vm.ip+" "+str(e) return "ERROR:"+vm.ip+" "+str(e)
ssh.close() ssh.close()
return "" return "SUCCESS"
def run(vm_list): def run(vm_list):
for i in vm_list: for i in vm_list:
if i.role == "master": join_cmd = install_manager(i) if i.role == "master":
if "ERROR" in join_cmd: join_cmd = install_manager(i)
return join_cmd if "ERROR" in join_cmd:
else: return join_cmd
join_cmd = join_cmd.encode() else:
join_cmd = join_cmd.strip() join_cmd = join_cmd.encode()
join_cmd = join_cmd.strip()
break
for i in vm_list: for i in vm_list:
if i.role == "slave": worker_cmd = install_worker(join_cmd, i) if i.role == "slave":
if "ERROR" in worker_cmd: worker_cmd = install_worker(join_cmd, i)
return worker_cmd if "ERROR" in worker_cmd:
return "" return worker_cmd
\ No newline at end of file
kuber_file = open(file_path + "/admin.conf", "r")
kuber_string = kuber_file.read()
kuber_file.close()
return kuber_string
\ No newline at end of file
#! /usr/bin/env python
# Copyright 2017 --Yang Hu--
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__author__ = 'Yang Hu'
import paramiko, os
from vm_info import VmInfo
def install_manager(vm):
try:
print "%s: ====== Start Swarm Manager Installing ======" % (vm.ip)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(vm.ip, username=vm.user, key_filename=vm.key)
stdin, stdout, stderr = ssh.exec_command("sudo docker swarm init --advertise-addr eth0")
retstr = stdout.readlines()
print "%s: ========= Swarm Manager Installed =========" % (vm.ip)
except Exception as e:
print '%s: %s' % (vm.ip, e)
return "ERROR:"+vm.ip+" "+str(e)
ssh.close()
return retstr[4] + retstr[5] + retstr[6]
def install_worker(join_cmd, vm):
try:
print "%s: ====== Start Swarm Worker Installing ======" % (vm.ip)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(vm.ip, username=vm.user, key_filename=vm.key)
stdin, stdout, stderr = ssh.exec_command("sudo %s" % (join_cmd))
stdout.read()
print "%s: ========= Swarm Worker Installed =========" % (vm.ip)
except Exception as e:
print '%s: %s' % (vm.ip, e)
return "ERROR:"+vm.ip+" "+str(e)
ssh.close()
return "SUCCESS"
def run(vm_list):
for i in vm_list:
if i.role == "master":
join_cmd = install_manager(i)
if "ERROR" in join_cmd:
return join_cmd
else:
join_cmd = join_cmd.encode()
join_cmd = join_cmd.replace("\n" , "")
join_cmd = join_cmd.replace("\\" , "")
join_cmd = join_cmd.strip()
swarm_file = open(i.key)
swarm_string = swarm_file.read()
swarm_file.close()
break
for i in vm_list:
if i.role == "slave":
worker_cmd = install_worker(join_cmd, i)
if "ERROR" in worker_cmd:
return worker_cmd
return swarm_string
\ No newline at end of file
...@@ -6,6 +6,8 @@ import time ...@@ -6,6 +6,8 @@ import time
from vm_info import VmInfo from vm_info import VmInfo
import docker_kubernetes import docker_kubernetes
import docker_engine
import docker_swarm
connection = pika.BlockingConnection(pika.ConnectionParameters(host='172.17.0.3')) connection = pika.BlockingConnection(pika.ConnectionParameters(host='172.17.0.3'))
channel = connection.channel() channel = connection.channel()
...@@ -19,32 +21,43 @@ def handleDelivery(message): ...@@ -19,32 +21,43 @@ def handleDelivery(message):
node_num = 0 node_num = 0
vm_list = [] vm_list = []
for param in params: for param in params:
value = param["value"] name = param["name"]
ip = param["attributes"]["IP"] if name == "cluster":
user = param["attributes"]["user"] cluster_type = param["value"]
role = param["attributes"]["role"] else:
node_num += 1 value = param["value"]
key = path + "%d.txt" % (node_num) ip = param["attributes"]["IP"]
fo = open(key, "w") user = param["attributes"]["user"]
fo.write(value) role = param["attributes"]["role"]
fo.close() node_num += 1
vm = VmInfo(ip, user, key, role) key = path + "%d.txt" % (node_num)
vm_list.append(vm) fo = open(key, "w")
return docker_kubernetes.run(vm_list) fo.write(value)
fo.close()
vm = VmInfo(ip, user, key, role)
vm_list.append(vm)
if cluster_type == "kubernetes":
ret = docker_kubernetes.run(vm_list)
return ret
elif cluster_type == "swarm":
ret = docker_engine.run(vm_list)
if "ERROR" in ret: return ret
ret = docker_swarm.run(vm_list)
return ret
else:
return "ERROR: invalid cluster"
def on_request(ch, method, props, body): def on_request(ch, method, props, body):
ret = handleDelivery(body) ret = handleDelivery(body)
print ret print ret
if "ERROR" in ret: if "ERROR" in ret:
kuber_string = ret
res_name = "error" res_name = "error"
#print(" Message %s" % body)
else: else:
res_name = "credential" res_name = "credential"
kuber_file = open(path + "admin.conf", "r")
kuber_string = kuber_file.read()
kuber_file.close()
response = {} response = {}
outcontent = {} outcontent = {}
...@@ -55,7 +68,7 @@ def on_request(ch, method, props, body): ...@@ -55,7 +68,7 @@ def on_request(ch, method, props, body):
par["url"] = "null" par["url"] = "null"
par["encoding"] = "UTF-8" par["encoding"] = "UTF-8"
par["name"] = res_name par["name"] = res_name
par["value"] = kuber_string par["value"] = ret
par["attributes"] = "null" par["attributes"] = "null"
response["parameters"].append(par) response["parameters"].append(par)
......
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