Timeline scripts for cirros

This commit is contained in:
Ryabin Sergey 2015-03-04 13:28:58 +03:00
parent 59f4faacc7
commit e96cc6b12e
2 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,93 @@
#!/bin/sh
#set -x
childs=""
state_cache_cleanup() {
#find . -iname ".*" -type f -delete
rm -v .network_*
}
state_name() {
echo $1 | sed 's/[^a-z0-9]/_/g;s/^/./'
}
state_save() {
echo $2 > `state_name "$1"`
}
state_get() {
local file=`state_name "$1"`
test -f $file && {
exit_code=`cat $file`
return $exit_code
}
return 255
}
state_is_change() {
state_get "$1"
local old_state=$?
local current_state=$2
local current_state_txt="true"
#echo "compare $current_state and $old_state"
if [ $current_state -ne 0 ]; then
current_state_txt="false"
current_state=1
fi
if [ $old_state -eq 255 ]; then
echo `date "+%s"` $1 null "->" $current_state_txt
return 1
fi
if [ $old_state -ne $current_state ]; then
echo `date "+%s"` $1 $old_state "->" $current_state_txt
return 1
fi
return 0
}
_do_run() {
local description="$1"
shift
run_cmd=$*
while :; do
$run_cmd > /dev/null 2>&1
new_state=$?
#echo $run_cmd $new_state
state_is_change "$description" $new_state
state_save "$description" $new_state
sleep 1
done
}
do_run() {
name="$1"
shift
_do_run "$name" $* &
childs="$childs $!"
}
state_cache_cleanup
while [ -n "$*" ]; do
do_run "network avialability ${1}" ping -c3 -W2 $1
shift
done
is_run=1
trap "is_run=''" 2 15
while [ ! -z "$is_run" ] ; do
sleep 1;
done
for child in $childs; do
echo stop child $child
kill -9 $child
done

View File

@ -0,0 +1,15 @@
#!/bin/sh
set -ex
export SSH_ARGS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
#echo 'select floating_ip_address from floatingips;' | mysql -s neutron | xargs -P5 -I% sh -c "sshpass -p'cubswin:)' scp cirros_timeline* $SSH_ARGS cirros@% id || :"
floating_ip=`echo "select floating_ip_address from floatingips;" | mysql -s neutron | tr "\n" " "`
cat<<EOF > cirros_timeline_wrapper.sh
#!/bin/sh
sh /home/cirros/cirros_timeline.sh $floating_ip > /home/cirros/output.txt 2>&1 &
EOF
echo -n $floating_ip | xargs -d" " -P5 -I% sh -c "sshpass -p'cubswin:)' scp $SSH_ARGS cirros_timeline* cirros@%: || :"
echo -n $floating_ip | xargs -d" " -P5 -I% sh -c "sshpass -p'cubswin:)' ssh $SSH_ARGS cirros@% sh ./cirros_timeline_wrapper.sh"