Skip to content

Instantly share code, notes, and snippets.

@chelnak
Last active September 27, 2016 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelnak/863c61425685e87ca060f27295c3dafa to your computer and use it in GitHub Desktop.
Save chelnak/863c61425685e87ca060f27295c3dafa to your computer and use it in GitHub Desktop.
Creating reservations with PowervRA - This gist contains examples for creating vSphere and vCloud Air reservations
# --- Create a vCloud Air Reservation
# --- Get the compute resource id
$ComputeResource = Get-vRAReservationComputeResource -Type "vCloud Air" -Name "uk-slough-1-6 - VDC1 (vCloud Air)"
# --- Get the network definition
$NetworkDefinitionArray = @()
$Network1 = New-vRAReservationNetworkDefinition -Type "vCloud Air" -ComputeResourceId $ComputeResource.Id -NetworkPath "isolated-network"
$NetworkDefinitionArray += $Network1
# --- Get the storage definition
$StorageDefinitionArray = @()
$Storage1 = New-vRAReservationStorageDefinition -Type "vCloud Air" -ComputeResourceId $ComputeResource.Id -Path "Standard" -ReservedSizeGB 500 -Priority 0
$StorageDefinitionArray += $Storage1
$Param = @{
Type = "vCloud Air"
Name = "vCA-Reservation-GB"
Tenant = "Tenant01"
BusinessGroup = "Default Business Group[Tenant01]"
ReservationPolicy = "ReservationPolicy01"
Priority = 0
ComputeResourceId = $ComputeResource.Id
Quota = 0
MemoryGB = 50
Storage = $StorageDefinitionArray
Network = $NetworkDefinitionArray
EnableAlerts = $False
EmailBusinessGroupManager = $False
AlertRecipients = "user1@vsphere.local", "user2@vsphere.local"
}
New-vRAReservation @Param
# --- Create a vSphere Reservation
# --- Get the compute resource id
$ComputeResource = Get-vRAReservationComputeResource -Type vSphere -Name "Cluster01 (vCenter)"
# --- Get the network definition
$NetworkDefinitionArray = @()
$Network1 = New-vRAReservationNetworkDefinition -Type vSphere -ComputeResourceId $ComputeResource.Id -NetworkPath "VM Network" -NetworkProfile "TestProfile"
$NetworkDefinitionArray += $Network1
# --- Get the storage definition
$StorageDefinitionArray = @()
$Storage1 = New-vRAReservationStorageDefinition -Type vSphere -ComputeResourceId $ComputeResource.Id -Path "Datastore01" -ReservedSizeGB 10 -Priority 0
$StorageDefinitionArray += $Storage1
$Param = @{
Type = "vSphere"
Name = "Reservation20"
Tenant = "Tenant01"
BusinessGroup = "Default Business Group[Tenant01]"
ReservationPolicy = "ReservationPolicy01"
Priority = 0
ComputeResourceId = $ComputeResource.Id
Quota = 0
MemoryGB = 20
Storage = $StorageDefinitionArray
Resourcepool = "Resources"
Network = $NetworkDefinitionArray
EnableAlerts = $true
StorageAlertPercentageLevel = 20
EmailBusinessGroupManager = $true
AlertRecipients = "user1@vsphere.local", "user2@vsphere.local"
}
New-vRAReservation @Param
# --- Create Multiple vCloud Air Reservations
1..10 | % {
# --- Set the reservation name
$ReservationName = "PowervRA-vCA-Reservation$($_)"
Write-Output "Creating $($ReservationName)"
# --- Get the compute resource id
$ComputeResource = Get-vRAReservationComputeResource -Type "vCloud Air" -Name "uk-slough-1-6 - VDC1 (vCloud Air)"
# --- Get the network definition
$NetworkDefinitionArray = @()
$Network1 = New-vRAReservationNetworkDefinition -Type "vCloud Air" -ComputeResourceId $ComputeResource.Id -NetworkPath "isolated-network"
$NetworkDefinitionArray += $Network1
# --- Get the storage definition
$StorageDefinitionArray = @()
$Storage1 = New-vRAReservationStorageDefinition -Type "vCloud Air" -ComputeResourceId $ComputeResource.Id -Path "Standard" -ReservedSizeGB 500 -Priority 0
$StorageDefinitionArray += $Storage1
$Param = @{
Type = "vCloud Air"
Name = $ReservationName
Tenant = "Tenant01"
BusinessGroup = "Default Business Group[Tenant01]"
ReservationPolicy = "Test01"
Priority = 0
ComputeResourceId = $ComputeResource.Id
Quota = 0
MemoryGB = 50
Storage = $StorageDefinitionArray
Network = $NetworkDefinitionArray
EnableAlerts = $False
EmailBusinessGroupManager = $False
AlertRecipients = "cgumbley@vsphere.local", "jmedd@vsphere.local"
}
New-vRAReservation @Param
}
# --- Create Multiple vSphere Reservations
1..10 | % {
# --- Set the reservation name
$ReservationName = "PowervRA-vSphere-Reservation$($_)"
Write-Output "Creating $($ReservationName)"
# --- Get the compute resource id
$ComputeResource = Get-vRAReservationComputeResource -Type vSphere -Name "Cluster01 (vCenter)"
# --- Get the network definition
$NetworkDefinitionArray = @()
$Network1 = New-vRAReservationNetworkDefinition -Type vSphere -ComputeResourceId $ComputeResource.Id -NetworkPath "VM Network" -NetworkProfile "TestProfile"
$NetworkDefinitionArray += $Network1
# --- Get the storage definition
$StorageDefinitionArray = @()
$Storage1 = New-vRAReservationStorageDefinition -Type vSphere -ComputeResourceId $ComputeResource.Id -Path "Datastore01" -ReservedSizeGB 10 -Priority 0
$StorageDefinitionArray += $Storage1
$Param = @{
Type = "vSphere"
Name = $ReservationName
Tenant = "Tenant01"
BusinessGroup = "Default Business Group[Tenant01]"
ReservationPolicy = "ReservationPolicy01"
Priority = 0
ComputeResourceId = $ComputeResource.Id
Quota = 0
MemoryGB = 20
Storage = $StorageDefinitionArray
Resourcepool = "Resources"
Network = $NetworkDefinitionArray
EnableAlerts = $true
StorageAlertPercentageLevel = 20
EmailBusinessGroupManager = $true
AlertRecipients = "user1@vsphere.local", "user2@vsphere.local"
}
New-vRAReservation @Param
}
@spiyacy
Copy link

spiyacy commented Sep 27, 2016

I tried this code for creating a reservation for a vsphere object on my vRA 7.0.1 environment, but got the following error. It's worth noting that I ran this from a workstation on a different network, not sure if that matters.

Invoke-RestMethod : {"errors":[{"code":10101,"message":"Invalid argument.","systemMessage":"Illegal GUID format null","moreInfoUrl":null}]}
At C:\Program Files\Microsoft Application Virtualization\Client\PowervRA\Functions\Public\Invoke-vRARestMethod.psm1:109 char:25

  • ... $Response = Invoke-RestMethod -Method $Method -Headers $Headers -Uri ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Any thoughts??

Here's the code I attempted to run.

--- Get the compute resource id

$ComputeResource = Get-vRAReservationComputeResource -Type vSphere -Name "vccls1 (vcenter1.nebe.local)" -verbose

--- Get the network definition

$NetworkDefinitionArray = @()
$Network1 = New-vRAReservationNetworkDefinition -Type vSphere -ComputeResourceId $ComputeResource.Id -NetworkPath "NetPath1" -NetworkProfile "192.168.0.1" -verbose
$NetworkDefinitionArray += $Network1

--- Get the storage definition

$StorageDefinitionArray = @()
$Storage1 = New-vRAReservationStorageDefinition -Type vSphere -ComputeResourceId $ComputeResource.Id -Path "Storage01" -ReservedSizeGB 10 -Priority 0 -verbose
$StorageDefinitionArray += $Storage1

$Param = @{

Type = "vSphere"
Name = "A-Test"
Tenant = "vsphere.local"
BusinessGroup = "Test Group"
ReservationPolicy = "ReservationPolicy01"
Priority = 1
ComputeResourceId = $ComputeResource.Id
Quota = 0
MemoryGB = 20
Storage = $StorageDefinitionArray
Resourcepool = "RP1"
Network = $NetworkDefinitionArray
EnableAlerts = $true
StorageAlertPercentageLevel = 20
EmailBusinessGroupManager = $true

}

New-vRAReservation @param -verbose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment