Public/pod.ps1
|
function New-CSPod { <# .SYNOPSIS Creates a CloudStack pod. .DESCRIPTION Wraps the createPod API, adding a pod to a zone with its management/reserved IP range. The pod holds clusters and hosts within the zone. .PARAMETER Name Name for the new pod. .PARAMETER ZoneId The zone the pod is created in. .PARAMETER Gateway The gateway for the pod's reserved system IP range. .PARAMETER Netmask The netmask for the pod's reserved system IP range. .PARAMETER StartIp First address of the pod's reserved system IP range. .PARAMETER EndIp Last address of the pod's reserved system IP range. .PARAMETER AllocationState Initial allocation state: Enabled, Disabled, or Unmanaged. .EXAMPLE New-CSPod -Name 'Detroit-1A' -ZoneId zone-uuid -Gateway '10.0.0.1' -Netmask '255.255.255.0' -StartIp '10.0.0.10' Creates a pod with a reserved system IP range starting at 10.0.0.10. .EXAMPLE New-CSPod -Name 'Detroit-1B' -ZoneId $zoneId -Gateway '10.0.1.1' -Netmask '255.255.255.0' -StartIp '10.0.1.10' -EndIp '10.0.1.50' -AllocationState Disabled Creates a pod that is disabled for allocation until you enable it. #> [CmdletBinding()] param( [Parameter(Mandatory=$true)][string]$Name, [Parameter(Mandatory=$true)][string]$ZoneId, [string]$Gateway, [string]$Netmask, [string]$StartIp, [string]$EndIp, [ValidateSet('Enabled','Disabled','Unmanaged')][string]$AllocationState ) $p=@{name=$Name;zoneid=$ZoneId} foreach($k in @('Gateway','Netmask','StartIp','EndIp','AllocationState')){if($PSBoundParameters.ContainsKey($k)){$p[$k.ToLowerInvariant()]=(Get-Variable $k -ValueOnly)}} Invoke-CSApiRequest -Command createPod -Parameters $p } function Remove-CSPod { <# .SYNOPSIS Deletes a CloudStack pod. .DESCRIPTION Wraps the deletePod API. The pod must be empty (no clusters or hosts) before it can be removed. Accepts pod objects on the pipeline by their id. .PARAMETER Id The pod to delete. Binds from a piped pod's id. .EXAMPLE Remove-CSPod -Id pod-uuid Deletes a pod after prompting for confirmation. .EXAMPLE Get-CSPod -Name 'Detroit-1A' | Remove-CSPod Deletes a pod located by name. #> [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='High')] param( [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$Id ) process { if($PSCmdlet.ShouldProcess("pod $Id",'Delete')){Invoke-CSApiRequest -Command deletePod -Parameters @{id=$Id}} } } function Set-CSPod { <# .SYNOPSIS Updates a CloudStack pod. .DESCRIPTION Wraps the updatePod API. Only the attributes you supply are changed. Accepts pod objects on the pipeline by their id. .PARAMETER Id The pod to update. Binds from a piped pod's id. .PARAMETER AllocationState New allocation state: Enabled, Disabled, or Unmanaged. .PARAMETER EndIp New last address of the pod's reserved system IP range. .PARAMETER Name New name for the pod. .PARAMETER StartIp New first address of the pod's reserved system IP range. .PARAMETER Netmask New netmask for the pod's reserved system IP range. .PARAMETER Gateway New gateway for the pod's reserved system IP range. .PARAMETER Description New description for the pod. .EXAMPLE Set-CSPod -Id pod-uuid -AllocationState Enabled Enables a pod for allocation. .EXAMPLE Get-CSPod -Name 'Detroit-1A' | Set-CSPod -EndIp '10.0.0.60' Extends a pod's reserved IP range on a pod piped in by object. #> [CmdletBinding()] param( [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$Id, [string]$AllocationState, [string]$EndIp, [string]$Name, [string]$StartIp, [string]$Netmask, [string]$Gateway, [string]$Description ) process { $p=@{id=$Id} foreach($k in @('AllocationState','EndIp','Name','StartIp','Netmask','Gateway','Description')){if($PSBoundParameters.ContainsKey($k)){$p[$k.ToLowerInvariant()]=(Get-Variable $k -ValueOnly)}} Invoke-CSApiRequest -Command updatePod -Parameters $p } } function Get-CSPod { <# .SYNOPSIS Lists CloudStack pods. .DESCRIPTION Wraps the listPods API. Filter by id, name, or zone; -ShowCapacities includes each pod's capacity figures. .PARAMETER Id Filter by pod ID. .PARAMETER Name Filter by pod name. .PARAMETER ZoneId Filter by zone ID. .PARAMETER Keyword Filter by keyword. .PARAMETER AllocationState Filter by allocation state (Enabled, Disabled, Unmanaged). .PARAMETER ShowCapacities Include capacity figures for each pod. .PARAMETER ListAll List all pods the caller is allowed to see. .PARAMETER Page Page number of results to return. .PARAMETER PageSize Number of results per page. .EXAMPLE Get-CSPod -ZoneId zone-uuid -ShowCapacities Lists the pods in a zone with their capacity figures. .EXAMPLE Get-CSPod -Name 'Detroit-1A' Gets a single pod by name. #> [CmdletBinding()] param( [string]$Id, [string]$Name, [string]$ZoneId, [string]$Keyword, [string]$AllocationState, [switch]$ShowCapacities, [switch]$ListAll, [int]$Page, [int]$PageSize ) $p=@{} foreach($k in @('Id','Name','ZoneId','Keyword','AllocationState','Page','PageSize')){if($PSBoundParameters.ContainsKey($k)){$p[$k.ToLowerInvariant()]=(Get-Variable $k -ValueOnly)}} if($ShowCapacities){$p.showcapacities='true'} if($ListAll){$p.listall='true'} $r=Invoke-CSApiRequest -Command listPods -Parameters $p if($r.listpodsresponse.pod){$r.listpodsresponse.pod} } function Set-CSPodDedicated { <# .SYNOPSIS Dedicates a pod to a domain or account. .DESCRIPTION Wraps the dedicatePod API, reserving a pod so only the given domain (or -Account within it) can run instances in it. Release it again with Clear-CSPodDedicated. Accepts pod objects on the pipeline by their id. .PARAMETER PodId The pod to dedicate. Binds from a piped pod's id. .PARAMETER DomainId The domain to dedicate the pod to. .PARAMETER Account Dedicate the pod to this account within -DomainId. .PARAMETER ProjectId Dedicate the pod to this project. .EXAMPLE Set-CSPodDedicated -PodId pod-uuid -DomainId domain-uuid Dedicates a pod to a domain. .EXAMPLE Get-CSPod -Name 'Detroit-1A' | Set-CSPodDedicated -DomainId $domainId -Account 'engineering' Dedicates a pod piped in by object to one account. #> [CmdletBinding()] param( [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][Alias('Id')][string]$PodId, [Parameter(Mandatory=$true)][string]$DomainId, [string]$Account, [string]$ProjectId ) process { $p=@{podid=$PodId;domainid=$DomainId} foreach($k in @('Account','ProjectId')){if($PSBoundParameters.ContainsKey($k)){$p[$k.ToLowerInvariant()]=(Get-Variable $k -ValueOnly)}} Invoke-CSApiRequest -Command dedicatePod -Parameters $p } } function Clear-CSPodDedicated { <# .SYNOPSIS Releases a pod's dedication back to the system. .DESCRIPTION Wraps the releaseDedicatedPod API, undoing a dedication made with Set-CSPodDedicated so any account can run instances in the pod again. Accepts pod objects on the pipeline by their id. .PARAMETER PodId The pod to release. Binds from a piped pod's id. .EXAMPLE Clear-CSPodDedicated -PodId pod-uuid Releases a pod's dedication. .EXAMPLE Get-CSPodDedicated -DomainId $domainId | Clear-CSPodDedicated Releases every pod dedicated to a domain. #> [CmdletBinding()] param( [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][Alias('Id')][string]$PodId ) process { Invoke-CSApiRequest -Command releaseDedicatedPod -Parameters @{podid=$PodId} } } function Get-CSPodDedicated { <# .SYNOPSIS Lists pods dedicated to domains or accounts. .DESCRIPTION Wraps the listDedicatedPods API, showing which pods have been reserved for which accounts or domains. .PARAMETER PodId Filter by pod ID. .PARAMETER Name Filter by name. .PARAMETER ZoneId Filter by zone ID. .PARAMETER Account Filter by account name. .PARAMETER DomainId Filter by domain ID. .PARAMETER Page Page number of results to return. .PARAMETER PageSize Number of results per page. .EXAMPLE Get-CSPodDedicated -ZoneId zone-uuid Lists the dedicated pods in a zone. .EXAMPLE Get-CSPodDedicated -DomainId domain-uuid Lists the pods dedicated to a domain. #> [CmdletBinding()] param( [string]$PodId, [string]$Name, [string]$ZoneId, [string]$Account, [string]$DomainId, [int]$Page, [int]$PageSize ) $p=@{} foreach($k in @('PodId','Name','ZoneId','Account','DomainId','Page','PageSize')){if($PSBoundParameters.ContainsKey($k)){$n=$k -replace 'PodId$','podid' -replace 'ZoneId$','zoneid' -replace 'DomainId$','domainid';$p[$n.ToLowerInvariant()]=(Get-Variable $k -ValueOnly)}} $r=Invoke-CSApiRequest -Command listDedicatedPods -Parameters $p if($r.listdedicatedpodsresponse.pod){$r.listdedicatedpodsresponse.pod} } function New-CSManagementNetworkIpRange { <# .SYNOPSIS Creates a management network IP range for a pod. .DESCRIPTION Wraps the createManagementNetworkIpRange API, adding a range of management network addresses (used by system VMs) to a pod. .PARAMETER PodId The pod to add the range to. .PARAMETER StartIp First address of the range. .PARAMETER EndIp Last address of the range. .PARAMETER Netmask Netmask for the range. .PARAMETER Gateway Gateway for the range. .PARAMETER Vlan VLAN the range is on. .EXAMPLE New-CSManagementNetworkIpRange -PodId pod-uuid -StartIp 10.0.0.10 -EndIp 10.0.0.20 -Netmask 255.255.255.0 -Gateway 10.0.0.1 Adds a management network IP range to a pod. .EXAMPLE New-CSManagementNetworkIpRange -PodId $podId -StartIp 10.0.5.10 -EndIp 10.0.5.20 -Netmask 255.255.255.0 -Gateway 10.0.5.1 -Vlan 500 Adds a VLAN-tagged management network IP range. #> [CmdletBinding()] param( [Parameter(Mandatory=$true)][string]$PodId, [Parameter(Mandatory=$true)][string]$StartIp, [Parameter(Mandatory=$true)][string]$EndIp, [Parameter(Mandatory=$true)][string]$Netmask, [Parameter(Mandatory=$true)][string]$Gateway, [string]$Vlan ) $p=@{podid=$PodId;startip=$StartIp;endip=$EndIp;netmask=$Netmask;gateway=$Gateway} if($PSBoundParameters.ContainsKey('Vlan')){$p.vlan=$Vlan} Invoke-CSApiRequest -Command createManagementNetworkIpRange -Parameters $p } function Remove-CSManagementNetworkIpRange { <# .SYNOPSIS Deletes a management network IP range. .DESCRIPTION Wraps the deleteManagementNetworkIpRange API, removing a pod management network IP range by its ID. .PARAMETER Id The management network IP range to delete. .EXAMPLE Remove-CSManagementNetworkIpRange -Id range-uuid Deletes a management network IP range after prompting for confirmation. #> [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='High')] param( [Parameter(Mandatory=$true)][string]$Id ) if($PSCmdlet.ShouldProcess("management IP range $Id",'Delete')){Invoke-CSApiRequest -Command deleteManagementNetworkIpRange -Parameters @{id=$Id}} } function Set-CSManagementNetworkIpRange { <# .SYNOPSIS Updates a management network IP range. .DESCRIPTION Wraps the updatePodManagementNetworkIpRange API. Only the attributes you supply are changed. .PARAMETER Id The management network IP range to update. .PARAMETER StartIp New first address of the range. .PARAMETER EndIp New last address of the range. .PARAMETER Netmask New netmask for the range. .PARAMETER Gateway New gateway for the range. .EXAMPLE Set-CSManagementNetworkIpRange -Id range-uuid -EndIp 10.0.0.40 Extends the upper bound of a management network IP range. #> [CmdletBinding()] param( [Parameter(Mandatory=$true)][string]$Id, [string]$StartIp, [string]$EndIp, [string]$Netmask, [string]$Gateway ) $p=@{id=$Id} foreach($k in @('StartIp','EndIp','Netmask','Gateway')){if($PSBoundParameters.ContainsKey($k)){$p[$k.ToLowerInvariant()]=(Get-Variable $k -ValueOnly)}} Invoke-CSApiRequest -Command updatePodManagementNetworkIpRange -Parameters $p } |