Added sql queries and script to update new template and restart networks

This commit is contained in:
kishan 2011-08-16 19:41:59 +05:30
parent b9183c0840
commit db6c0e810b
2 changed files with 101 additions and 3 deletions

View File

@ -5,7 +5,7 @@
#set -x #set -x
usage() { usage() {
printf "\nThe tool stopping/starting running system vms and domain routers \n\nUsage: %s: [-d] [-u] [-p] [-m] [-s] [-r] [-a] [-t]\n\n -d - cloud DB server ip address, defaulted to localhost if not specified \n -u - user name to access cloud DB, defaulted to "root" if not specified \n -p - cloud DB user password, defaulted to no password if not specified \n\n -m - the ip address of management server, defaulted to localhost if not specified\n\n -s - stop then start all running SSVMs and Console Proxies \n -r - stop then start all running Virtual Routers\n -a - stop then start all running SSVMs, Console Proxies, and Virtual Routers \n -t - number of parallel threads used for stopping Domain Routers. Default is 5.\n -l - log file location. Default is cloud.log under current directory.\n\n" $(basename $0) >&2 printf "\nThe tool stopping/starting running system vms and domain routers \n\nUsage: %s: [-d] [-u] [-p] [-m] [-s] [-r] [-a] [-t] [-e]\n\n -d - cloud DB server ip address, defaulted to localhost if not specified \n -u - user name to access cloud DB, defaulted to "root" if not specified \n -p - cloud DB user password, defaulted to no password if not specified \n\n -m - the ip address of management server, defaulted to localhost if not specified\n\n -s - stop then start all running SSVMs and Console Proxies \n -r - stop then start all running Virtual Routers\n -a - stop then start all running SSVMs, Console Proxies, and Virtual Routers \n -e - restart all Guest networks \n -t - number of parallel threads used for stopping Domain Routers. Default is 5.\n -l - log file location. Default is cloud.log under current directory.\n\n" $(basename $0) >&2
} }
@ -21,13 +21,15 @@ maxthreads=5
LOGFILE=cloud.log LOGFILE=cloud.log
while getopts 'sarhd:m:u:p:t:l:' OPTION while getopts 'sarhnd:m:u:p:t:l:' OPTION
do do
case $OPTION in case $OPTION in
s) system=1 s) system=1
;; ;;
r) router=1 r) router=1
;; ;;
n) redundant=1
;;
a) all=1 a) all=1
;; ;;
d) db="$OPTARG" d) db="$OPTARG"
@ -195,6 +197,86 @@ reboot_router(){
} }
restart_networks(){
networks=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select n.id from networks n, network_offerings no where n.network_offering_id = no.id and no.system_only = 0 and n.removed is null"`)
length_networks=(${#networks[@]})
echo -e "\nRestarting networks... "
echo -e "Restarting networks... " >>$LOGFILE
#Spawn restart network in parallel - run commands in <n> chunks - number of threads is configurable
pids=()
for d in "${networks[@]}"; do
restart_network $d &
pids=( "${pids[@]}" $! )
length_pids=(${#pids[@]})
unfinishedPids=(${#pids[@]})
if [ $maxthreads -gt $length_networks ]; then
maxthreads=$length_networks
fi
if [ $length_pids -ge $maxthreads ]; then
while [ $unfinishedPids -gt 0 ]; do
sleep 10
count=0
for (( i = 0 ; i < $length_pids; i++ )); do
if ! ps ax | grep -v grep | grep ${pids[$i]} > /dev/null; then
count=`expr $count + 1`
fi
done
if [ $count -eq $unfinishedPids ]; then
unfinishedPids=0
fi
done
#remove all elements from pids
if [ $unfinishedPids -eq 0 ]; then
pids=()
length_pids=(${#pids[@]})
fi
fi
done
if [ "$length_networks" == "0" ];then
echo -e "No networks found \n" >>$LOGFILE
else
while [ $unfinishedPids -gt 0 ]; do
sleep 10
done
echo -e "Done restarting networks. \n"
echo -e "Done restarting networks. \n" >>$LOGFILE
fi
}
restart_network(){
jobid=`curl -sS "http://$ms:8096/?command=restartNetwork&id=$1&response=json" | sed 's/\"//g' | sed 's/ //g' | sed 's/{//g' | sed 's/}//g' | awk -F: {'print $3'}`
if [ "$jobid" == "" ]; then
echo "ERROR: Failed to restart network with id $1" >>$LOGFILE
echo 2
return
fi
jobresult=$(query_async_job_result $jobid)
if [ "$jobresult" != "1" ]; then
echo "ERROR: Failed to restart network with id $1" >>$LOGFILE
else
echo "INFO: Successfully restarted network with id $1" >>$LOGFILE
fi
}
query_async_job_result() { query_async_job_result() {
while [ 1 ] while [ 1 ]
@ -208,7 +290,7 @@ sleep 5
done done
} }
if [ "$system$router$all$help" == "" ] if [ "$system$router$all$help$redundant" == "" ]
then then
usage usage
exit exit
@ -235,3 +317,8 @@ if [ "$router" == "1" ]
then then
stop_start_router stop_start_router
fi fi
if [ "$redundant" == "1" ]
then
restart_networks
fi

View File

@ -18,3 +18,14 @@ ALTER TABLE `cloud`.`host` MODIFY `storage_ip_address` char(40);
INSERT IGNORE INTO configuration VALUES ('Network', 'DEFAULT', 'management-server', 'network.redundantrouter', 'false', 'enable/disable redundant virtual router'); INSERT IGNORE INTO configuration VALUES ('Network', 'DEFAULT', 'management-server', 'network.redundantrouter', 'false', 'enable/disable redundant virtual router');
INSERT IGNORE INTO configuration VALUES ('Storage', 'DEFAULT', 'management-server', 'storage.pool.max.waitseconds', '3600', 'Timeout (in seconds) to synchronize storage pool operations.'); INSERT IGNORE INTO configuration VALUES ('Storage', 'DEFAULT', 'management-server', 'storage.pool.max.waitseconds', '3600', 'Timeout (in seconds) to synchronize storage pool operations.');
INSERT IGNORE INTO configuration VALUES ('Storage', 'DEFAULT', 'management-server', 'storage.template.cleanup.enabled', 'true', 'Enable/disable template cleanup activity, only take effect when overall storage cleanup is enabled'); INSERT IGNORE INTO configuration VALUES ('Storage', 'DEFAULT', 'management-server', 'storage.template.cleanup.enabled', 'true', 'Enable/disable template cleanup activity, only take effect when overall storage cleanup is enabled');
UPDATE `cloud`.`vm_template` SET type='SYSTEM' WHERE name='systemvm-xenserver-2.2.10';
UPDATE `cloud`.`vm_template` SET type='SYSTEM' WHERE name='systemvm-kvm-2.2.10';
UPDATE `cloud`.`vm_template` SET type='SYSTEM' WHERE name='systemvm-vSphere-2.2.10';
UPDATE vm_instance SET vm_template_id=(SELECT id FROM vm_template WHERE name='systemvm-xenserver-2.2.10' AND removed IS NULL) where vm_template_id=1;
UPDATE vm_instance SET vm_template_id=(SELECT id FROM vm_template WHERE name='systemvm-kvm-2.2.10' AND removed IS NULL) where vm_template_id=3;
UPDATE vm_instance SET vm_template_id=(SELECT id FROM vm_template WHERE name='systemvm-vSphere-2.2.10' AND removed IS NULL) where vm_template_id=8;
-- Update system Vms using systemvm-xenserver-2.2.4 template;
UPDATE vm_instance SET vm_template_id=(SELECT id FROM vm_template WHERE name='systemvm-xenserver-2.2.10' AND removed IS NULL) where vm_template_id=(SELECT id FROM vm_template WHERE name='systemvm-xenserver-2.2.4' AND removed IS NULL);