Edit detail for vmware revision 2 of 2

1 2
Editor: rgouveia
Time: 2010/05/17 12:07:17 GMT+2

-from: http://www.jedi.be/blog/2009/03/10/automated-creation-of-vmware-server-virtual-machines/


from: http://www.jedi.be/blog/2009/03/10/automated-creation-of-vmware-server-virtual-machines/

Check if registered
To verify is there isn't a virtual machine already listed with our name, you can check the registered VM's
# vmrun -T server -h https://localhost:8333/sdk -u $VMWARE_USER -p $VMWARE_PASSWORD listRegisteredVM

Stop the virtual Machine
If there is one registered, stop it before we will scratch it.
# vmrun -T server -h https://localhost:8333/sdk -u $VMWARE_USER -p $VMWARE_PASSWORD stop "[standard] $VM_NAME/$VM_NAME.vmx"

Unregister the Virtual Machine
Remove it from the inventory
# vmrun -T server -h https://localhost:8333/sdk -u $VMWARE_USER -p $VMWARE_PASSWORD stop "[standard] $VM_NAME/$VM_NAME.vmx"

Add remote management
To enable the remote display of a virtual machine we set the correct VNC port , so when the machine boots we can access it on VNC_PORT
# echo 'RemoteDisplay.vnc.enabled = "True"' >> "$VMWARE_PATH/$VM_NAME/$VM_NAME.vmx" # echo 'RemoteDisplay.vnc.password = "$VNC_PASSWORD" >> "$VMWARE_PATH/$VM_NAME/$VM_NAME.vmx" # echo 'RemoteDisplay.vnc.port = "'$VNC_PORT'"' >> "$VMWARE_PATH/$VM_NAME/$VM_NAME.vmx"

Ignore altered UID
Vmware has a way of detecting changes to virtual machines by using uuid's. For more details see http://communities.vmware.com/thread/189294
In the VM_TEMPLATE we had:
uuid.location = "56 4d 71 ec 89 ef d7 7a-c5 6a d5 e2 8d ec 91 dd" uuid.bios = "56 4d 71 ec 89 ef d7 7a-c5 6a d5 e2 8d ec 91 dd" vc.uuid = "52 ae 03 1b 89 41 c3 06-9f 1a 7c 35 f8 fc 3b 30"
If we would boot our machine, the startup would hang, asking you to confirm the following:
msg.uuid.altered:This virtual machine may have been moved or copied. In order to configure certain management and networking features VMware Server needs to know which. Did you move this virtual machine, or did you copy it? If you don't know, answer "I copied it".
# echo 'uuid.action = "create"' >> "$VMWARE_PATH/$VM_NAME/$VM_NAME.vmx" # echo 'msg.autoAnswer = "TRUE"' >> "$VMWARE_PATH/$VM_NAME/$VM_NAME.vmx"

Register the new virtual machine # vmrun -T server -h https://localhost:8333/sdk -u $VMWARE_USER -p $VMWARE_PASSWORD register "[standard] $VM_NAME/$VM_NAME.vmx"

Start the new virtual machine
# vmrun -T server -h https://localhost:8333/sdk -u $VMWARE_USER -p $VMWARE_PASSWORD start "[standard] $VM_NAME/$VM_NAME.vmx" 

Remove the previous files
remove and recreate the files in the Virtual Machine location = VMWARE_PATH
# rm -rf "$VMWARE_PATH/$VM_NAME" # mkdir -p "$VMWARE_PATH/$VM_NAME"

Re-create the virtual disk
First thing to recreate is the disk with disksize $DISK_SIZE and with the controller type that matches the VMX file we created.
# vmware-vdiskmanager  -c -s $DISK_SIZE -a $DISK_CONTROLLER -t 0 "$VMWARE_PATH/$VM_NAME/$VM_NAME.vmdk"
$DISK_Controller has to correspond to the controller in the VMX. lsilogic for centos
"qemu-img" can be used as alternative, but it does not have an option to specify the controller type

Fix the Mac Addres
When you make a standard VMX, vmware assigns a self generated mac-address. In order to have the machine respond to the PXE-boot, we need to fix the mac address by removing the ethernet0.autogeneratedAddress and setting the addressType to 'static'.
The valid range for Mac-Addresses is : 00:50:56:00:00:00   -   00:50:56:3f:ff:ff
See http://sanbarrow.com/vmx/vmx-network-advanced.html for more detail.
We will get the mac-address from another source where the names and mac-addresses are managed. In our case we get it from the cobbler inventory
# MAC_ADDRESS=$(cobbler report --what=systems  --name=$VM_NAME | grep "mac address" | cut -d ':' -f 2-| sed -e 's/^ //'g)
# cat $VM_TEMPLATE | grep -v "ethernet0.addressType"| grep -v "ethernet0.generatedAddress" > "$VMWARE_PATH/$VM_NAME/$VM_NAME.vmx" # echo 'ethernet0.addressType = "static"' >> "$VMWARE_PATH/$VM_NAME/$VM_NAME.vmx" # echo 'ethernet0.address = "'$MAC_ADDRESS'"' >> "$VMWARE_PATH/$VM_NAME/$VM_NAME.vmx"

from: http://www.jedi.be/blog/2009/03/10/automated-creation-of-vmware-server-virtual-machines/