Skip to content

Instantly share code, notes, and snippets.

@jhrcz
Created January 17, 2014 13:18
Show Gist options
  • Save jhrcz/8473237 to your computer and use it in GitHub Desktop.
Save jhrcz/8473237 to your computer and use it in GitHub Desktop.
there are some situations, when after incorrectly finished vm migration in opennebula. there are two last history reasons as 'none' (0) and this causes that opennebula does not allow next live migration. this is first try to catch the problem early and not at the migration moment.
#!/bin/bash
[ "$DEBUG" = "YES" ] \
&& set -x
qverbose ()
{
[ "$VERBOSE" = "YES" ] \
&& return 0 || return 1
}
list_running_vmids ()
{ # none
onevm list --xml \
| xmlstarlet sel -t -m '/VM_POOL/VM' -v 'ID' -n
}
get_vmid_history_count ()
{ # 1: vmid
onevm show --xml $1 \
| xmlstarlet sel -t -m '/VM/HISTORY_RECORDS/HISTORY' -v 'SEQ' -n \
| grep -v '^$' \
| tail -n 1
}
get_vmid_history_last_two_reasons ()
{ # 1: vmid
onevm show --xml $1 | xmlstarlet sel -t -m '/VM/HISTORY_RECORDS/HISTORY' -v 'REASON' -n | grep -v '^$' | tail -n 2
}
list_running_vmids | while read vmid
do
[ -n "$vmid" ] || continue
qverbose \
&& echo "# $vmid"
last_vm_history_record=""
last_vm_history_record=$( get_vmid_history_count "$vmid" )
# list last two history reasons for vm, get rid of the none/0 states
# if there is nothing left, last two were none/0 and this looks like a problem
non_none_reasons=""
if [ "$last_vm_history_record" -gt "1" ]
then
non_none_reasons=$( get_vmid_history_last_two_reasons $vmid | grep -v '^0$' )
if [ -z "$non_none_reasons" ]
then
echo "ERROR: there is double-none in history for vmid $vmid" >&2
else
echo "OK: vmid $vmid is ok"
fi
else
echo "OK: vmid $vmid is ok, has short history"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment