Background
at some commitment of recent clients I faced the problem of creating a large number (100+) of Provisioning services 6.1 XenApp 6.5 based target devices with their write cache placed on the local SSD storage of a VMware vSphere 5.1 host. One might think that this would not be a complicated task, so just make a copy of your master machine of the target device with a second disc placed on SSD storage, converting it into a model and use this model with the assistant Provisioning Services VM configuration StreamD create machines to vSphere. Easy huh? No, because I learned that the PVS wizard does not allow me to use models that include drives hosted on local storage vSphere Hypervisor. This behavior can not be changed easily.
Creating machines by hand via VMware vCenter is not possible to their high number. In addition, they must be evenly distributed on all respective hosts for Dynamic Resource Scheduling (as it is called by VMware) will not work because of local storage. Second step would be to create entries corresponding target devices in the collections of the PVS instrument which would also be time for such a large number of machines.
So when it comes to script a solution. Using three different SDKs (VMware Power CLI, MCLI Provisioning Services and PowerShell module to gain access to Active Directory management) required functionality can be achieved. Scripting the whole process also gave me the opportunity to include a step that should be done manually anyway: move workers XenApp computer objects in two Active Directory groups to monitor the XenApp machine reboot cycle. For reasons of availability, it was always expected that 50% of servers in a PVS site (two sites created for two data centers) will restart every 2 days. So dividing the XenApp machines for this type of restart behavior could also be easily reached by PowerShell scripts
The following process has been implemented :.
1. Interrogate the XenApp vSphere cluster to the host with the smallest number of VMs
2. Determine the free following name for the new virtual machine based on a defined naming convention
3. Create the virtual machine with the drive on the local SSD storage
4. Create the entry of the target device in PVS via MCLI
5. Create the computer object in active Directory common OR
6. Add the computer object for the proper restart group
Sons not complicated, but there were some things to consider that could easily be found in any other client deployment. The vSphere cluster used was a stretched cluster including hosts two data centers in an active / active configuration. To fairly distribute the target devices in the two location data centers host interviewed had to be determined. However, this could not be easily done by a host naming convention, but rather by a custom attribute vSphere client has defined for guests to view the location. So this attribute query is the only opportunity to obtain the correct location for vSphere hosts. Another challenge is to cope with Active Directory response times to create computer objects via MCLI. The following commands to add the computer object often failed to restart groups so I had to implement a short cmdlet that verifies the existence of the newly created object and pause the script as long as the subject does has not yet responded to exist.
Scripting the whole process
prerequisites that must be installed on the machine running the scripts are:
- VMware PowerCLI
- Provisioning Console services (to access MCLI commands)
- Windows Server 08R2 Feature - active Module Directory for Windows PowerShell
script is quite long, so I'll just cover some important excerpts here, you can try to fully adapt script attached below.
Query the XenApp vSphere cluster to the host with the smallest number of VMs
First, we receive all cluster hosts, sort them depending on their location (DC1 and DC2) and calculate the number of currently deployed on each host machine:
$ hosts = $ bunch | Get-VMHost connected -Etat | Select Name, @ {N = "NumVM"; E = {@ (($ _ | Get-Vm )) Count}}, {L @ = "Location";. e = {$ _. CustomFields | {$ _ Eq Key 'Location'.} | select the value -ExpandProperty}} | Sort Place HostVMsDC1 $ = $ host | or {. $ _ "DC1" -eq $ HostVMsDC2 Location} = $ host | where {$ _. "DC2" -eq Location}
is an example for the host DC1 with fewer machines on it. Based on what we need to get the name of the local database to create the virtual disk. For the request for local datastores attribute MultipleHostAccess is used which is always set to false for local datastores. $ UsedHost finally designates the host we use to create VMs DC1:
$ LeastHost = $ HostVMsDC1 | Sort NumVM | -First Select Datastore $ 1 = Get-VMHost -Name $ LeastHost.Name | Get-Datastore | ? {(. $ _ Eq Type "VMFS") -and ($ _ eq $ ExtensionData.Summary.MultipleHostAccess False.)} | Sort Name | -First Select UsedHost $ 1 = Get-VMHost -Name $ LeastHost.Name
Create the virtual machine
$ taskTab [( New-VM -Name $ vm_name -VMHost UsedHost -template $ $ $ Datastore folder template -Datastore $ -Location) .ID] = $ vm_name
After creation, we increase the counter for the number of virtual machines on that host by (we do not question the number of machines for all guests every time for performance reasons):
$ HostVMsDC1 | Where {$ _ eq $ LeastHost.Name name.} | {Foreach. $ _} ++ NumVM
We will also need the MAC address for the creation of the target device in PVS
$ MAC = Get-NetworkAdapter $ -VM vm_name | ForEach-Object {$ _ MacAddress.} | -replace% {$ _ '', "-"}
Add the target device to its collection of devices and create a computer object
Add-MCLI -r deviceName unit = $ vm_name, collectionName = $ collection = $ siteName site_1, deviceMac = $ MAC, $ description = description, copyTemplate = 1 MCLI-Run AddDeviceToDomain deviceName -p = $ vm_name, organizationUnit OR = $
Addition of 50% of each machine a different data center restart groups
the cmdlet custom test XADComputer (see attached) test scripts for the existence of an active computer object Directory. In case the object does not exist sleeps the whole script for an amount of time and continues when the object is created and finally reported to exist:
do {sleep 5 Write -Host "." Until} ( Test-XADComputer $ vm_name)
The newly created machines to a data center are also distributed to restart groups so that According to the configuration of Citrix restart policies filtered to these two groups only 50% of servers will restart every day. The Get-ADComputer and Add-PrincipalGroupMembership cmdlets are part of the Directory PowerShell module
if (vm_count $% 2) { Get-ADComputer $ -identity vm_name | Add-ADPrincipalGroupMembership $ -memberof Reboot2 Write-Host "Restart Computer object added to group $ Reboot2"} else { Get-ADComputer $ -identity vm_name | Add-ADPrincipalGroupMembership $ -memberof Reboot1 Write-Host "Restart Computer object added to group $ Reboot1"}
I hope this script can be useful if you encounter similar difficulties when implemented and show what can be achieved by taking advantage of our really powerful SDKs (and other) products 😉
here you can see the whole script, bold settings must be adapted to your environment:
@ "============ ===================================== ============= ============= ============= Title: CreateTargetDevices with disk on the local SSD storage and imports the devices in Citrix PVS Author: Thomas Fuhrmann version: 1.6 use :. CreateTargetDevices.ps1 Date: 04/06/2013 ====================================== ============ ====================================== "@
« Prev Post
Next Post »
0 Komentar