Problem/ definition:
To automatically deploy a virtual XenApp6 on a XenServer (Pool) you have to use 2 different consoles. (XenCenter and Altiris)
XenCenter
- Virtual machine (cover) has to be created via XenCenter (CPU, RAM
- Assign an display name
- Create a hard disk
- Add a network interface card (NIC) and select the network the VM is connected
- Assign a MAC address
- Change boot order to network boot
Deployment Console
- Create a new computer
- Define a computer name as created in XenCenter
- Define MAC address as assigned in XenCenter
- Create a job which installs the OS and XenApp6
The goal was to do this via the Deployment Server Console with a single job containing multiple tasks.
Solution
Prerequisites:
- Windows 2003 or up with PowerShell 2.0 installed
- Symantec Deployment Solution v6.9sp4 or newer installed
- PXE Server and DHCP Server Running Correctly in your environment
- XenServer SDK for PowerShell installed and registered(*) on the Deployment Server
Link:
XenServer SDK for PowerShell http://community.citrix.com/cdn/xs/sdks/
(*)
To check if the PowerShell CmdLets are successfully registered:
PS> Get-PSSnapIn –registered
Name : XenServerPSSnapIn
PSVersion : 2.0
Description: Citrix XenServer PowerShell SnapIn
Steps:
- Windows PowerShell on Deployment Server
- Install Citrix XenServer PowerShell SDK
- Create a folder below the Deployment Server eXpress share “.\scripts\XenServer\”
- Place file “XenCreateXA.ps1” into folder (see below)
Deployment Console
- Create a new computer
- Define a computer name using the Token %COMPNAME%
- Define MAC address using the Token %USER_NAME%
- Define Storage Location using the Token %SITE%
- Define Home Server using the Token %PROD_LIC%
- Add %XENSRVUSER% and %XENSRVPWD% to the Altiris eXpress database, table dbo.user_tokens
(These values are the connection details for the XenServer pool master)
- Create a job within the Task to create the VM on the XenServer using the PowerShell script attached in this Article following by the XENAPP6 install job (as shown in the Screenshot)
Create a new computer
VM properties: VM name, MAC, home server
Modify the properties
VM property: storage location of VM-disk
The essential data are stored in the Express database:
%XENSRVUSER% = user to connect to pool master XenServer
%XENSRVPWD% = password to connect to pool master XenServer
PowerShell Script: XenCreateXA.ps1
#-------------------------------------------------------------------------------------------
# (c) 04/2011 Thomas.Subotitsch@x-tech.at
# Script to create an empty VM for XenApp (requires Citrix XenServer SDK for PowerShell installed)
# v1.0 Initial version
# v1.1 Pool aware version
#-------------------------------------------------------------------------------------------
$ErrorActionPreference="Stop"
#------------ variable section START -------------------------------------------------------
# VM Info
$HOMESERVER= "%PROD_LIC%" # XenServer the VM should reside on
$VM_NAME= "%COMPNAME%" # VM name (display name in XenCenter, not hostname)
$VM_NAME_DESCRIPTION="XenApp $VM_NAME" # long description of VM
$VM_MEMORY= 8 # 8 for 8 GB
#VM_MAC= "00:00:00:00:00:01" # leave empty for random MAC
$VM_MAC= "%USER_NAME%" # leave empty for random MAC
$VM_ETH= "Network 0" # "Pool-wide network associated with eth0", "Network 0"
$SRDISK_NAME= "%SITE%" # name of the Storage repository to place VM_DISK
$VM_DISKSIZE= 60 # 60 for 60 GB
$VM_BOOT_ORDER= "nc" # Boot order: DVD(d),Network(n),C-Drive(c) (e.g. dnc, nc, nd, ...)
#------------ variable section END ---------------------------------------------------
#--- XenServer Pool-Master connection data ---------------------------------------------------------------
$user = "% XENSRVUSER %" # Pool-Master username
$password = "% XENSRVPWD %" # Pool-Master password
$server = " http://192.168.0.1" # Pool-Master FQDN, name, IP as web-address
#--- XenServer connection data end -----------------------------------------------------------
$VM_MEMORY=$VM_MEMORY*1024*1024*1024
$VM_DISKSIZE=$VM_DISKSIZE*1024*1024*1024
function checkForPSSnapins ()
{
Write-Host "Verifying PowerShell snapin..."
#Check if the snapin is installed AND registered properly.
if(Get-PSSnapin -Name "XenServerPSSnapIn" -Registered -ErrorAction SilentlyContinue){
#If the snapin is not loaded, load it.
if (!(Get-PSSnapin "XenServerPSSnapIn" -ErrorAction SilentlyContinue))
{
Write-Host "-- Loading XenServerPSSnapIn."
Add-PSSnapin XenServerPSSnapIn
}
}
else{
Write-Host "-- Citrix XenServerPSSnapIn is not installed/registered on this machine."
Write-Host "-- Download The XenServer SDK for PowerShell from: http://www.community.citrix.com/cdn/xs/sdks"
Write-Host "-- Script will now exit."
exit
}
}
checkForPSSnapins
# connect to your XenServer (must be Pool Master !!!)
$XS=Connect-xenserver `
-Url $server `
-UserName $user `
-Password $password
If (!$?) {break}
# create the VM with the necessary parameters
"vm-create: $VM_NAME"
$VM=Create-XenServer:VM `
-NameLabel "$VM_NAME" `
-NameDescription "$VM_NAME_DESCRIPTION" `
-VCPUsMax 2 `
-VCPUsAtStartup 2 `
-MemoryStaticMin 134217728 `
-MemoryStaticMax $VM_MEMORY `
-MemoryDynamicMin $VM_MEMORY `
-MemoryDynamicMax $VM_MEMORY `
-HVMShadowMultiplier 4 `
-HVMBootPolicy "BIOS order" `
-HVMBootParams @{order=$VM_BOOT_ORDER;}
# set VM affinity
Set-XenServer:VM.Affinity -VM $vmname -Affinity $homeserver
# Set CPU Flags
$PLATFORM=Get-XenServer:VM.Platform -VM $VM.UUID
$PLATFORM.set_item("nx","true")
$PLATFORM.set_item("viridian","true")
$PLATFORM.set_item("acpi","true")
$PLATFORM.set_item("pae","true")
$PLATFORM.set_item("apic","true")
Set-XenServer:VM.Platform -VM $VM.UUID -Platform $PLATFORM
# locating Storage Repository on Homeserver
" locating SR $SRDISK_NAME on $HOMESERVER"
$PBD=Get-XenServer:Host.PBDs -host $HOMESERVER|Where-Object {((Get-XenServer:SR.NameLabel -SR $_.SR) -eq "$SRDISK_NAME") -and ((Get-XenServer:SR.Type -SR $_.SR) -eq "lvm")}
# Create a virtual disk
" create virtual disk"
$VDI=Create-XenServer:VDI -NameLabel "$VM_NAME" -NameDescription "System disk for $VM_NAME" -SR $PBD.SR -virtualsize $VM_DISKSIZE
# Connect virtual disk to VM
" connect virtual disk to VM"
$VBD_DISK=Create-XenServer:VBD -VM "$VM_NAME" -VDI "$VM_NAME" -Userdevice "0" -type disk -mode RW
# Create VM network interface
" attaching $VM_NAME to $VM_ETH"
if ($VM_MAC -eq „“)
{
" creating NIC without predefined MAC"
$VIF=Create-XenServer:VIF -VM "$VM_NAME" -Network "$VM_ETH" -device "0"
}
else
{
" creating NIC with predefined MAC"
$VIF=Create-XenServer:VIF -VM "$VM_NAME" -Network "$VM_ETH" -device "0" -MAC "$VM_MAC"
}
# Create CD-ROM drive
" create CD-ROM drive"
$VBD_CD=Create-XenServer:VBD -VM "$VM_NAME" -VDI "xs-tools.iso" -Userdevice "1" -Type "CD" -mode RO -Userdevice "hdd" -Empty 1
# Power on VM
" power on VM"
Invoke-XenServer:VM.Start -VM "$VM_NAME"
Altiris Job:
Add a job
REM Replacetoken in Powershell Script for creating a Virtual Machine
REM Replacetoken .\scripts\XenServer\XenCreateXA.ps1 .\temp\%ID%_XenCreateXA.ps1
Click “Next”
With this option enabled the PowerShell script will be executed locally and creates an empty VM at the XenServer.
Click “Finish”
Summary
The PowerShell script which runs on the Deployment Server simplifies the deployment effort of a new virtual XenApp6 server dramatically. Only one console has to be used. The possibility of doing something wrong (e.g. typos between XenCenter and Deployment Server Console) are reduced to the minimum/erased. The only negative point is that we have to misuse various fields in the computer object properties of the Deployment Console.
Greetings,
-Thomas