Commit 0c872925 authored by Yang's avatar Yang

add service scale

parent 21622555
#! /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 scale_service(vm, application_name, service_name, service_num):
try:
print "%s: ====== Start Docker Service Scaling ======" % (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 service scale %s_%s=%s" % (application_name, service_name, service_num))
stdout.read()
print "%s: ======= Service Scaling 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, application_name, service_name, service_num):
for i in vm_list:
if i.role == "master":
ret = scale_service(i, application_name, service_name, service_num)
if "ERROR" in ret:
return ret
break
return ret
\ No newline at end of file
...@@ -9,6 +9,7 @@ import docker_kubernetes ...@@ -9,6 +9,7 @@ import docker_kubernetes
import docker_engine import docker_engine
import docker_swarm import docker_swarm
import docker_compose import docker_compose
import docker_service
import control_agent import control_agent
import ansible_playbook import ansible_playbook
import sys, argparse import sys, argparse
...@@ -104,6 +105,9 @@ def handleDelivery(message): ...@@ -104,6 +105,9 @@ def handleDelivery(message):
elif manager_type == "ansible": elif manager_type == "ansible":
ret = ansible_playbook.run(vm_list,playbook) ret = ansible_playbook.run(vm_list,playbook)
return ret return ret
elif manager_type == "scale":
ret = docker_service.run(vm_list, name_of_deployment, name_of_service, number_of_containers)
return ret
else: else:
return "ERROR: invalid cluster" return "ERROR: invalid cluster"
...@@ -125,6 +129,8 @@ def on_request(ch, method, props, body): ...@@ -125,6 +129,8 @@ def on_request(ch, method, props, body):
res_name = "error" res_name = "error"
elif manager_type == "ansible": elif manager_type == "ansible":
res_name = "ansible_output" res_name = "ansible_output"
elif manager_type == "scale":
res_name = "status"
else: else:
res_name = "credential" res_name = "credential"
......
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