[bonfiredemokit] View of /virt-cluster/build-client.rb
View of /virt-cluster/build-client.rb
Parent Directory
| Revision Log
Revision 17 -
( download)
( annotate)
Tue Oct 9 16:14:55 2012 UTC
(11 years, 10 months ago)
by agomez
File size: 4556 byte(s)
#
# BonFIRE Virtual Clusters on Federated Clouds Demonstration Kit
#
# Copyright (c) Fundacion Centro Tecnologico de Supercomputacion de Galicia 2012
#
# License Apache Software
#
# The research leading to these results has received funding from
# the European Community's Seventh Framework Programme (FP7/2007-2013)
# under agreement number 257386
#
# This software is provided with ABSOLUTELY NO WARRANTY
#
require 'rubygems'
require 'restfully'
require 'restfully/addons/bonfire'
##Editable parameters
#LOCATION = "de-hlrs"
LOCATION = "fr-inria"
#LOCATION = "uk-epcc"
##
EXPERIMENT_NAME = "Build image client"
EXPERIMENT_DESCRIPTION = "Build image client for virtual cluster."
EXPERIMENT_WALLTIME = 3600
IMAGE_NAME = "BonFIRE Debian Squeeze 2G v3"
NEW_IMAGE_DESCRIPTION = "VirtualCluster Client image."
WAN_NAME = "BonFIRE WAN"
session = Restfully::Session.new(
:configuration_file => "~/.restfully/api.bonfire-project.eu",
:cache => false,
:gateway => "ssh.fr-inria.bonfire-project.eu",
:keys => ["~/.ssh/id_rsa"]
)
session.logger.level = Logger::INFO
#session.logger.level = Logger::DEBUG
NEW_IMAGE_NAME = "VirtualClusterClient-#{session.config[:username]}-v0.1"
experiment = nil
begin
session.logger.info "Deploying experiment..."
experiment = session.root.experiments.submit(
:name => EXPERIMENT_NAME,
:description => EXPERIMENT_DESCRIPTION + " - " + Time.now.to_s,
:walltime => EXPERIMENT_WALLTIME
)
location = session.root.locations[:"#{LOCATION}"]
session.logger.info "Chosen location is: #{location['name']}"
fail "Can't select the machine location" if location.nil?
session.logger.info "Deleting previous version"
storage = location.storages.find{|s| s["name"] == NEW_IMAGE_NAME}
storage.delete unless storage.nil?
session.logger.info "Launching machine..."
machine = experiment.computes.submit(
:name => "machine-experiment#{experiment['id']}",
:instance_type => "small",
:disk => [{:storage => location.storages.find{|s| s['name'] == IMAGE_NAME}}],
:nic => [
{:network => location.networks.find{|n| n['name'] == WAN_NAME}}
],
:location => location,
:context => {}
)
hostname = "#{machine['name']}-#{machine['id']}"
session.logger.info "Machine: #{hostname} #{machine['nic'][0]['ip']}"
session.logger.info "Starting experiment..."
experiment.update(:status => "running")
session.logger.info "Checking if machine is ready..."
until [machine].all?{|vm|
vm.reload['state'] == 'RUNNING' && vm.ssh.accessible?
} do
fail "Machine has failed" if [machine].any?{|vm| vm['state'] == 'FAILED'}
session.logger.info "Machine is not ready. Waiting..."
sleep 20
end
session.logger.info "Machine is ready"
machine.ssh do |ssh|
session.logger.info "Preinstallation..."
output = ssh.scp.upload!('killproc.sh', '/root/')
session.logger.info output unless output.nil?
session.logger.info "Installing software..."
output = ssh.exec!("apt-get update
apt-get install -y -q nfs-common
apt-get autoclean
mkdir -p /root/vc
mkdir -p /shared
echo 'source /etc/default/bonfire' >> /root/.bashrc
sed '2 i\ sleep 5' /etc/rc.local > /tmp/rc.local
sed -i '2 i\ sleep 5' /etc/rc.local
sed -i '2 i\ /root/killproc.sh &' /etc/rc.local
sed -i '/^exit/ i\ nohup python -u /root/vc/vc-node-init.py /var/log/vc-node-init.log &' /etc/rc.local
chmod 755 /etc/rc.local
chmod u+x /root/killproc.sh")
session.logger.info output unless output.nil?
session.logger.info "Uploading Virtual Cluster scripts..."
output = ssh.exec!("mkdir -p /root/vc")
session.logger.info output unless output.nil?
Dir.glob("vc/*.py").each do |file|
output = ssh.scp.upload!(file, '/root/vc/')
session.logger.info output unless output.nil?
end
end
session.logger.warn "Image installation finished"
session.logger.warn "Saving image and shutting down"
machine.update(:disk => [{:save_as => {:name => NEW_IMAGE_NAME}}])
machine.update(:state => 'SHUTDOWN')
until machine.reload['state'] == 'DONE' do
session.logger.info "Machine is #{machine['state']}."
sleep 20
end
experiment.delete
session.logger.info "Image built: #{NEW_IMAGE_NAME}"
session.logger.warn "Experiment terminated!"
rescue Exception => e
session.logger.error "#{e.class.name}: #{e.message}"
session.logger.error e.backtrace.join("\n")
session.logger.warn "Cleaning up in 30 seconds. Hit CTRL-C now to keep your VMs..."
sleep 30
experiment.delete unless experiment.nil?
end
|