Created
June 5, 2024 04:28
-
-
Save fenar/6319ccf32210ef5019c5f16757caee07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Sample Script for VM migration betweek Openstack Deployments | |
# This is for inspiration purposes, use it wisely. | |
# Variables | |
SOURCE_OS_AUTH_URL="http://source-openstack:5000/v3" | |
SOURCE_OS_PROJECT_NAME="source_project" | |
SOURCE_OS_USERNAME="source_user" | |
SOURCE_OS_PASSWORD="source_password" | |
SOURCE_IMAGE_ID="source_image_id" | |
DEST_OS_AUTH_URL="http://destination-openstack:5000/v3" | |
DEST_OS_PROJECT_NAME="dest_project" | |
DEST_OS_USERNAME="dest_user" | |
DEST_OS_PASSWORD="dest_password" | |
IMAGE_NAME="migrated_image" | |
FLAVOR_ID="dest_flavor_id" | |
NETWORK_ID="dest_network_id" | |
VM_NAME="migrated_vm" | |
# Source OpenStack environment | |
export OS_AUTH_URL=$SOURCE_OS_AUTH_URL | |
export OS_PROJECT_NAME=$SOURCE_OS_PROJECT_NAME | |
export OS_USERNAME=$SOURCE_OS_USERNAME | |
export OS_PASSWORD=$SOURCE_OS_PASSWORD | |
# Stop the VM | |
openstack server stop $VM_NAME | |
# Export the VM image | |
openstack image save --file /tmp/$IMAGE_NAME.img $SOURCE_IMAGE_ID | |
# Destination OpenStack environment | |
export OS_AUTH_URL=$DEST_OS_AUTH_URL | |
export OS_PROJECT_NAME=$DEST_OS_PROJECT_NAME | |
export OS_USERNAME=$DEST_OS_USERNAME | |
export OS_PASSWORD=$DEST_OS_PASSWORD | |
# Upload the VM image | |
openstack image create --file /tmp/$IMAGE_NAME.img $IMAGE_NAME | |
# Launch the VM on the destination | |
openstack server create --flavor $FLAVOR_ID --image $IMAGE_NAME --network $NETWORK_ID $VM_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment