Commit 70ef3781 authored by skoulouzis's avatar skoulouzis Committed by GitHub

Merge branch 'master' into drip_1.0

parents fbef3be4 45479297
#! /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 deploy_compose(vm, compose_file, compose_name):
try:
print "%s: ====== Start Docker Compose Deploying ======" % (vm.ip)
paramiko.util.log_to_file("deployment.log")
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/')
sftp.put(compose_file, "docker-compose.yml")
stdin, stdout, stderr = ssh.exec_command("sudo docker stack deploy --compose-file /tmp/docker-compose.yml %s" % (compose_name))
stdout.read()
print "%s: ======= Deployment of Compose Finished =========" % (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, compose_file, compose_name):
for i in vm_list:
if i.role == "master":
ret = deploy_compose(i, compose_file, compose_name)
if "ERROR" in ret:
return ret
else:
swarm_file = open(i.key)
ret = swarm_file.read()
swarm_file.close()
break
return ret
\ No newline at end of file
......@@ -22,9 +22,15 @@ import threading
def install_engine(vm):
try:
print "%s: ====== Start Docker Engine Installing ======" % (vm.ip)
paramiko.util.log_to_file("deployment.log")
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 dpkg --get-selections | grep docker")
temp_list = stdout.readlines()
temp_str = ""
for i in temp_list: temp_str += i
if temp_str.find("docker") != -1: return "SUCCESS"
sftp = ssh.open_sftp()
sftp.chdir('/tmp/')
file_path = os.path.dirname(os.path.abspath(__file__))
......
......@@ -7,5 +7,5 @@ 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
sudo echo "{ \"insecure-registries\":[\"129.7.98.3:5000\"] }" > /etc/docker/daemon.json
sudo service docker restart
#sudo echo "{ \"insecure-registries\":[\"129.7.98.3:5000\"] }" > /etc/docker/daemon.json
#sudo service docker restart
......@@ -22,9 +22,15 @@ from vm_info import VmInfo
def install_manager(vm):
try:
print "%s: ====== Start Swarm Manager Installing ======" % (vm.ip)
paramiko.util.log_to_file("deployment.log")
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 info | grep Swarm")
temp_list = stdout.readlines()
temp_str = ""
for i in temp_list: temp_str += i
if temp_str.find("Swarm: active") != -1: return "SUCCESS"
stdin, stdout, stderr = ssh.exec_command("sudo docker swarm leave --force")
stdout.read()
stdin, stdout, stderr = ssh.exec_command("sudo docker swarm init --advertise-addr %s" % (vm.ip))
......@@ -39,6 +45,7 @@ def install_manager(vm):
def install_worker(join_cmd, vm):
try:
print "%s: ====== Start Swarm Worker Installing ======" % (vm.ip)
paramiko.util.log_to_file("deployment.log")
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(vm.ip, username=vm.user, key_filename=vm.key)
......@@ -62,6 +69,11 @@ def run(vm_list):
join_cmd = install_manager(i)
if "ERROR" in join_cmd:
return join_cmd
elif "SUCCESS" in join_cmd:
swarm_file = open(i.key)
swarm_string = swarm_file.read()
swarm_file.close()
return swarm_string
else:
join_cmd = join_cmd.encode()
join_cmd = join_cmd.replace("\n" , "")
......
......@@ -8,6 +8,7 @@ from vm_info import VmInfo
import docker_kubernetes
import docker_engine
import docker_swarm
import docker_compose
import control_agent
import ansible_playbook
import sys, argparse
......@@ -69,8 +70,9 @@ def handleDelivery(message):
fo.close()
elif name == "composer":
value = param["value"]
docker_composer = path + "docker-composer.yml"
fo = open(docker_composer, "w")
compose_file = path + "docker-compose.yml"
compose_name = param["attributes"]["name"]
fo = open(compose_file, "w")
fo.write(value)
fo.close()
......@@ -82,9 +84,7 @@ def handleDelivery(message):
if "ERROR" in ret: return ret
ret = docker_swarm.run(vm_list)
if "ERROR" in ret: return ret
ret1 = control_agent.run(vm_list)
#deploy_composer.run(vm_list,docker_composer)
if "ERROR" in ret1: ret = ret1
ret = docker_compose.run(vm_list, compose_file, compose_name)
return ret
elif manager_type == "ansible":
ret = ansible_playbook.run(vm_list,playbook)
......
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