Skip to content

Commit db6c0e8

Browse files
author
kishan
committed
Added sql queries and script to update new template and restart networks
1 parent b9183c0 commit db6c0e8

2 files changed

Lines changed: 101 additions & 3 deletions

File tree

setup/bindir/cloud-sysvmadm.in

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#set -x
66

77
usage() {
8-
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
8+
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
99
}
1010

1111

@@ -21,13 +21,15 @@ maxthreads=5
2121
LOGFILE=cloud.log
2222

2323

24-
while getopts 'sarhd:m:u:p:t:l:' OPTION
24+
while getopts 'sarhnd:m:u:p:t:l:' OPTION
2525
do
2626
case $OPTION in
2727
s) system=1
2828
;;
2929
r) router=1
3030
;;
31+
n) redundant=1
32+
;;
3133
a) all=1
3234
;;
3335
d) db="$OPTARG"
@@ -195,6 +197,86 @@ reboot_router(){
195197

196198
}
197199

200+
restart_networks(){
201+
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"`)
202+
length_networks=(${#networks[@]})
203+
204+
echo -e "\nRestarting networks... "
205+
echo -e "Restarting networks... " >>$LOGFILE
206+
207+
#Spawn restart network in parallel - run commands in <n> chunks - number of threads is configurable
208+
209+
pids=()
210+
for d in "${networks[@]}"; do
211+
212+
restart_network $d &
213+
214+
pids=( "${pids[@]}" $! )
215+
216+
length_pids=(${#pids[@]})
217+
unfinishedPids=(${#pids[@]})
218+
219+
if [ $maxthreads -gt $length_networks ]; then
220+
maxthreads=$length_networks
221+
fi
222+
223+
if [ $length_pids -ge $maxthreads ]; then
224+
while [ $unfinishedPids -gt 0 ]; do
225+
sleep 10
226+
count=0
227+
for (( i = 0 ; i < $length_pids; i++ )); do
228+
if ! ps ax | grep -v grep | grep ${pids[$i]} > /dev/null; then
229+
count=`expr $count + 1`
230+
fi
231+
done
232+
233+
if [ $count -eq $unfinishedPids ]; then
234+
unfinishedPids=0
235+
fi
236+
237+
done
238+
239+
#remove all elements from pids
240+
if [ $unfinishedPids -eq 0 ]; then
241+
pids=()
242+
length_pids=(${#pids[@]})
243+
fi
244+
245+
fi
246+
247+
done
248+
249+
250+
if [ "$length_networks" == "0" ];then
251+
echo -e "No networks found \n" >>$LOGFILE
252+
else
253+
while [ $unfinishedPids -gt 0 ]; do
254+
sleep 10
255+
done
256+
257+
echo -e "Done restarting networks. \n"
258+
echo -e "Done restarting networks. \n" >>$LOGFILE
259+
260+
fi
261+
}
262+
263+
restart_network(){
264+
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'}`
265+
if [ "$jobid" == "" ]; then
266+
echo "ERROR: Failed to restart network with id $1" >>$LOGFILE
267+
echo 2
268+
return
269+
fi
270+
271+
jobresult=$(query_async_job_result $jobid)
272+
273+
if [ "$jobresult" != "1" ]; then
274+
echo "ERROR: Failed to restart network with id $1" >>$LOGFILE
275+
else
276+
echo "INFO: Successfully restarted network with id $1" >>$LOGFILE
277+
fi
278+
279+
}
198280

199281
query_async_job_result() {
200282
while [ 1 ]
@@ -208,7 +290,7 @@ sleep 5
208290
done
209291
}
210292

211-
if [ "$system$router$all$help" == "" ]
293+
if [ "$system$router$all$help$redundant" == "" ]
212294
then
213295
usage
214296
exit
@@ -235,3 +317,8 @@ if [ "$router" == "1" ]
235317
then
236318
stop_start_router
237319
fi
320+
321+
if [ "$redundant" == "1" ]
322+
then
323+
restart_networks
324+
fi

setup/db/db/schema-229to2210.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@ ALTER TABLE `cloud`.`host` MODIFY `storage_ip_address` char(40);
1818
INSERT IGNORE INTO configuration VALUES ('Network', 'DEFAULT', 'management-server', 'network.redundantrouter', 'false', 'enable/disable redundant virtual router');
1919
INSERT IGNORE INTO configuration VALUES ('Storage', 'DEFAULT', 'management-server', 'storage.pool.max.waitseconds', '3600', 'Timeout (in seconds) to synchronize storage pool operations.');
2020
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');
21+
22+
UPDATE `cloud`.`vm_template` SET type='SYSTEM' WHERE name='systemvm-xenserver-2.2.10';
23+
UPDATE `cloud`.`vm_template` SET type='SYSTEM' WHERE name='systemvm-kvm-2.2.10';
24+
UPDATE `cloud`.`vm_template` SET type='SYSTEM' WHERE name='systemvm-vSphere-2.2.10';
25+
26+
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;
27+
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;
28+
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;
29+
30+
-- Update system Vms using systemvm-xenserver-2.2.4 template;
31+
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);

0 commit comments

Comments
 (0)