The following batch script was created to automate the creation of a Workstation vApp. The vapprun command is called due to it also consisting of a batch file. This script (VAPP.cmd) creates two VM’s on the fly. Virtual Machines must be present before vApp creation.
VAPP.cmd:
—
@ ECHO OFF
rem # VAPPRUN TESTING SCRIPT
rem # — Set Variables –
set VAPP=TESTAVAPP
set VM1=TESTAVM1
set VM2=TESTAVM2
rem # Set Disk size in GB
set DISK=5
rem # — END Set Variables –
rem # — Start Creation –
rem # Create vAPP Container
echo Initializing vAPP Container called %VAPP%
call vapprun init
rem # Create or Link VM with VMDK Disk
echo Creating %VM1%
call vapprun create-vm %VM1% “disk=%DISK%”
rem # Create or Link VM with VMDK Disk
echo Creating %VM2%
call vapprun create-vm %VM2% “disk=%DISK%”
rem # Create vAPP Instance
echo Creating vAPP called %VAPP%
call vapprun create-vapp %VAPP%
rem # Link VM to vAPP Instance
echo Linking %VM1% to vAPP Container %VAPP%
call vapprun edit %VM1% “parent=%VAPP%”
rem # Link VM to vAPP Instance
echo Linking %VM2% to vAPP Container %VAPP%
call vapprun edit %VM2% “parent=%VAPP%”
rem # List VM / vAPP status
call vapprun list
rem # Set Startup Order
call vapprun edit %VM1% “startOrder=10″ “startWait=10″ “waitForTools=True” “stopWait=10″
rem # Set Startup Order
call vapprun edit %VM2% “startOrder=20″ “startWait=10″ “waitForTools=True” “stopWait=10″
rem # Start vAPP and VM Guests in Workstation
echo Starting Composite vAPP “%VAPP%”
call vapprun start -gui %VAPP%
rem # List VM / vAPP Status
call vapprun list
The following script illustrates how the vApprun command ‘links’ to VM’s to allow them to become part of the vApp via the path to .vmx files:
VAPPLNK.cmd:
—
@ ECHO OFF
rem # VAPPRUN TESTING SCRIPT
rem # — Set Variables –
set VAPP=TESTAVAPP
set VM1=TESTAVM1
set VM2=TESTAVM2
rem # — Linked VM Variables –
set VM1LINKPATH=”vmx=.\WindowsServer2008R2x64\WindowsServer2008R2x64.vmx”
set VM2LINKPATH=”vmx=.\WindowsServer2008R2x64.2\WindowsServer2008R2x64.vmx”
rem # — END Set Variables –
rem # — Start Creation –
rem # Create vAPP Container
echo Initializing vAPP Container called %VAPP%
call vapprun init
rem # Create or Link VM with VMDK Disk
echo Creating %VM1%
.\src\vapprun.py link-vm %VM1% %VM1LINKPATH%
rem # Create or Link VM with VMDK Disk
echo Creating %VM2%
.\src\vapprun.py link-vm %VM2% %VM2LINKPATH%
rem # Create vAPP Instance
echo Creating vAPP called %VAPP%
call vapprun create-vapp %VAPP%
rem # Link VM to vAPP Instance
echo Linking %VM1% to vAPP Container %VAPP%
call vapprun edit %VM1% “parent=%VAPP%”
rem # Link VM to vAPP Instance
echo Linking %VM2% to vAPP Container %VAPP%
call vapprun edit %VM2% “parent=%VAPP%”
rem # List VM / vAPP status
call vapprun list
rem # Set Startup Order
call vapprun edit %VM1% “startOrder=10″ “startWait=10″ “waitForTools=True” “stopWait=10″
rem # Set Startup Order
call vapprun edit %VM2% “startOrder=20″ “startWait=10″ “waitForTools=True” “stopWait=10″
rem # Start vAPP and VM Guests in Workstation
echo Starting Composite vAPP “%VAPP%”
call vapprun start -gui %VAPP%
rem # List VM / vAPP Status
call vapprun list
—-
As illustrated, vApps may be created in batch to ensure repeatability and testing.