Déplacement des fichiers depuis eole-one-singlenode

This commit is contained in:
2014-11-13 10:06:16 +01:00
commit 7a3f95db42
15 changed files with 2638 additions and 0 deletions

116
scripts/onehost_create_all Executable file
View File

@ -0,0 +1,116 @@
#!/usr/bin/env bash
#
# Register all Hâpy Cluster Nodes
#
. /usr/lib/eole/ihm.sh
#
# NAME: copy_ssh_id
# AIM: Copy the ssh key on the host
# PARAM: the hostname of the node
#
function copy_ssh_id()
{
local ip=${1}
su - ${ONEUSER} -c "ssh-copy-id ${ip}"
}
#
# NAME: register_node
# AIM: register the node in OpenNebula master
# PARAM: the node hostname
#
function register_node()
{
cmd="onehost create -i kvm -v kvm -n ovswitch -c \"$(CreoleGet one_cluster_name)\" ${1}"
ret=$(su - ${ONEUSER} -c -- "${cmd}")
return $?
}
#
# NAME: wait_node_ok
# AIM: Wait until the node is OK or ERROR
# PARAM: The node name
#
function wait_node_ok()
{
local RET=0
local cmd="onehost show ${1} | awk '/^STATE/ {print \$3}'"
local spinstr='|/-\'
local delay=0.75
while [ 1 ]
do
st=$(su - ${ONEUSER} -c "${cmd}")
[[ ${st} == "MONITORED" ]] && break
[[ ${st} == '' ]] && break
if [[ ${st} == "ERROR" ]]
then
RET=2
break
fi
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
return ${RET}
}
#
# MAIN
#
HAPY_ACTIF=$(echo $(CreoleGet activer_onesinglenode))
if [[ $HAPY_ACTIF == "non" ]]
then
EchoRouge "Le serveur de virtualisation n'est pas activé dans l'interface de configuration du module"
exit 1
fi
HAPY_NODE_SUPPORT=$(echo $(CreoleGet activer_multinode))
if [[ $HAPY_NODE_SUPPORT == "non" ]]
then
EchoRouge "Le mode multi-noeuds n'est pas activé dans l'interface de configuration du module"
exit 1
fi
declare -a HAPY_SLV=('')
declare -a HAPY_SLV_IP=('')
ONEUSER=$(CreoleGet virt_user)
HAPY_SLV=$(echo $(CreoleGet one_nodes) | sed -e "s/\n/ /g")
HAPY_SLV_IP=$(echo $(CreoleGet node_ip) | sed -e "s/\n/ /g")
echo -e "\n"
EchoBleu "Vous allez inscrire un noeud dans une grappe Hâpy"
EchoBleu "Pour ce faire vous devez vous munir du mot de passe de l'utilisateur 'oneadmin' de chacun des noeuds"
Question_ouinon "Voulez-vous commencer ?" 'True' "oui"
if [[ $? -ne 0 ]]
then
EchoOrange "Abandon de l'enregistrement"
exit 1
fi
for ((i = 0; i < ${#HAPY_SLV[*]}; i +=1))
do
echo -e "\n"
EchoOrange "Traitement du noeud ${HAPY_SLV[${i}]}"
echo
EchoVert " * Gestion des clés SSH"
echo
copy_ssh_id ${HAPY_SLV_IP[${i}]}
EchoVert " * Enregistrement du noeud"
register_node ${HAPY_SLV[${i}]}
wait_node_ok ${HAPY_SLV[${i}]}
if [[ ${?} -ne 0 ]]
then
EchoRouge "Erreur lors de l'enregistrement du noeud ${HAPY_SLV[${i}]} !"
fi
done
echo -e "\n"
EchoVert "Enregistrement des noeuds terminé"

181
scripts/onevm-all Executable file
View File

@ -0,0 +1,181 @@
#!/usr/bin/env ruby
##############################################################################
# Environment Configuration
##############################################################################
ONE_LOCATION=ENV["ONE_LOCATION"]
USER=ENV["user"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
end
$: << RUBY_LIB_LOCATION
##############################################################################
# Required libraries
##############################################################################
require 'opennebula'
require 'optparse'
include OpenNebula
MAXWAIT=60
INTERVAL=1
def _wait(vm, st)
wait = 0
while vm.status != st
vm.info
if vm.status == 'unkn'
break
end
wait += INTERVAL
sleep(INTERVAL)
if wait >= MAXWAIT
break
end
end
end
def CreoleGet(variable)
begin
value = `CreoleGet #{variable}`
return value
rescue
return nil
end
end
#
# NAME: _do_suspend
# PARAM: OpenNebula::VirtualMachine object
# AIM: Suspend a virtual machine
#
def _do_suspend(vm, wait)
if vm.status == "runn"
puts("Suspending #{vm.name} ...")
vm.suspend
if wait
_wait(vm, "susp")
end
end
end
#
# NAME: _do_resume
# PARAM: OpenNebula::VirtualMachine object
# AIM: Resum a suspended virtual machines
#
def _do_resume(vm, wait)
if vm.status == "susp"
puts("Resume on #{vm.name}")
vm.resume
elsif vm.status == 'unkn'
puts("Boot on #{vm.name}")
vm.boot
else
return -1
end
if wait
_wait(vm, "runn")
end
end
options = {:creds => nil, :action => nil, :endpoint => nil}
parser = OptionParser.new do|opts|
opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
opts.on('-c', '--creds file', 'Crediential file') do |value|
options[:creds] = value;
end
opts.on('-a', '--action action', 'Action to run') do |value|
options[:action] = value;
end
opts.on('-e', '--end-point url', 'End point URL') do |value|
options[:endpoint] = value;
end
opts.on('-w', '--wait', 'Wait for action ends') do |w|
options[:wait] = w
end
opts.on('-h', '--help', 'Displays Help') do
puts opts
exit
end
end
parser.parse!
# OpenNebula credentials
if not options[:creds]
options[:creds] = "/var/lib/one/.one/one_auth"
end
if not options[:action]
options[:action] = "status"
end
if not options[:endpoint]
ip = CreoleGet('adresse_ip_eth0').chomp
options[:endpoint] = "http://#{ip}:2633/RPC2"
end
# Actions
SUPPORTED = ['status', 'boot', 'resume', 'shutdown', 'suspend']
if not SUPPORTED.include?(options[:action])
puts("Action : #{options[:action]}) is not supported")
exit -1
end
begin
File.readlines(options[:creds]).each do |line|
CREDENTIALS = line
end
rescue
puts("#{options[:creds]}: Problem loading credentials, check if file exists.")
exit -1
end
begin
client = Client.new(CREDENTIALS, options[:endpoint])
vm_pool = VirtualMachinePool.new(client, -1)
rc = vm_pool.info
if OpenNebula.is_error?(rc)
puts rc.message
exit -1
end
vm_pool.each do |vm|
case options[:action]
when "status"
puts("#{vm.name}\t#{vm.status}")
when "boot"
if vm.status == "unkn"
puts("Booting #{vm.name} ...")
vm.boot
end
when "suspend"
_do_suspend(vm, options[:wait])
when "resume"
_do_resume(vm, options[:wait])
else
puts("#{vm.name}\t#{vm.status}")
end
end
rescue Exception => e
puts e.message
exit -1
end
exit 0