Skip to content

Instantly share code, notes, and snippets.

@JohnPreston
Created August 31, 2014 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnPreston/65b73f5f85fb6abab451 to your computer and use it in GitHub Desktop.
Save JohnPreston/65b73f5f85fb6abab451 to your computer and use it in GitHub Desktop.
Update Instance Type
#!/usr/bin/env bash
#
# This must be used with care and only knowing what you are doing.
# Eucalyptus cant be taken reponsible for bad usage of this script
#
NEWTYPE=$1
INSTANCE=$2
function check_instances()
{
INS=`euca-describe-instances verbose | grep $INSTANCE | grep INST | awk '{print $2}'`;
INS_STATE=`euca-describe-instances verbose | grep $INSTANCE | grep INST | awk '{print $6}'`;
EMI=`euca-describe-instances verbose | grep $INSTANCE | grep INST | awk '{print $3}'`;
EMI_TYPE=`euca-describe-images verbose | grep $EMI| awk '{print $9}'`
echo $INS $EMI | $EMI_TYPE;
if ! [ $EMI_TYPE == "ebs" ]; then echo "Your image must be a bf_EBS - Now exiting" ; exit 1 ; fi
if ! [ $INS_STATE == 'stopped' ]; then echo "Your instance must be in a STOPPED state - Now Exiting" ; exit 1 ; fi
}
check_instances
NEWTYPE_QY="select id from cloud_vm_type where config_vm_type_name = '$NEWTYPE';"
NEWTYPE_ID=`psql -h /var/lib/eucalyptus/db/data -p 8777 -U root eucalyptus_cloud -c "$NEWTYPE_QY"`
NEWTYPE_ID=`echo $NEWTYPE_ID | awk '{print $3}'`
UPDATE_QY="update metadata_instances set metadata_vm_type_id = '$NEWTYPE_ID' where metadata_display_name = '$INSTANCE';"
UPDATE_GO=`psql -h /var/lib/eucalyptus/db/data -p 8777 -U root eucalyptus_cloud -c "$UPDATE_QY"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment