Skip to content

Instantly share code, notes, and snippets.

@jkapusi
Created September 20, 2017 19:13
Show Gist options
  • Save jkapusi/ee4afedc9e78c538bdd183b4109b2f20 to your computer and use it in GitHub Desktop.
Save jkapusi/ee4afedc9e78c538bdd183b4109b2f20 to your computer and use it in GitHub Desktop.
Mass migration of softlayer vms to new hosts
#!/bin/bash
TYPE=${1:-server}
while :; do
VSID=`slcli virtual list --columns id,hostname,pendingMigrationFlag | grep "$TYPE" | grep True | head -1 | cut -d ' ' -f1`;
if [[ -n "$VSID" ]]; then
echo "Next item to migrate: $VSID"
slcli vs detail "$VSID"
slcli call-api Virtual_Guest migrate "--id=$VSID"
if [[ "$?" -eq "0" ]]; then
echo "Waiting for the migration to complete..."
while :; do
sleep 5
STATE=`slcli vs detail "$VSID" | grep active_transaction | awk '{print $2}'`
if [ "$STATE" = "NULL" ]; then
echo "Migration finished"
break
else
echo "Current state: $STATE"
fi
done
fi
else
echo "No vs found to migrate"
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment