Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ME_CREDS="--os-username=$ME_OS_USERNAME \
- --os-password=$ME_OS_PASSWORD \
- --os-tenant-name=$ME_OS_TENANT_NAME \
- --os-tenant-id=$ME_OS_TENANT_ID \
- --os-auth-url=$ME_OS_AUTH_URL"
- IAD2_CREDS="--os-username=$IAD2_OS_USERNAME \
- --os-password=$IAD2_OS_PASSWORD \
- --os-tenant-name=$IAD2_OS_TENANT_NAME \
- --os-tenant-id=$IAD2_OS_TENANT_ID \
- --os-auth-url=$IAD2_OS_AUTH_URL"
- function stop_vm {
- status=$(nova $ME_CREDS show $vm --minimal | grep '^| status ' | awk '{print $4}')
- echo "Stopping ${vm}..."
- nova $ME_CREDS stop $vm
- while [[ $status != "SHUTOFF" ]]; do
- status=$(nova $ME_CREDS show $vm --minimal | grep '^| status ' | awk '{print $4}')
- sleep 10
- done
- echo "Successfully stopped $vm!"
- }
- function convert_to_image {
- volume_id=""
- status=""
- volume_id=$(nova $ME_CREDS show $vm | grep 'os-extended-volumes:volumes_attached' | cut -d\" -f4)
- if [[ $volume_id == "" ]]; then
- echo "Unable to determine backing volume (was this an ephemeral VM?)"
- exit 1
- fi
- echo "Uploading volume to image. This may take a very long time..."
- image=$(cinder $ME_CREDS upload-to-image --force True $volume_id ${vm}-snapshot | grep ' image_id ' | awk '{print $4}')
- while [[ $status != "active" ]]; do
- echo "Current status: $status"
- status=$(glance image-show $image | grep '^| status ' | awk '{print $4}')
- echo "Checking status again in 60 seconds..."
- sleep 60
- done
- }
- function download_image {
- echo "Downloading image $image from ME..."
- glance --os-image-api-version 1 $ME_CREDS image-download --file ${vm}-snapshot.raw --progress $image
- echo "Successfully downloaded $image from ME!"
- echo "Removing image snapshot $image from ME..."
- # glance $ME_CREDS image-delete $image
- echo "Successfully delete image ${image} from ME!"
- }
- function upload_image {
- new_image=""
- status=""
- echo "Uploading image $image to IAD2..."
- glance $IAD2_CREDS image-create --name ${vm}-snapshot \
- --disk-format raw \
- --visibility private \
- --container-format bare \
- --file ${vm}-snapshot.raw
- new_image=$(glance $IAD2_CREDS image-list | grep ${vm}-snapshot | awk '{print $2}')
- if [[ $new_image == "" ]]; then
- echo "New image not found (failed in image creation?)."
- exit 1
- fi
- while [[ $status != "active" ]]; do
- status=$(glance $IAD2_CREDS image-show $new_image | grep '^| status ' | awk '{print $4}')
- sleep 10
- done
- echo "Successfully uploaded image $image to IAD2"
- }
- ALL_ME_VMS=$(nova $ME_CREDS list | grep -v '^+' | sed -n '1!p' | awk '{print $2}')
- for vm in $ALL_ME_VMS; do
- echo "Begin migration of $vm from ME (yes/no)?"
- read answer
- if [[ $answer == "yes" ]]; then
- stop_vm
- convert_to_image
- download_image
- upload_image
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement