My last blog post on Citrix Octoblu got me thinking about how we could leverage Octoblu to Automatically Build Master Images on a schedule or on demand.
So in this post I’m going to show you how to do exactly that using my Automation Framework which is part of my xenapptraining.com membership site.
The lab used for this test is Citrix XenServer 7.0 You’ll need to install Citrix XenCenter and Citrix XenServer SDK on the same machine which host the Octoblu Connector.
To make things simple, I’ve created a VM template without a network card and set it to boot on MDTProduction_x64.iso. After 60 seconds (when the deployment has started) I unmount & mount BDM.iso which will establish the contact with my Provisioning Server.
That’s how the vDisk Master Image will be created 100% automatically.
The script below has been added to Profile.ps1 located in the folder C:\Windows\System32\WindowsPowerShell\v1.0 as a function which again is called from Octoblu.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
function vWS16PVS { $XS_mst = “192.168.2.11” $XS_usr = “root” $XS_pwd = “P@ssw0rd” import-module XenServerPSModule connect-xenserver -url http://$XS_mst -username $XS_usr -password $XS_pwd -SetDefaultSession $Template = Get-XenVM -Name "MDT Template 32GB" $VMName = "WS16PVS-MI" $Network = "Internal" $MAC = "06:91:c9:1d:20:06" $ISO = "BDM.iso" Invoke-XenVM $Template -XenAction Clone -NewName $VMName -Async -PassThru | Wait-XenTask -ShowProgress Invoke-XenVM $VMName -XenAction Provision -Async -PassThru | Wait-XenTask -ShowProgress $VM = Get-XenVM -Name $VMName $NET = Get-XenNetwork -name $Network New-XenVIF -VM $VM -Network $NET -Device "0" -MAC $MAC Invoke-XenVM -VM $VM -XenAction Start Start-Sleep -s 60 CD "C:\Program Files (x86)\Citrix\XenCenter\" .\xe.exe -s $XS_mst -u $XS_usr -pw $XS_pwd vm-cd-eject vm=$VMName .\xe.exe -s $XS_mst -u $XS_usr -pw $XS_pwd vm-cd-insert cd-name=$ISO vm=$VMName # LOOP UNTIL VM IS SHUTDOWN # DELETE VM } |
The hardest part was to find out how to easily eject the ISO image through PowerShell SDK. Well I didn’t, so I used the xe.exe command instead.
This and much much more will be taught in my 3 day Automation Framework Workshop around the world next year.
Stay tuned and remember Be the Automator NOT the Automated!