Commit 6b4ca7a3 authored by Oceans's avatar Oceans

control agent

parent 00a13b34
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ 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
def install_agent(vm, vm_list):
try:
print "%s: ====== Start Control Agent Installation ======" % (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/')
vm_cnt = 0
file_path = os.path.dirname(os.path.abspath(__file__))
fo = open(file_path + "/cluster_file", "w")
for i in vm_list:
vm_cnt += 1
sftp.put(i.key, "%d" % (vm_cnt))
fo.write("%s %s /tmp/%d %s\n" % (i.ip, i.user, vm_cnt, i.role))
fo.close()
sftp.put(file_path + "/cluster_file", "cluster_file")
sftp.put(file_path + "/control_agent.sh", "control_agent.sh")
stdin, stdout, stderr = ssh.exec_command("sudo sh /tmp/control_agent.sh")
stdout.read()
stdin, stdout, stderr = ssh.exec_command("nohup python /root/Swarm-Agent/run.py>/dev/null 2>&1 &")
stdout.read()
print "%s: ========= Control Agent 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":
ret = install_agent(i, vm_list)
if "ERROR" in ret: return ret
return "SUCCESS"
\ No newline at end of file
#! /bin/bash
sudo apt-get update
sudo apt-get -y install git
sudo apt-get -y install wget
sudo apt-get -y install build-essential libssl-dev libffi-dev python-dev
cd /root/
sudo wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
sudo pip install flask
sudo pip install paramiko
sudo git clone https://github.com/oceanshy/Swarm-Agent.git
#! /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
......@@ -8,3 +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 "DOCKER_OPTS="--insecure-registry=145.100.133.241:5000"" >> /etc/default/docker
sudo service docker restart
......@@ -8,6 +8,8 @@ from vm_info import VmInfo
import docker_kubernetes
import docker_engine
import docker_swarm
import control_agent
connection = pika.BlockingConnection(pika.ConnectionParameters(host='172.17.0.3'))
channel = connection.channel()
......@@ -44,10 +46,12 @@ def handleDelivery(message):
ret = docker_engine.run(vm_list)
if "ERROR" in ret: return ret
ret = docker_swarm.run(vm_list)
if "ERROR" in ret: return ret
ret1 = control_agent.run(vm_list)
if "ERROR" in ret1: ret = ret1
return ret
else:
return "ERROR: invalid cluster"
def on_request(ch, method, props, body):
......
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