Commit 1f8ca025 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Merge origin/package into package

parents e6c95725 1c71860a
#! /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 Kubernetes Master 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()
file_path = os.path.dirname(os.path.abspath(__file__))
sftp.chdir('/tmp/')
install_script = file_path + "/" + "docker_kubernetes.sh"
sftp.put(install_script, "kubernetes_setup.sh")
stdin, stdout, stderr = ssh.exec_command("sudo hostname ip-%s" % (vm.ip.replace('.','-')))
stdout.read()
stdin, stdout, stderr = ssh.exec_command("sudo sh /tmp/kubernetes_setup.sh")
stdout.read()
stdin, stdout, stderr = ssh.exec_command("sudo kubeadm init --api-advertise-addresses=%s" % (vm.ip))
retstr = stdout.readlines()
stdin, stdout, stderr = ssh.exec_command("sudo cp /etc/kubernetes/admin.conf /tmp/")
stdout.read()
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")
print "%s: ========= Kubernetes Master Installed =========" % (vm.ip)
except Exception as e:
print '%s: %s' % (vm.ip, e)
ssh.close()
return retstr[-1]
def install_worker(join_cmd, vm):
try:
print "%s: ====== Start Kubernetes Slave 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_kubernetes.sh"
sftp.put(install_script, "kubernetes_setup.sh")
stdin, stdout, stderr = ssh.exec_command("sudo hostname ip-%s" % (vm.ip.replace('.','-')))
stdout.read()
stdin, stdout, stderr = ssh.exec_command("sudo sh /tmp/kubernetes_setup.sh")
stdout.read()
stdin, stdout, stderr = ssh.exec_command("sudo %s" % (join_cmd))
stdout.read()
print "%s: ========= Kubernetes Slave Installed =========" % (vm.ip)
except Exception as e:
print '%s: %s' % (vm.ip, e)
ssh.close()
def run(vm_list):
for i in vm_list:
if i.role == "master": join_cmd = install_manager(i)
join_cmd = join_cmd.encode()
join_cmd = join_cmd.strip()
for i in vm_list:
if i.role == "slave": install_worker(join_cmd, i)
#! /bin/bash
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y docker.io
sudo apt-get install -y kubelet kubeadm kubectl kubernetes-cni
\ No newline at end of file
#!/usr/bin/env python
import pika
import json
import os
from vm_info import VmInfo
import docker_kubernetes
connection = pika.BlockingConnection(pika.ConnectionParameters(host='172.17.0.2'))
channel = connection.channel()
channel.queue_declare(queue='deployer_queue')
path = os.path.dirname(os.path.abspath(__file__)) + "/"
def handleDelivery(message):
parsed_json = json.loads(message)
params = parsed_json["parameters"]
node_num = 0
vm_list = []
for param in params:
value = param["value"]
ip = param["attributes"]["IP"]
user = param["attributes"]["user"]
role = param["attributes"]["role"]
node_num += 1
key = path + "%d.txt" % (node_num)
fo = open(key, "w")
fo.write(value)
fo.close()
vm = VmInfo(ip, user, key, role)
vm_list.append(vm)
docker_kubernetes.run(vm_list)
def on_request(ch, method, props, body):
handleDelivery(body)
print(" Message %s" % body)
kuber_file = open(path + "admin.conf", "r")
kuber_string = kuber_file.read()
kuber_file.close()
response = {}
response["creationDate"] = 1487002029722
response["parameters"] = []
par = {}
par["url"] = "null"
par["encoding"] = "UTF-8"
par["name"] = "credential"
par["value"] = kuber_string
par["attributes"] = "null"
response["parameters"].append(par)
ch.basic_publish(exchange='',
routing_key=props.reply_to,
properties=pika.BasicProperties(correlation_id = \
props.correlation_id),
body=str(response))
ch.basic_ack(delivery_tag = method.delivery_tag)
channel.basic_qos(prefetch_count=1)
channel.basic_consume(on_request, queue='deployer_queue')
print(" [x] Awaiting RPC requests")
channel.start_consuming()
\ 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.
class VmInfo:
def __init__(self, ip = "", user = "", key = "", role = ""):
self.ip = ip
self.user = user
self.key = key
self.role = role
def displayVm(self):
print "IP:", self.ip, " USER:", self.user
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