Update vm-image-update script.
Use libcloud. Install debs listed in devstack within this script. Add shell script that wraps image update script and gets the debs from devstack. Change-Id: Ib6cfcd8572221d828c019903a7be094a011454fc
This commit is contained in:
@@ -18,58 +18,76 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from libcloud.base import NodeImage, NodeSize, NodeLocation
|
||||
from libcloud.types import Provider
|
||||
from libcloud.providers import get_driver
|
||||
from libcloud.deployment import MultiStepDeployment, ScriptDeployment, SSHKeyDeployment
|
||||
from libcloud.dns.types import Provider as DnsProvider
|
||||
from libcloud.dns.types import RecordType
|
||||
from libcloud.dns.providers import get_driver as dns_get_driver
|
||||
import libcloud
|
||||
import sys
|
||||
import os
|
||||
import openstack.compute
|
||||
import commands
|
||||
import time
|
||||
from paramiko import SSHClient
|
||||
|
||||
USERNAME = os.environ['CLOUD_SERVERS_USERNAME']
|
||||
API_KEY = os.environ['CLOUD_SERVERS_API_KEY']
|
||||
CLOUD_SERVERS_DRIVER = os.environ.get('CLOUD_SERVERS_DRIVER','rackspace')
|
||||
CLOUD_SERVERS_USERNAME = os.environ['CLOUD_SERVERS_USERNAME']
|
||||
CLOUD_SERVERS_API_KEY = os.environ['CLOUD_SERVERS_API_KEY']
|
||||
|
||||
SERVER_NAME = 'devstack-oneiric.slave.openstack.org'
|
||||
SERVER_NAME = 'devstack-oneiric.template.openstack.org'
|
||||
IMAGE_NAME = 'devstack-oneiric'
|
||||
|
||||
compute = openstack.compute.Compute(username=USERNAME, apikey=API_KEY,
|
||||
cloud_api='RACKSPACE')
|
||||
debs = ' '.join(open(sys.argv[0]).read().split('\n'))
|
||||
|
||||
print "Searching for %s server" % SERVER_NAME
|
||||
node = compute.servers.find(name=SERVER_NAME)
|
||||
print "Searching for %s image" % IMAGE_NAME
|
||||
try:
|
||||
image = compute.images.find(name=IMAGE_NAME)
|
||||
except openstack.compute.exceptions.NotFound:
|
||||
image = None
|
||||
if CLOUD_SERVERS_DRIVER == 'rackspace':
|
||||
Driver = get_driver(Provider.RACKSPACE)
|
||||
conn = Driver(CLOUD_SERVERS_USERNAME, CLOUD_SERVERS_API_KEY)
|
||||
|
||||
print "Searching for %s server" % SERVER_NAME
|
||||
node = [n for n in conn.list_nodes() if n.name==SERVER_NAME][0]
|
||||
|
||||
stat, out = commands.getstatusoutput("ssh %s sudo apt-get -y dist-upgrade" %
|
||||
node.public_ip)
|
||||
if stat:
|
||||
print out
|
||||
raise Exception("Unable to upgrade server")
|
||||
stat, out = commands.getstatusoutput("ssh %s sudo /etc/init.d/mysql stop" %
|
||||
node.public_ip)
|
||||
if stat:
|
||||
print out
|
||||
raise Exception("Unable to stop mysql")
|
||||
stat, out = commands.getstatusoutput("ssh %s sudo /etc/init.d/rabbitmq-server stop" %
|
||||
node.public_ip)
|
||||
if stat:
|
||||
print out
|
||||
raise Exception("Unable to stop rabbitmq")
|
||||
print "Searching for %s image" % IMAGE_NAME
|
||||
image = [img for img in conn.list_images() if img.name==IMAGE_NAME]
|
||||
if image:
|
||||
image = image[0]
|
||||
else:
|
||||
image = None
|
||||
else:
|
||||
raise Exception ("Driver not supported")
|
||||
|
||||
ip = node.public_ip[0]
|
||||
client = SSHClient()
|
||||
client.load_system_host_keys()
|
||||
client.connect(ip)
|
||||
|
||||
def run(action, x):
|
||||
stdin, stdout, stderr = client.exec_command(x)
|
||||
ret = stdout.channel.recv_exit_status()
|
||||
print stdout.read()
|
||||
print stderr.read()
|
||||
if ret:
|
||||
raise Exception("Unable to %s" % action)
|
||||
|
||||
run('update package list', 'sudo apt-get update')
|
||||
run('install packages', 'sudo DEBIAN_FRONTEND=noninteractive apt-get --option "Dpkg::Options::=--force-confold" --assume-yes install %s' % debs)
|
||||
run('upgrade server', 'sudo apt-get -y dist-upgrade')
|
||||
run('stop mysql', 'sudo /etc/init.d/mysql stop')
|
||||
run('stop rabbitmq', 'sudo /etc/init.d/rabbitmq-server stop')
|
||||
|
||||
if image:
|
||||
image.delete()
|
||||
image = compute.images.create(name=IMAGE_NAME, server=node)
|
||||
conn.ex_delete_image(image)
|
||||
|
||||
last_status = None
|
||||
image = conn.ex_save_image(node=node, name=IMAGE_NAME)
|
||||
|
||||
last_extra = None
|
||||
while True:
|
||||
if image.status != last_status:
|
||||
print
|
||||
print time.ctime(), image.status,
|
||||
last_status = image.status
|
||||
if image.status == u'ACTIVE':
|
||||
image = [img for img in conn.list_images(ex_only_active=False)
|
||||
if img.name==IMAGE_NAME][0]
|
||||
if image.extra != last_extra:
|
||||
print image.extra['status'], image.extra['progress']
|
||||
if image.extra['status'] == 'ACTIVE':
|
||||
break
|
||||
sys.stdout.write('.')
|
||||
sys.stdout.flush()
|
||||
time.sleep(1)
|
||||
image = compute.images.get(image.id)
|
||||
last_extra = image.extra
|
||||
time.sleep(2)
|
||||
|
||||
34
slave_scripts/devstack-vm-update-image.sh
Executable file
34
slave_scripts/devstack-vm-update-image.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash -xe
|
||||
|
||||
# Update the VM used in devstack deployments.
|
||||
|
||||
# Copyright (C) 2011 OpenStack LLC.
|
||||
#
|
||||
# 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.
|
||||
|
||||
CI_SCRIPT_DIR=$(cd $(dirname "$0") && pwd)
|
||||
cd $WORKSPACE
|
||||
|
||||
if [[ ! -e devstack ]]; then
|
||||
git clone https://review.openstack.org/p/openstack-dev/devstack
|
||||
fi
|
||||
cd devstack
|
||||
git remote update
|
||||
git pull --ff-only origin
|
||||
|
||||
cd $WORKSPACE
|
||||
cat devstack/files/apts/* | grep NOPRIME | cut -d\# -f1 > devstack-debs
|
||||
|
||||
$CI_SCRIPT_DIR/devstack-vm-update-image.py $WORKSPACE/devstack-debs
|
||||
Reference in New Issue
Block a user