View
225
Download
2
Category
Tags:
Preview:
Citation preview
Turn Your XenApp and XenDesktop into Capacity on Demand with PVS Automation
Paul StanselEnterprise Infrastructure Architect
Shane O’NeillSenior Engineer – Virtual Client Engineering
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Before We Get Started…
Tweet about this session with hashtag #SYN514 and #CitrixSynergy
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Introduction
XenApp and XenDesktop PowerShell is a very capable set of tools when used correctly. Unfortunately the same can’t necessarily be said for PVS PowerShell. But when you are dealing with hundreds of streamed servers or thousands of streamed desktops, it’s nice to be able to manage them as capacity pools instead of spending all your time manually sizing them. Today we will talk about some ways to handle that.
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Who Am I?
2015 Citrix Technology Professional (CTP)Architect of multiple Fortune 100 Citrix environments18 years working with Citrix productsAuthor and editor Owner of CitrixTips.com
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Who Am I?
Senior Engineer – Virtual Client Engineering at Aetna*CCA, VCP, and MCPSupport 55,000 user XenApp and XenDesktop environment spanning 5 datacenters around the globePowerShell Scripter, C# Mad Genius, and Irish Rugby fan
* Today I am presenting in a personal capacity and not on behalf of Aetna.
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Your Takeaways Today
Why do you want a capacity on demand model?How do you treat your capacity as pools rather than silos?Monitoring your pools to provide the capacity needed. Automating the updates to gold disksCode examples for you to take and make your own.
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
What is a Capacity On Demand Model with PVS?
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
These are Silos….
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
These are Pools…
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
The problem that we faced was sprawl. With XenApp for instance it’s all too easy to keep spinning up silos of servers based on a gold disk. That means you’ve got to keep an eye on your capacity in each silo, juggle servers in case of burst usage, and most importantly overprovision your environment to avoid running out of capacity.
So we wanted something better. And something free
So Why Did We Come Up With This?
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
What’s the Plan?
Create a new poolSet minimum pool sizeMonitor the pool usageSpin up or down capacity within the pool as needed and based on thresholds we define
Sounds easy right? And it was… with a lot of hard work and Shane’s scripting magic.
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
WARNINGAll content is provided at your own risk. Please make sure to test thoroughly in your own environment before using this code in a production environment. We take no responsibility if you manage to nuke your servers, destroy your environment, or initiate a large scale user uprising that turns into the zombie apocalypse we all know is coming.
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
PVS Layout
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Infrastructure Layout
Target DeviceMachine Group
Worker Group
Published Apps
Citrix XenDesktopDelivery Group 1
Spare Devices
Delivery Group 2 Pooled VDI or
XACopyright © 2015 The Travelers Indemnity Company. All rights reserved
Flow Chart of the Capacity Process
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
When to add and remove devices?This is easy for XenDesktop, you can just query the number of active VM’s and instantly know your usage.XenApp requires a different approach as server usage will differ depending on the server specs and other considerations. A usage ratio needs to be defined for your XenApp servers in a PVS collection. That ratio will determine if the servers are over or under utilized and if resources should be added or removed from the collection.
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Determine XenApp UsageIn order to tie your XenApp servers back to your collections, you would need to organize them in Folders that correspond to your gold disks. We start by building a list of these folders that we are going to query using the XenApp PowerShell Snap-In.
static List<string> listOfServerPaths = new List<string>();listOfServerPaths.Add(“Servers\\GoldDisk01”);listOfServerPaths.Add(“Servers\\GoldDisk02”);listOfServerPaths.Add(“Servers\\GoldDisk03”);
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Determine XenApp Usageforeach (string path in listOfServerPaths){PowerShell PS = PowerShell.Create();command = “Add-PSSnapin Citrix.Xenapp.Commands” + Environment.NewLine +@”$servers = Get-XAServer -FolderPath “”” + path + @”””” + Environment.NewLine +“$sessionCount = 0″ + Environment.NewLine +“foreach($server in $servers)” + Environment.NewLine +“{$sessions = Get-XASession -ServerName $server | Where-Object {$_.State -match ‘Active’ -and $_.Protocol -match ‘ICA’}” + Environment.NewLine +“$sessionCount = $sessionCount + $sessions.count}” + Environment.NewLine + “$servers.count” + Environment.NewLine +“$sessionCount”;PS.AddScript(command);var results = PS.Invoke();int servers = int.Parse(results[0].ToString());int sessions = int.Parse(results[1].ToString());}
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
PowerShell for XenApp Usage DeterminationAdd-PSSnapin Citrix.Xenapp.Commands$servers = Get-XAServer -FolderPath $folderPath$sessionCount = 0foreach($server in $servers){$sessions = Get-XASession -ServerName $server | Where-Object {$_.State -match ‘Active’ -and $_.Protocol -match ‘ICA’}$sessionCount = $sessionCount + $sessions.count}$servers.count$sessionCount
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Usage Ratio Algorithmint minServerThreshold = 2;int sessionRatio = 20;foreach (loadResult lr in listOfResults){if (lr.servers > minServerThreshold ){double ratio = lr.sessions / (lr.servers – minServerThreshold);if (ratio < sessionRatio){double optimumNumber = Math.Ceiling(lr.sessions / sessionRatio);int serversToRemove = lr.servers – optimumNumber – minServerThreshold;}else{double optimumNumber = Math.Ceiling(lr.sessions / sessionRatio);int serversToAdd = (optimumNumber – lr.servers);}}} Copyright © 2015 The Travelers Indemnity Company. All rights reserved
The PVS PowerShell Snap-InMost Citrix administration does not require the use of PowerShell by the administrator. The PowerShell Snap-In for XenDesktop and XenApp are user friendly and easy to work with. When it comes to the PowerShell Snap-In for PVS, this is not the case. PVS PowerShell does not return objects or collections.Only returns large blocks of text which are not easy on the eye.
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
The PVS PowerShell Snap-In Cont.Being able to predict where the information that you require will be displayed in the return text and with some text manipulation, this beast can be tamed. The MCliPSSnapIn is not installed by default. %systemroot%\Microsoft.NET\Framework64\v2.0.50727\installutil.exe “C:\Program Files\Citrix\Provisioning Services Console\McliPSSnapIn.dll”
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Adding a device to a collectionGet the name of spare device in the source collection.Get the details of that spare device.Get the name of a device in the target collection.Get the vDisk details of that device.Delete the spare device from the source collection.Add the spare device to the target collection.Assign the vDisk to the spare device.Add the device to AD group/delivery group.Boot the device.
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Get the name of spare device in the source collection.string deviceName = getDeviceName(“MySourceCollection”, “MySite”);static string getDeviceName(string sourceCollection, string siteName){string result = null;PowerShell ps = PowerShell.Create();string command = “Add-PSSnapin McliPSSnapin” + Environment.NewLine +“$results = Mcli-Get Device -p CollectionName=” + sourceCollection + @”, siteName=””” + siteName + @””” -f DeviceName” + Environment.NewLine +“$results[4]”;ps.AddScript(command);var output = ps.Invoke();result = output.ToString();int splitPosition = result.IndexOf(“:”);return result.Substring(splitPosition + 2, result.Length – (splitPosition + 2));}
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
PowerShell to Get the name of spare device in the source collection.
Add-PSSnapin McliPSSnapin$results = Mcli-Get Device -p CollectionName=MySourceCollection, siteName=MySite -f DeviceName$temp = results[4]$splitPosition = $temp.IndexOf(“:”)$deviceName = $temp.SubString($splitPosition + 2, $temp.Length – ($splitPosition + 2))
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Get the details of that spare devicestatic deviceDetails getDeviceDetails(string deviceName){PowerShell ps = PowerShell.Create();string command = “Add-PSSnapin McliPSSnapin” + Environment.NewLine +“Mcli-Get Device -p DeviceName=” + deviceName + ” -f deviceMac, adtimestamp, adsignature, domainname, domainobjectsid, domaincontrollername, domaintimecreated, description”;ps.AddScript(command);var output = ps.Invoke();deviceDetails details = new deviceDetails();details.deviceMAC = formatResultString(output[4].ToString());details.deviceADTimeStamp = formatResultString(output[5].ToString());details.deviceADSignature = formatResultString(output[6].ToString());details.deviceDomainName = formatResultString(output[7].ToString());details.deviceObjectSID = formatResultString(output[8].ToString());details.deviceDomainControllerName = formatResultString(output[9].ToString());details.deviceDomainTimeCreated = formatResultString(output[10].ToString());details.description = formatResultString(output[11].ToString());return details;}
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Get the details of that spare device in PowerShellAdd-PSSnapin McliPSSnapinMcli-Get Device -p DeviceName=MyDeviceName -f deviceMac, adtimestamp, adsignature, domainname, domainobjectsid, domaincontrollername, domaintimecreated, description
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Get the name of a device in the target collection.This is the same code as that which was used in the first step except that this time we are looking at a different collection.
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Get the vDisk details of that device.static string getvDisk(string deviceName){string result = null;PowerShell ps = PowerShell.Create();string command = “Add-PSSnapin McliPSSnapin” + Environment.NewLine +$diskInfo = Mcli-Get diskinfo -p deviceName=” + deviceName + Environment.NewLine +“$diskinfo[4]”;ps.AddScript(command);var output = ps.Invoke();result = output.ToString();ps.Dispose();return formatResultString(result);}
Add-PSSnapin McliPSSnapin$diskInfo = Mcli-Get diskinfo -p deviceName=MyDeviceName –f diskLocatorId$diskinfo[4]
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Delete the spare device from the source collectionstatic bool deleteDevice(string deviceMac){PowerShell ps = PowerShell.Create();string command = “Add-PSSnapin McliPSSnapin” + Environment.NewLine +“Mcli-Delete Device -p devicemac=” + deviceMac;ps.AddScript(command);var output = ps.Invoke();if (output[2].ToString().ToUpper().Trim() == “DELETE SUCCEEDED.”){return true;}else{return false;}}
Add-PSSnapin McliPSSnapinMcli-Delete Device -p devicemac=MyDeviceMAC
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Add the spare device to the target collectionaddDevice(spareDeviceName, dDetails.deviceMAC, “MyTargetCollection”, “MySite”, dDetails.deviceADTimeStamp, dDetails.deviceADSignature, dDetails.deviceDomainName, dDetails.deviceObjectSID, dDetails.deviceDomainControllerName, dDetails.deviceDomainTimeCreated, dDetails.description)static bool addDevice(string devicename, string devicemac, string collection, string site, string adtimestamp, string adsignature, string domainname, string domainobjectsid, string domaincontrollername, string domaintimecreated, string description){PowerShell ps = PowerShell.Create();string command = “Add-PSSnapin McliPSSnapin” + Environment.NewLine +“Mcli-Add Device -r devicename=” + devicename + “, devicemac=” + devicemac + “, collectionname=” + collection + @”, sitename=””” + site + @”””, adtimestamp=” + adtimestamp + “, adsignature=” + adsignature + “, domainname=” + domainname + “, domainobjectsid=” + domainobjectsid + “, domaincontrollername=” + domaincontrollername + @”, domaintimecreated=””” + domaintimecreated + @”””,description=””” + description + @””””;ps.AddScript(command);var output = ps.Invoke();if (output[2].ToString().Substring(0, 14).ToUpper().Trim() == “ADD SUCCEEDED.”){return true;}else{return false;}}
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Add the spare device to the target collectionAdd-PSSnapin McliPSSnapinMcli-Add Device -r devicename=devicename, devicemac=devicemac, collectionname=MyTargetCollection, sitename=MySite, adtimestamp=adtimestamp, adsignature=adsignature, domainname=domainname, domainobjectsid=domainobjectsid, domaincontrollername=domaincontrollername,domaintimecreated=domaintimecreated,description=description
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Assign the vDisk to the spare device
static bool assignVDiskToServer(string deviceMac, string vdisk){PowerShell ps = PowerShell.Create();string command = “Add-PSSnapin McliPSSnapin” + Environment.NewLine +“Mcli-Run AssignDiskLocator -p deviceMac=” + deviceMac + “, diskLocatorId=” + vdisk;ps.AddScript(command);var output = ps.Invoke();if (output[2].ToString().Substring(0, 14).ToUpper().Trim() == “RUN SUCCEEDED.”){return true;}else{return false;}}
Add-PSSnapin McliPSSnapinMcli-Run AssignDiskLocator -p deviceMac=deviceMac, diskLocatorId=vdisk
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Add the device to AD Group
For XenApp 6.5, our design uses AD groups to control the membership of the Worker Group. We add the device to the AD group using some simple PowerShellTo add a VM called “Device001” to an AD group called “DeviceGroup01”:ADD-ADGroupMember “DeviceGroup01” –members “Device001$”
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Add the device to the Delivery Group
For XenDesktop and later version of XenApp, we would need to add the device to the delivery group for that collection. Add-BrokerMachine –MachineName Domain\Device001 –DesktopGroup DeliveryGroupName –AdminAddress ControllerServer
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Remove Device From Other Groups
AD Group Removal:
Remove-adgroupmember -Identity "DeviceGroup01" -Member "Device001$" Delivery Group Removal: Remove-BrokerMachine Domain\Device001 –DesktopGroup DeliveryGroupName –AdminAddress ControllerServer
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Boot the deviceThe device is production ready and can now be booted. Best to use the SDK of your underlying hypervisor to perform any required power actions. The MCliPSSnapin does have commands for performing power actions but have found them to be unreliable. Boot: Mcli-RunWithReturn BootShutdown: Mcli-Run ShutdownUsing the hypervisor SDK will ensure that actions are completed.
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Check If the Device is Upstatic bool portCheck(string device, int port){ TcpClient portCheck = new TcpClient(); portCheck.Connect(server, port); if(portCheck.Connected) { return true; } else { return false; }portCheck.Close()}
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Updating a Gold Disk
Maintenance Device
Device Collection
Maintenance Image
Production DeviceProduction
Image
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Seal The Diskstring resealCommand = @"cmd.exe /c C:\Reseal_Automated.cmd";ManagementPath run = new ManagementPath(@"\\" + vm + "\root\cimv2:Win32_process");ManagementClass man = new ManagementClass(run);Object returnValue = man.InvokeMethod("Create", new Object[] {resealCommand});man.Dispose();
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Promote the ImageAdd-PSSnapin McliPSSnapin$diskInfo = Mcli-Get diskinfo -p deviceName=Device001 –f diskLocatorId$diskID = $diskinfo[4]$splitPosition = $diskID.IndexOf(“:”)$diskID = $diskID.SubString($splitPosition + 2, $diskID.Length – ($splitPosition + 2))Mcli-Run PromoteDiskVersion -p diskLocatorId=$diskID
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Create New Maintenance DiskAdd-PSSnapin McliPSSnapin$diskInfo = Mcli-Get diskinfo -p deviceName=Device001 –f diskLocatorId$diskID = $diskinfo[4]$splitPosition = $diskID.IndexOf(“:”)$diskID = $diskID.SubString($splitPosition + 2, $diskID.Length – ($splitPosition + 2))Mcli-RunWithReturn CreateMaintenanceVersion-p diskLocatorId=$diskID
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
But wait a minute… why did you do it this way?
Because we could.
And because it’s cool.
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Oh yeah… one more thing!
There will be a better Powershell for PVS!
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Other Resources
http://citrixtips.com
http://blogs.citrix.com/2012/04/05/automating-pvs-based-virtual-desktops-with-windows-powershell/
http://support.citrix.com/static/kc/CTX127254/help/
http://support.citrix.com/article/CTX141467Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Before you leave…
Conference surveys are available online at www.citrixsynergy.com starting today at 9am. Provide your feedback by 6:00 p.m. today to be entered to win one of many prizes!
Download presentations from the CUGC site and from CitrixTips.com
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
© 2014 Citrix. Confidential.47
@mycugc www.mycugc.org
USER LED EXPERIENCE:
• Knowledge-sharing
• Training and other discounts
• Blogs, webinars and whitepapers
• Exclusive content, Geek Speak Live!
GET INVOLVED:
• Join a Local Group or SIG
• Connect with peers
• Be part of the conversation
• Access and contribute content
Synergy Booth #101
JOIN NOW!www.mycugc.org
Questions?Contact info:Paul@paulstansel.comhttp://citrixtips.com@pstansel
SasPonto@gmail.com@SasPonto
Copyright © 2015 The Travelers Indemnity Company. All rights reserved
Recommended