Provisionierte XenApp Server automatisch erzeugen

Haben wir uns nicht alle über den XenDesktop Setup Wizard gefreut? Aber ja, sicher!
Es ist schon beeindruckend, wie schnell man damit etliche VMs für den Einsatz als XenDesktop VDAs erzeugen kann. Aber was ist mit provisionierten Terminalservern? Für XenApp bietet sich die Bereitstellung als provisionierte VM aus vielen Gründen an: einfaches Patchmanagement, flexible Skalierung, exakt gleiche Server (fordern wir doch seit Jahren) und abwaschbare Server - kein Profil, kein ActiveX-Plugin, kein korrupter Druckjob überlebt nun einen Reboot. Die alte Redensart "Reboot tut gut" besaß niemals mehr Wahrheit.
Leider erfordert der Einsatz des XenDesktop Setup Wizards einen DDC - ich kenne Systemhäuser, die zum raschen Erzeugen vieler XA-VMs einen DDC aufsetzen oder als VM mitbringen, nur um den XD Setup Wizard benutzen zu können. Dabei wird die Erstellung virtueller Desktop-VMs lediglich vorgegaukelt um folgende Arbeitsschritte automatisiert ablaufen lassen zu können:

  1. Erstellen mehrerer Kopien einer Template VM auf dem XenServer
  2. Eintragen der generierten MAC Adressen als Target Device in die PVS DB
  3. Fortlaufend nummerierte Namen generieren und passende AD Konten anlegen
Ich stelle diese Schritte als Batch-Datei in diesem Blog-Eintrag zur Verfügung, vielleicht rettet es ja jemandem den Tag :-) Schließlich lässt sich hiermit nicht nur ein XenApp erzeugen, sondern auch spontan eine Horde von Webservern für einen Lasttest, eine Armee von provisionierten VDAs für XenDesktop 5 oder einfach nur viele identische VMs für welchen Zweck auch immer.
Voraussetzung für den Einsatz der "xacreator.bat" ist die Ausführung auf einem System, auf dem sowohl XenCenter, als auch die PVS Console installiert sind. Die Pfade zur xe.exe und mcli.exe müssen am Anfang der Batch-Datei ggf. angepasst werden.
Ganz sicher müssen IP,Username und Password für den XenServer-Zugriff angepasst werden - ich weise nur dezent darauf hin, dass Klartext-Passwörter in einer Batch-Datei ein Risiko darstellen. Wisst ihr schon? Sicher.
Bekannt sein muss ferner der Name eines Templates, einer PVS Site und einer PVS Collection.

Hier ist nun das Skript, wie immer als copy&paste taugliche Batch-Datei (passt durch jede Firewall, in jede Zwischenablage und kann per Email versendet werden - sprengt nur jedesmal leider das hübsche Layout):


@echo off
rem ### contact daniel.wipperfuerth@adn.de for info / improvements.
echo ######
echo ### script to create provisioned XenApp servers as VMs in
echo ### XenServer and target devices in PVS and computer accounts
echo ### in AD as well.
echo ######
echo.
setlocal
rem ### declaring windows specific variables
rem ### you should customize these
set pass=Password1
set host=192.168.88.21
set user=root
set xecmd="c:\program files (x86)\citrix\xencenter\xe.exe"
set xeparms=-s %host% -u %user% -pw %pass%
set mclicmd="C:\Program Files\Citrix\Provisioning Services\mcli.exe"

rem ### check if programs are available
if not exist %xecmd% goto :noxecmd
if not exist %mclicmd% goto :nomclicmd

rem ### ask some stuff
:gettemplatename
echo Tell me the name of your XA PVS template
echo and please respect that it has to be cAsE sENsitIVE
echo and no spaces are allowed inside
set /P xapvstempname=Enter XA PVS template name:
if "%xapvstempname%"=="" (goto :noxapvstempname)

:gettemplateuuid
for /F "usebackq" %%n in (`%xecmd% %xeparms% template-list name-label^=%xapvstempname% --minimal`) do set xapvstempuuid=%%n
if "%xapvstempuuid%"=="" (goto :noxapvstempuuid)
echo I received %xapvstempuuid% as XA PVS Template UUID.

:getxaprefixname
echo.
set /P xaprefix=Tell me a prefix for the new XAs:
if "%xaprefix%"=="" (goto :noxaprefix)

:gethowmany
set /P howmany=How many XAs do you want to create:
if "%howmany%"=="" (goto :nohowmany)

:getpadding
set /P padding=How many zeros shall we use for padding? (01=1, 0001=4):
if "%padding%"=="" (goto :nopadding)

:getpvssite
echo.
echo Tell me the name of the PVS Site that you want
echo the new XAs to be added to. This name MUST NOT
echo contain spaces.
set /P pvssite=Which PVS site should we add the XAs to? :
for /F "usebackq skip=4 tokens=2" %%n in (`%mclicmd% get site /p sitename^=%pvssite% /f siteid`) do set pvssiteuuid=%%n
if "%pvssiteuuid%"=="" (goto :nopvssiteuuid)
echo I received %pvssiteuuid% as PVS site UUID.

:getpvscollection
echo.
echo Tell me the name of the PVS collection that the
echo new XAs will be added to. This name MUST NOT
echo contain spaces.
set /P pvscollection=Which PVS collection should we add the XAs to? :
for /F "usebackq skip=4 tokens=2" %%n in (`%mclicmd% get collection /p siteid^=%pvssiteuuid% collectionname^=%pvscollection% /f collectionid`) do set pvscollectionuuid=%%n
if "%pvscollectionuuid%"=="" (goto :nopvscollectionuuid)
echo I received %pvscollectionuuid% as PVS collection UUID.

rem ### Point of no return
echo.
echo Everything seems fine so far, i am going to create
echo %howmany% copies of the XenServer VM template %xapvstempname%
echo and add them with their new MAC addresses to PVS collection
echo %pvscollection% in site %pvssite% including active directory
echo computer accounts.
echo.
echo THIS IS YOUR LAST CHANCE TO QUIT.
choice /c qc /m "Quit or Continue"
if not errorlevel 2 goto :end


rem ### do some stuff
FOR /L %%m IN (1,1,%howmany%) DO (
set s=%%m
call :padding
)
goto :end

:padding
call set padded=%%s:~%padding%,1%%
if "%padded%"=="" set s=0%S%& goto :padding
call :xacreator %s%
goto :EoF

rem ### this is the main routine
:xacreator
echo ________________________________
echo Starting cycle %1 of %howmany%
echo ________________________________
for /F "usebackq" %%n in (`%xecmd% %xeparms% vm-install new-name-label^=%xaprefix%%1 template^=%xapvstempuuid%`) do set newxauuid=%%n
echo i created the vm %xaprefix%%1 with uuid %newxauuid%
for /F "usebackq" %%n in (`%xecmd% %xeparms% vif-list vm-uuid^=%newxauuid% params^=MAC --minimal`) do set newmac=%%n
echo the new mac is %newmac%
set mclimac=%newmac::=-%
%mclicmd% add device /r devicename=%xaprefix%%1 devicemac=%mclimac% collectionid=%pvscollectionuuid% siteid=%pvssiteuuid% copytemplate=1
%mclicmd% run adddevicetodomain -p devicename=%xaprefix%%1
goto :EoF
goto :end


rem ### here are the catchpoints if information is missing
:noxapvstempname
echo No XA PVS Template name entered, sorry.
choice /c ra /m "Retry or Abort"
if not errorlevel 2 goto :gettemplatename
goto :end

:noxapvstempuuid
echo No XA PVS Template UUID received, sorry.
choice /c ra /m "Retry or Abort"
if not errorlevel 2 goto :gettemplatename
goto :end

:noxaprefix
echo No XA prefix entered, sorry.
choice /c ra /m "Retry or Abort"
if not errorlevel 2 goto :getxaprefixname
goto :end

:nohowmany
echo No number of machines to create entered, sorry.
choice /c ra /m "Retry or Abort"
if not errorlevel 2 goto :gethowmany
goto :end

:nopadding
echo No number of zeros for padding entered, sorry.
choice /c ra /m "Retry or Abort"
if not errorlevel 2 goto :getpadding
goto :end

:nopvssiteuuid
echo No uuid for the PVS site you entered received, sorry.
choice /c ra /m "Retry or Abort"
if not errorlevel 2 goto :getpvssite
goto :end

:nopvscollectionuuid
echo No uuid for the PVS collection you entered received, sorry.
choice /c ra /m "Retry or Abort"
if not errorlevel 2 goto :getpvscollection
goto :end

:noxecmd
echo I cannot find your xe.exe - please specify location in this batch file.
echo Verify if XenCenter is installed on this machine...
goto :end

:nomclicmd
echo I cannot find your mcli.exe - please specify location in this batch file.
echo Verify if PVS Console is installed on this machine...
goto :end

rem ### This is the end, my friend.
:end
echo.
echo Done. Press any key to exit.
pause



Kommentare

Beliebte Posts aus diesem Blog

Auf NFS Shares mit Windows zugreifen

Citrix Default Passwords

Lokales ISO Repository im XenServer anlegen