Solving problems invented by others...
My journey to automate vCloud Director with PowerShell – part #4  : create an organization virtual datacenter

My journey to automate vCloud Director with PowerShell – part #4 : create an organization virtual datacenter

After creating an organization, the next part was to create an OrgVDC.

With the help of the New-OrgVDC commandlet, it was not really difficult to create one. (https://code.vmware.com/docs/11794/cmdlet-reference/doc/New-OrgVdc.html) You just have add name and description and references to other objects which you can easily get.

# set the parameters
$orgvdcname = "my-new-orgvdc"
$orgvdcdescription = "my first OrgVDC"

# get a reference to the pVDC
$providervdc = Get-ProviderVdc -Name "my-provider-vdc"

# get a reference to the network pool to be used.
$networkpool = Get-NetworkPool -Name "my-network-pool"

# create OrgVDC
$orgvdc = New-OrgVdc -AllocationModelPayAsYouGo -Name $orgvdcname -Description $orgvdcdescription -NetworkPool $networkpool -Org $org -ProviderVdc $providervdc -VMCpuCoreMHz ($maxcpuspeedghz * 1000)

In the above example I hardcoded to use the PayAsYouGo allocation model for the OrgVDC. If you want a different kind, you have to switch to the other two possibilities like -AllocationModelAllocationPool or -AllocationModelReservationPool.

Since the New-OrgVDC commandlet has no parameters to set the allocation limits, it has to be done after creating the OrgVDC. These settings can be found as an sub-object of the newly created OrgVDC. I’ve found the settings I needed while playing around with the Get-Member commandlet under the sub-object ExtensionData. (Which is by the way a very good source for finding such things.)

I wanted to:

  • set a cpu quota
  • set a memory quota
  • set the reserved reservations (cpu + ram) to 0%
  • limit the numbers of vms in this OrgVDC
  • activate thin provisioning
#########################
# set allocation limits #
#########################

# define the quotas
$maxcpuquotaghz = 50
$maxmemoryquotagb = 200
$maxnumberofvms = 30

# set maximum cpu capacity limit (the value has to be set a MHz)
$orgvdc.ExtensionData.ComputeCapacity.Cpu.Limit = $maxcpuquotaghz * 1000

# set maximum ram capacity limit (the value has to be set in MB)
$orgvdc.ExtensionData.ComputeCapacity.Memory.Limit = $maxmemoryquotagb * 1024

# set ram reservation to disable
$orgvdc.ExtensionData.ResourceGuaranteedMemory = 0

# set maximum number of allowed vms
$orgvdc.ExtensionData.VmQuota = $maxnumberofvms

# activate thin provisioning of vm disks
$orgvdc.ExtensionData.IsThinProvision = $true

# save changes
$orgvdc.ExtensionData.UpdateServerData()

As explained in the former blog post, these changes are made on a local copy of the ExtensionData object and had to be written back to the vCloud Director with the UpdateServerData() method.


Next article in this series:

Add and remove storage profiles

Leave a Reply

Your email address will not be published.

six × = fifty four