Skip to content

Instantly share code, notes, and snippets.

/gist:389967
Created May 4, 2010

Embed
What would you like to do?
#!/bin/bash
DOMAIN='wcyd.org'
#-
GOLDEN_VM='/vmfs/volumes/LUN_240/birch.${DOMAIN}/birch.${DOMAIN}.vmx'
LINKED_VM='/vmfs/volumes/LUN_240/hickory.${DOMAIN}/hickory.${DOMAIN}.vmx'
# --
GOLDEN_VM_NAME=`vmware-cmd ${GOLDEN_VM} getconfig DisplayName|awk '{print $3}'` #
LINKED_VM_NAME=$(echo ${LINKED_VM}|sed -e 's/.*\///' -e 's/\.vmx$//')
# --
GOLDEN_VM_PATH=`echo ${GOLDEN_VM%%.vmx*}`
SED_GOLDEN_VM_PATH=$(echo ${GOLDEN_VM_PATH} | sed -e 's/\//\\\//g')
LINKED_VM_PATH=`echo ${LINKED_VM%%.vmx*}`
#--
GOLDEN_STORAGE_PATH=`echo ${GOLDEN_VM%/*/*}`
LINKED_STORAGE_PATH=`echo ${LINKED_VM%/*/*}`
mkdir -p ${LINKED_STORAGE_PATH}/${LINKED_VM_NAME}
sed -e 's/displayName = "'${GOLDEN_VM_NAME}'"/displayName = "'${LINKED_VM_NAME}'"/' \
-e 's/extendedConfigFile = "'${GOLDEN_VM_NAME}.vmxf'"/extendedConfigFile = "'${LINKED_VM_NAME}.vmxf'"/' \
-e 's/scsi0:0.fileName = .*/scsi0:0.fileName = "'${SED_GOLDEN_VM_PATH}'.vmdk"/' \
-e 's/scsi0:1.fileName = .*/scsi0:1.fileName = "'${SED_GOLDEN_VM_PATH}'_1.vmdk"/' \
-e 's/nvram = "'${GOLDEN_VM_NAME}.nvram'"/nvram = "'${LINKED_VM_NAME}.nvram'"/' \
-e '/ethernet0.generatedAddress/d' -e '/uuid.location/d' -e '/uuid.bios/d' -e '/sched.swap.derivedName/d' \
${GOLDEN_VM} > ${LINKED_VM}
vmware-cmd -s register ${LINKED_STORAGE_PATH}/${LINKED_VM_NAME}/${LINKED_VM_NAME}.vmx #> /dev/null 2>&1
vmware-cmd ${LINKED_STORAGE_PATH}/${LINKED_VM_NAME}/${LINKED_VM_NAME}.vmx \
createsnapshot Cloned ${LINKED_VM_NAME}_Cloned_from_${GOLDEN_VM_NAME} # > /dev/null 2>&1
##########
# Removal
##########
# ensure 'vmware-cmd ${LINKED_VM} getstate' returns "getstate() = off"
# or /usr/bin/vmware-cmd ${LINKED_VM} stop
# vmware-cmd -s unregister ${LINKED_VM}
# Remove orphaned vm from inventory
# cd ${LINKED_STORAGE_PATH}; rm -fr ${LINKED_VM_NAME}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.