ClcControl.psm1
<#
.Description Collection of functions to interact with CenturyLink Cloud Control API v1 and v2. .Tags CenturyLink CenturyLinkCloud ClcControl ClcControlAPIv1 ClcControlAPIv2 .FileList ClcControl.psm1 ClcControl.psd1 .FunctionsToExport New-DynamicParameter New-ClcControlApi1Session New-ClcControlApi2Session Invoke-ClcControlApi1 Invoke-ClcControlApi2 .Author Dmitry Gancho .LicenseUri https://opensource.org/licenses/CDDL-1.0 .ProjectUri https://github.com/dgancho/PowerShell/tree/master/ClcControl .HelpInfoUri https://www.ctl.io/api-docs/v2/ .PowerShellVersion 5.0 .ReleaseNotes Initial release .ModuleVersion 1.0.0.1 .Notes # Publish $key = Import-Credential -FriendlyName NuGet -EntryName APIKey Publish-Module -Name ClcControl -NuGetApiKey $key #> #Requires -Version 5 Using Namespace System.Diagnostics.CodeAnalysis # DataCenter list: used in Invoke-ClcControlApi1/2 $script:DataCenterList = @( 'AU1' 'CA1' 'CA2' 'CA3' 'DE1' 'GB1' 'GB3' 'IL1' 'NE1' 'NY1' 'SG1' 'UC1' 'UT1' 'VA1' 'VA2' 'WA1' ) function New-DynamicParameter { <# .SYNOPSIS Create a dynamic parameter to use in DynamicParam {} scriptblock. .DESCRIPTION Create RuntimeDefinedParameter object for RuntimeDefinedParameterDictionary. Must be called from DynamicParam {} scriptblock of an advanced function. Begin {} and/or Process {} and/or End {} scriptblocks are mantatory in function body. See example for usage details. .EXAMPLE # New-DynamicParameter in an advanced function. function Test-DynamicParameter { [CmdletBinding()] Param ( [Parameter()] [string]$StaticStringParameter, [Parameter()] [switch]$StaticSwitchParameter ) DynamicParam { # create array of dynamic parameters $parameters = @( New-DynamicParameter -Name DynamicStringParameter New-DynamicParameter -Name DynamicSwitchParameter -Type ([switch]) ) # add dynamic parameters to dictionary object and return it $dictionary = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary $parameters.ForEach{$dictionary.Add($_.Name,$_)} $dictionary } End { # create named variables from dictionary of dynamic parameters to use them as usual $dictionary.Values.ForEach{Set-Variable -Name $_.Name -Value ($_.Value -as $_.ParameterType) -Force} # return variable names and values Get-Variable -Name *Parameter -Scope Local } } .NOTES Author : Dmitry Gancho Last edit : 2/18/2017 #> [CmdletBinding()] param ( [Parameter(Mandatory, Position = 0)] [ValidateNotNullOrEmpty()] [string]$Name, [Parameter()] [ValidateNotNullOrEmpty()] [string[]]$Alias, [Parameter()] [ValidateNotNullOrEmpty()] [type]$Type = [string], [Parameter()] [AllowEmptyString()] [string]$ParameterSetName, [Parameter()] [byte]$Position, [Parameter()] [ValidateNotNullOrEmpty()] [string]$HelpMessage, [Parameter()] [ValidateNotNullOrEmpty()] [string]$HelpMessageBaseName, [Parameter()] [ValidateNotNullOrEmpty()] [string]$HelpMessageResourceId, [Parameter()] [AllowNull()] [AllowEmptyString()] [AllowEmptyCollection()] [object]$DefaultValue, [Parameter()] [ValidateCount(2,2)] [int[]]$ValidateCount, [Parameter()] [ValidateCount(2,2)] [int[]]$ValidateLength, [Parameter()] [ValidateNotNullOrEmpty()] [string]$ValidatePattern, [Parameter()] [ValidateNotNullOrEmpty()] [scriptblock]$ValidateScript, [Parameter()] [Alias('values')] [AllowEmptyString()] [string[]]$ValidateSet, [Parameter()] [ValidateCount(2,2)] [object[]]$ValidateRange, [Parameter()] [switch]$AllowNull, [Parameter()] [switch]$AllowEmptyString, [Parameter()] [switch]$AllowEmptyCollection, [Parameter()] [switch]$Mandatory, [Parameter()] [switch]$ValueFromPipeline, [Parameter()] [switch]$ValueFromPipelineByPropertyName, [Parameter()] [switch]$ValueFromRemainingArguments, [Parameter()] [switch]$DontShow, [Parameter()] [switch]$ValidateNotNull, [Parameter()] [switch]$ValidateNotNullOrEmpty ) # create attribute collection object $collection = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute] # set Mandatory to $false if [switch]$Help is set in caller scope $mandatoryValue = if ( (Test-Path -Path Variable:Help) -and $Help -is [switch] -and $Help.IsPresent ) { $false } else { $Mandatory.IsPresent } # create Parameter attribute and set [bool] properties $attribute = New-Object -TypeName System.Management.Automation.ParameterAttribute -Property @{ Mandatory = $mandatoryValue ValueFromPipeline = $ValueFromPipeline.IsPresent ValueFromPipelineByPropertyName = $ValueFromPipelineByPropertyName.IsPresent ValueFromRemainingArguments = $ValueFromRemainingArguments.IsPresent DontShow = $DontShow.IsPresent } # set other Parameter attribute properties @( 'Position' 'ParameterSetName' 'HelpMessage' 'HelpMessageBaseName' 'HelpMessageResourceId' ).Where{ $PsBoundParameters.ContainsKey($_) }.ForEach{ $attribute.$_ = Get-Variable -Name $_ -ValueOnly } # add attribute to collection $collection.Add($attribute) # add other attributes if provided @( if ($PsBoundParameters.ContainsKey('Alias')) { New-Object -TypeName System.Management.Automation.AliasAttribute -ArgumentList $Alias } if ($AllowEmptyCollection.IsPresent) { New-Object -TypeName System.Management.Automation.AllowEmptyCollectionAttribute } if ($AllowEmptyString.IsPresent) { New-Object -TypeName System.Management.Automation.AllowEmptyStringAttribute } if ($AllowNull.IsPresent) { New-Object -TypeName System.Management.Automation.AllowNullAttribute } if ($PsBoundParameters.ContainsKey('ValidateCount')) { New-Object -TypeName System.Management.Automation.ValidateCountAttribute -ArgumentList $ValidateCount } if ($PsBoundParameters.ContainsKey('ValidateLength')) { New-Object -TypeName System.Management.Automation.ValidateLengthAttribute -ArgumentList $ValidateLength } if ($ValidateNotNull.IsPresent) { New-Object -TypeName System.Management.Automation.ValidateNotNullAttribute } if ($ValidateNotNullOrEmpty.IsPresent) { New-Object -TypeName System.Management.Automation.ValidateNotNullOrEmptyAttribute } if ($PsBoundParameters.ContainsKey('ValidatePattern')) { New-Object -TypeName System.Management.Automation.ValidatePatternAttribute -ArgumentList $ValidatePattern } if ($PsBoundParameters.ContainsKey('ValidateRange')) { New-Object -TypeName System.Management.Automation.ValidateRangeAttribute -ArgumentList $ValidateRange } if ($PsBoundParameters.ContainsKey('ValidateScript')) { New-Object -TypeName System.Management.Automation.ValidateScriptAttribute -ArgumentList $ValidateScript } if ($PsBoundParameters.ContainsKey('ValidateSet')) { # ValidateSetAttribute does not accept values of $null and @(), so convert to empty string if (-not $ValidateSet) {$ValidateSet = [string]::Empty} New-Object -TypeName System.Management.Automation.ValidateSetAttribute -ArgumentList $ValidateSet } ).ForEach{ $collection.Add($_) } # create parameter object $parameter = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter -ArgumentList $Name, $Type, $collection # set parameter default value if provided if ($PSBoundParameters['DefaultValue']) { $parameter.Value = $DefaultValue -as $Type } # return parameter object $parameter } function New-ClcControlApi1Session { <# .SYNOPSIS Create new CenturyLink Cloud Control API v1 WebSession. .DESCRIPTION Create new CenturyLink Cloud Control API v1 WebSession. The session can be used in subsequent API v1 calls using function Invoke-ClcControlApi1. .EXAMPLE New-ClcControlApi1Session .EXAMPLE New-ClcControlApi1Session -Key <ControlAPIv1Key> -Password <ControlAPIv1Password> .LINK https://www.ctl.io/api-docs/v1/ .NOTES Author : Dmitry Gancho Last edit : 2/17/2017 #> [CmdLetBinding()] [SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] [SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '')] param ( [Parameter()] [Alias('key')] [string]$ApiKey, [Parameter()] [string]$Password ) if (-not ($ApiKey -and $Password)) { $credential = Get-Credential -Message "Enter CenturyLink Cloud APIv1 Key (as UserName) and Password" if ($credential) { $ApiKey = $credential.UserName $Password = $credential.GetNetworkCredential().Password } else { throw "APIv1 Key and Password are required to make Control APIv1 calls." } } $params = @{ Uri = 'https://api.ctl.io/REST/Auth/Logon/' Method = 'POST' ContentType = 'application/json' Body = @{ APIKey = $ApiKey Password = $Password } | ConvertTo-Json -Compress SessionVariable = 'webSession' ErrorAction = 'Stop' } Write-Verbose "Invoke-RestMethod params:$(Out-String -InputObject $params)" $response = Invoke-RestMethod @params Write-Verbose -Message "Invoke-RestMethod response:$(Out-String -InputObject $response)" Write-Verbose -Message "WebSession:$(Out-String -InputObject $webSession)" if ($response.Success) { $webSession } else { $message = 'New-ClcControlApi1Session: authentication failed. Server response:' $message += $response | Format-List | Out-String throw $message } } function New-ClcControlApi2Session { <# .SYNOPSIS Create new CenturyLink Cloud Control API v2 WebSession. .DESCRIPTION Create new CenturyLink Cloud Control API v2 WebSession. The session can be used in subsequent API v2 calls using function Invoke-ClcControlApi2. .EXAMPLE New-ClcControlApi2Session .EXAMPLE $credential = Get-Credential -Message 'Provide CenturyLink Cloud Control Credential' New-ClcControlApi2Session -Credential $credential .LINK https://www.ctl.io/api-docs/v2/ .NOTES Author : Dmitry Gancho Last edit : 2/17/2017 #> [CmdletBinding()] [SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] param ( [Parameter()] [PSCredential]$Credential ) # only TLS 1.2 is supported by APIv2 [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 # get credential if (-not $Credential) { $Credential = Get-Credential -Message 'Provide CenturyLink Cloud Control Credential' } if (-not $Credential) { throw "CenturyLink Cloud Control Credential are required to make Control APIv2 calls." } # login and get websession $params = @{ Method = 'POST' Uri = 'https://api.ctl.io/v2/authentication/login' Body = @{ username = $Credential.UserName password = $Credential.GetNetworkCredential().Password } SessionVariable = 'webSession' ErrorAction = 'Stop' } Write-Verbose -Message "Invoke-RestMethod params:$(Out-String -InputObject $params)" $response = Invoke-RestMethod @params Write-Verbose -Message "Invoke-RestMethod response:$(Out-String -InputObject $response)" # add these values to reuse in Invoke function $webSession.Headers.Add('UserName',$response.username) $webSession.Headers.Add('AccountAlias',$response.accountAlias) $webSession.Headers.Add('LocationAlias',$response.locationAlias) $webSession.Headers.Add('Roles',$response.roles) # add these mandatory values to maintain authenticated web session $webSession.Headers.Add('Accept','application/json') $webSession.Headers.Add('Authorization',"Bearer $($response.bearerToken)") Write-Verbose -Message "WebSession:$(Out-String -InputObject $webSession)" $webSession } function Invoke-ClcControlApi1 { <# .SYNOPSIS Invoke an API v1 method against CenturyLink Cloud Control. .DESCRIPTION Invoke an API v1 method against CenturyLink Cloud Control. The function allows to call any published API v1 method and dynamically assigns required set of paramters. Use with PowerShell_ISE for best interactive experience. .EXAMPLE # Get available DataCenters. Invoke-ClcControlApi1 -Account GetLocations .EXAMPLE # Get account details. Invoke-ClcControlApi1 -Account GetAccountDetails -AccountAlias ABCD .EXAMPLE # Get account network. Invoke-ClcControlApi1 -Network GetAccountNetworks .EXAMPLE # Get billing group summaries. Invoke-ClcControlApi1 -Billing GetGroupSummaries -StartDate 1/1/2017 .LINK https://www.ctl.io/api-docs/v1/ .NOTES Author : Dmitry Gancho Last edit : 2/17/2017 #> [CmdletBinding( SupportsShouldProcess, ConfirmImpact = 'High' )] param ( [Parameter( Mandatory, ParameterSetName = 'Account' )] [ValidateSet( 'CreateAccount', 'EnableAccount', 'GetAccountDetails', 'GetAccounts', 'GetCustomFields', 'GetLocations', 'SuspendAccount', 'UpdateAccountDetails' )] [string]$Account, [Parameter( Mandatory, ParameterSetName = 'Billing' )] [ValidateSet( 'GetAccountSummary', 'GetBillingHistory', 'GetGroupEstimate', 'GetGroupSummaries', 'GetInvoiceDetails', 'GetServerEstimate', 'GetServerHourlyCharges' )] [string]$Billing, [Parameter( Mandatory, ParameterSetName = 'Blueprint' )] [ValidateSet( 'DeployBlueprint', 'GetBlueprintDetails', 'GetBlueprintParameters', 'GetBlueprints', 'GetDeploymentStatus', 'GetPackages', 'GetPendingPackages', 'PublishPackage' )] [string]$Blueprint, [Parameter( Mandatory, ParameterSetName = 'Group' )] [ValidateSet( 'ArchiveHardwareGroup', 'CreateHardwareGroup', 'DeleteHardwareGroup', 'GetGroups', 'HardwareGroupMaintenance', 'PauseHardwareGroup', 'PowerOffHardwareGroup', 'PowerOnHardwareGroup', 'RebootHardwareGroup', 'ResetHardwareGroup', 'RestoreHardwareGroup', 'ShutdownHardwareGroup' )] [string]$Group, [Parameter( Mandatory, ParameterSetName = 'Network' )] [ValidateSet( 'AddPublicIPAddress', 'GetAccountNetworks', 'GetDeployableNetworks', 'GetNetworkDetails', 'GetNetworks', 'UpdatePublicIPAddress' )] [string]$Network, [Parameter( Mandatory, ParameterSetName = 'Queue' )] [ValidateSet( 'GetRequestStatus', 'ListQueueRequests' )] [string]$Queue, [Parameter( Mandatory, ParameterSetName = 'Server' )] [ValidateSet( 'ArchiveServer', 'ChangePassword', 'ConfigureServer', 'ConvertServerToTemplate', 'ConvertTemplateToServer', 'CreateServer', 'DeleteDisk', 'DeleteServer', 'DeleteSnapshot', 'DeleteTemplate', 'GetAllServersByModifiedDates', 'GetAllServersForAccountHierarchyByModifiedDates', 'GetAllServersForAccountHierarchy', 'GetAllServers', 'GetArchiveServers', 'GetServerCredentials', 'GetServerTemplates', 'GetServer', 'GetServersByModifiedDates', 'GetServers', 'GetSnapshots', 'ListArchivedServers', 'ListAvailableServerTemplates', 'ListDisks', 'PauseServer', 'PowerOffServer', 'PowerOnServer', 'RebootServer', 'ResetServer', 'ResizeDisk', 'RestoreServer', 'RevertToSnapshot', 'ServerMaintenance', 'ShutdownServer', 'SnapshotServer' )] [string]$Server, [Parameter( Mandatory, ParameterSetName = 'SMTPRelay' )] [ValidateSet( 'CreateAlias', 'DisableAlias', 'GetInvalidAddresses', 'ListAliases', 'RemoveAlias' )] [string]$SMTPRelay, [Parameter( Mandatory, ParameterSetName = 'User' )] [ValidateSet( 'CreateUser', 'DeleteUser', 'GetUserDetails', 'GetUsers', 'SuspendUser', 'UnsuspendUser', 'UpdateUser' )] [string]$User, [Parameter()] [Alias('ws')] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession = (New-ClcControlApi1Session), [Parameter()] [Alias('to')] [uint16]$TimeOut = 5, [Parameter()] [switch]$Force, [Parameter()] [switch]$Json, [Parameter()] [switch]$Help ) DynamicParam { # define enumerator $enum = @{ HelpUri = 'https://www.ctl.io/api-docs/v1/' TimeZone = @( 'Dateline Standard Time' 'UTC-11' 'Hawaiian Standard Time' 'Alaskan Standard Time' 'Pacific Standard Time (Mexico)' 'Pacific Standard Time' 'US Mountain Standard Time' 'Mountain Standard Time (Mexico)' 'Mountain Standard Time' 'Central America Standard Time' 'Central Standard Time' 'Central Standard Time(Mexico)' 'Canada Central Standard Time' 'SA Pacific Standard Time' 'Eastern Standard Time' 'US Eastern Standard Time' 'Venezuela Standard Time' 'Paraguay Standard Time' 'Atlantic Standard Time' 'Central Brazilian Standard Time' 'SA Western Standard Time' 'Pacific SA Standard Time' 'Newfoundland Standard Time' 'E. South America Standard Time' 'Argentina Standard Time' 'SA Eastern Standard Time' 'Greenland Standard Time' 'Montevideo Standard Time' 'Bahia Standard Time' 'UTC-02' 'Mid-Atlantic Standard Time' 'Azores Standard Time' 'Cape Verde Standard Time' 'Morocco Standard Time' 'UTC' 'GMT Standard Time' 'Greenwich Standard Time' 'W. Europe Standard Time' 'Central Europe Standard Time' 'Romance Standard Time' 'Central European Standard Time' 'W. Central Africa Standard Time' 'Namibia Standard Time' 'Jordan Standard Time' 'GTB Standard Time' 'Middle East Standard Time' 'Egypt Standard Time' 'Syria Standard Time' 'South Africa Standard Time' 'FLE Standard Time' 'Turkey Standard Time' 'Israel Standard Time' 'E. Europe Standard Time' 'Arabic Standard Time' 'Kaliningrad Standard Time' 'Arab Standard Time' 'E. Africa Standard Time' 'Iran Standard Time' 'Arabian Standard Time' 'Azerbaijan Standard Time' 'Russian Standard Time' 'Mauritius Standard Time' 'Georgian Standard Time' 'Caucasus Standard Time' 'Afghanistan Standard Time' 'Pakistan Standard Time' 'West Asia Standard Time' 'India Standard Time' 'Sri Lanka Standard Time' 'Nepal Standard Time' 'Central Asia Standard Time' 'Bangladesh Standard Time' 'Ekaterinburg Standard Time' 'Myanmar Standard Time' 'SE Asia Standard Time' 'N. Central Asia Standard Time' 'China Standard Time' 'North Asia Standard Time' 'Singapore Standard Time' 'W. Australia Standard Time' 'Taipei Standard Time' 'Ulaanbaatar Standard Time' 'North Asia East Standard Time' 'Tokyo Standard Time' 'Korea Standard Time' 'Cen. Australia Standard Time' 'AUS Central Standard Time' 'E. Australia Standard Time' 'AUS Eastern Standard Time' 'West Pacific Standard Time' 'Tasmania Standard Time' 'Yakutsk Standard Time' 'Central Pacific Standard Time' 'Vladivostok Standard Time' 'New Zealand Standard Time' 'UTC+12' 'Fiji Standard Time' 'Magadan Standard Time' 'Kamchatka Standard Time' 'Tonga Standard Time' 'Samoa Standard Time' ) } # define action $action = Get-Variable -Name $PSCmdlet.ParameterSetName -ValueOnly -ErrorAction Ignore # dynamic parameters collection $parameters = @() # define other parameters switch -Exact ($PSCmdlet.ParameterSetName) { Account { switch -Exact ($action) { CreateAccount { $enum.HelpUri += '#account-create-account' $enum.Status = @{ 1 = 'Active' 0 = 'Inactive' } $parameters += New-DynamicParameter -Name ParentAlias -Mandatory $parameters += New-DynamicParameter -Name AccountAlias -Alias alias $parameters += New-DynamicParameter -name Location -mandatory -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name BusinessName -mandatory $parameters += New-DynamicParameter -name Address1 -mandatory $parameters += New-DynamicParameter -name Address2 $parameters += New-DynamicParameter -name City -mandatory $parameters += New-DynamicParameter -name StateProvince -mandatory $parameters += New-DynamicParameter -name PostalCode -mandatory $parameters += New-DynamicParameter -name Country -mandatory $parameters += New-DynamicParameter -name Telephone -mandatory $parameters += New-DynamicParameter -name Fax $parameters += New-DynamicParameter -name TimeZone -values $enum.TimeZone $parameters += New-DynamicParameter -name ShareParentNetworks -mandatory -type ([bool]) $parameters += New-DynamicParameter -name BillingResponsibilityID -mandatory -values 1,2 } EnableAccount { $enum.HelpUri += '#account-enable-account' $parameters += New-DynamicParameter -name AccountAlias -mandatory -alias alias } GetAccountDetails { $enum.HelpUri += '#account-getaccountdetails' $enum.Status = @{ 1 = 'Active' 2 = 'Disabled' 3 = 'Deleted' 4 = 'Demo' } $parameters += New-DynamicParameter -name AccountAlias -mandatory -alias alias } GetAccounts { $enum.HelpUri += '#account-getaccounts' } GetCustomFields { $enum.HelpUri += '#account-getcustomfields' $parameters += New-DynamicParameter -name AccountAlias -mandatory -alias alias } GetLocations { $enum.HelpUri += '#account-getlocations' } SuspendAccount { $enum.HelpUri += '#account-suspendaccount' $parameters += New-DynamicParameter -name AccountAlias -mandatory -alias alias } UpdateAccountDetails { $enum.HelpUri += '#account-updateaccountdetails' $enum.Status = @{ 1 = 'Active' 0 = 'Inactive' } $parameters += New-DynamicParameter -name AccountAlias -mandatory -alias alias $parameters += New-DynamicParameter -name BusinessName -mandatory $parameters += New-DynamicParameter -name Address1 -mandatory $parameters += New-DynamicParameter -name Address2 $parameters += New-DynamicParameter -name City -mandatory $parameters += New-DynamicParameter -name StateProvince -mandatory $parameters += New-DynamicParameter -name PostalCode -mandatory $parameters += New-DynamicParameter -name Country -mandatory $parameters += New-DynamicParameter -name Telephone -mandatory $parameters += New-DynamicParameter -name Fax $parameters += New-DynamicParameter -name TimeZone -mandatory -values $enum.TimeZone $parameters += New-DynamicParameter -name ShareParentNetworks -mandatory -type ([bool]) } } } Billing { switch -Exact ($action) { GetAccountSummary { $enum.HelpUri += '#billing-getaccountsummary' $parameters += New-DynamicParameter -name AccountAlias -mandatory -alias alias } GetBillingHistory { $enum.HelpUri += '#billing-getbillinghistory' $parameters += New-DynamicParameter -name AccountAlias -mandatory -alias alias } GetGroupEstimate { $enum.HelpUri += '#billing-getgroupestimate' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name HardwareGroupUUID -mandatory } GetGroupSummaries { $enum.HelpUri += '#billing-getgroupsummaries' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name StartDate $parameters += New-DynamicParameter -name EndDate } GetInvoiceDetails { $enum.HelpUri += '#billing-getinvoicedetails' $parameters += New-DynamicParameter -name AccountAlias -mandatory -alias alias $parameters += New-DynamicParameter -name InvoiceID -mandatory } GetServerEstimate { $enum.HelpUri += '#billing-getserverestimate' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name ServerName -mandatory } GetServerHourlyCharges { $enum.HelpUri += '#billing-getserverhourlycharges' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name ServerName -mandatory $parameters += New-DynamicParameter -name StartDate $parameters += New-DynamicParameter -name EndDate } } } Blueprint { switch -Exact ($action) { DeployBlueprint { $enum.HelpUri += '#blueprint-deploy-blueprint' $parameters += New-DynamicParameter -name ID -mandatory $parameters += New-DynamicParameter -name LocationAlias -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name Parameters -type ([object]) $parameters += New-DynamicParameter -name CustomFields -type ([object]) } GetBlueprintDetails { $enum.HelpUri += '#blueprint-get-blueprint-details' $enum.Status = @{ 1 = 'Active' 3 = 'Deleted' 4 = 'Under Construction' } $enum.Visibility = @{ 1 = 'Public' 2 = 'Private' } $parameters += New-DynamicParameter -name ID -mandatory } GetBlueprintParameters { $enum.HelpUri += '#blueprint-get-blueprint-parameters' $enum.Type = @{ 1 = 'Network' 2 = 'Numeric' 3 = 'Option' 4 = 'Password' 5 = 'Server' 6 = 'ServerIP' 7 = 'String' 8 = 'MultiSelect' } $parameters += New-DynamicParameter -name ID -mandatory } GetBlueprints { $enum.HelpUri += '#blueprint-get-blueprints' $parameters += New-DynamicParameter -name CompanySize -values 1,2,3,4 $parameters += New-DynamicParameter -name OperatingSystems -values 6,7,21,13,14,19,20,15,16,2,3,4,5,17,18 $parameters += New-DynamicParameter -name Search $parameters += New-DynamicParameter -name Visibility -values 1,2,3 } GetDeploymentStatus { $enum.HelpUri += '#blueprint-get-deployment-status' $parameters += New-DynamicParameter -name RequestID -mandatory $parameters += New-DynamicParameter -name LocationAlias -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name AccountAlias -mandatory -alias alias } GetPackages { $enum.HelpUri += '#blueprint-get-packages' $enum.Classification = @{ 1 = 'System' 2 = 'Script' 3 = 'Software' } $parameters += New-DynamicParameter -name Classification -mandatory -values 1,2,3 $parameters += New-DynamicParameter -name Visibility -mandatory -values 1,2,3 } GetPendingPackages { $enum.HelpUri += '#blueprint-get-pending-packages' $enum.Classification = @{ 0 = 'Pending' } } PublishPackage { $enum.HelpUri += '#blueprint-publish-package' $parameters += New-DynamicParameter -name Classification -mandatory -values 1,2,3 $parameters += New-DynamicParameter -name Name -mandatory $parameters += New-DynamicParameter -name OperatingSystems -mandatory -values 2,3,5,15,16,18,20,25,26,27,28,29,30,31,32,33,34,35,36,37,38,40,41 $parameters += New-DynamicParameter -name Visibility -mandatory -values 1,2,3 } } } Group { switch -Exact ($action) { ArchiveHardwareGroup { $enum.HelpUri += '#group-archivehardwaregroup' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name UUID -mandatory } CreateHardwareGroup { $enum.HelpUri += '#group-createhardwaregroup' $parameters += New-DynamicParameter -name AccountAlias -mandatory -alias alias $parameters += New-DynamicParameter -name ParentUUID -mandatory $parameters += New-DynamicParameter -name Name -mandatory $parameters += New-DynamicParameter -name Description } DeleteHardwareGroup { $enum.HelpUri += '#group-deletehardwaregroup' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name UUID -mandatory } GetGroups { $enum.HelpUri += '#group-getgroups' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Location -mandatory -values $DataCenterList -alias dc } HardwareGroupMaintenance { $enum.HelpUri += '#group-hardwaregroupmaintenance' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name UUID -mandatory $parameters += New-DynamicParameter -name Enable -type ([bool]) -mandatory } PauseHardwareGroup { $enum.HelpUri += '#group-pausehardwaregroup' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name UUID -mandatory } PowerOffHardwareGroup { $enum.HelpUri += '#group-poweroffhardwaregroup' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name UUID -mandatory } PowerOnHardwareGroup { $enum.HelpUri += '#group-poweronhardwaregroup' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name UUID -mandatory } RebootHardwareGroup { $enum.HelpUri += '#group-reboothardwaregroup' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name UUID -mandatory } ResetHardwareGroup { $enum.HelpUri += '#group-resethardwaregroup' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name UUID -mandatory } RestoreHardwareGroup { $enum.HelpUri += '#group-restorehardwaregroup' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name UUID -mandatory $parameters += New-DynamicParameter -name ParentUUID -mandatory } ShutdownHardwareGroup { $enum.HelpUri += '#group-shutdownhardwaregroup' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name UUID -mandatory } } } Network { switch -Exact ($action) { AddPublicIPAddress { $enum.HelpUri += '#network-addpublicipaddress' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name ServerName -mandatory $parameters += New-DynamicParameter -name IPAddress -mandatory $parameters += New-DynamicParameter -name ServerPassword $parameters += New-DynamicParameter -name AllowHTTP -type ([switch]) $parameters += New-DynamicParameter -name AllowHTTPonPort8080 -type ([switch]) $parameters += New-DynamicParameter -name AllowHTTPS -type ([switch]) $parameters += New-DynamicParameter -name AllowFTPS -type ([switch]) $parameters += New-DynamicParameter -name AllowSFTP -type ([switch]) $parameters += New-DynamicParameter -name AllowSSH -type ([switch]) $parameters += New-DynamicParameter -name AllowRDP -type ([switch]) } GetAccountNetworks { $enum.HelpUri += '#network-getaccountnetworks' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Location -values $DataCenterList -alias dc } GetDeployableNetworks { $enum.HelpUri += '#network-getdeployablenetworks' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Location -values $DataCenterList -alias dc } GetNetworkDetails { $enum.HelpUri += '#network-getnetworkdetails' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Location -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name Name -mandatory } GetNetworks { $enum.HelpUri += '#network-getnetworks' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Location -values $DataCenterList -alias dc } UpdatePublicIPAddress { $enum.HelpUri += '#network-updatepublicipaddress' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name ServerName -mandatory $parameters += New-DynamicParameter -name PublicIPAddress -mandatory $parameters += New-DynamicParameter -name AllowHTTP -type ([switch]) $parameters += New-DynamicParameter -name AllowHTTPonPort8080 -type ([switch]) $parameters += New-DynamicParameter -name AllowHTTPS -type ([switch]) $parameters += New-DynamicParameter -name AllowFTPS -type ([switch]) $parameters += New-DynamicParameter -name AllowSFTP -type ([switch]) $parameters += New-DynamicParameter -name AllowSSH -type ([switch]) $parameters += New-DynamicParameter -name AllowRDP -type ([switch]) } } } Queue { switch -Exact ($action) { GetRequestStatus { $enum.HelpUri += '#queue-getrequeststatus' $parameters += New-DynamicParameter -name RequestID -mandatory } ListQueueRequests { $enum.HelpUri += '#queue-listqueuerequests' $parameters += New-DynamicParameter -name ItemStatusType -mandatory -values 1,2,3,4 } } } Server { $enum.Status = @{ 1 = 'Standard' 2 = 'Premium' } $enum.ServerType = @{ 1 = 'Standard' 2 = 'Premium' } $enum.ServiceLevel = @{ 1 = 'Standard' 2 = 'Premium' } $enum.OperatingSystem = @{ 2 = 'Windows 2003 32-bit' 3 = 'Windows 2003 64-bit' 4 = 'Windows 2008 32-bit' 5 = 'Windows 2008 64-bit' 6 = 'CentOS 32-bit' 7 = 'CentOS 64-bit' 8 = 'Windows XP 32-bit' 9 = 'Windows Vista 32-bit' 10 = 'Windows Vista 64-bit' 11 = 'Windows 7 32-bit' 12 = 'Windows 7 64-bit' 13 = 'FreeBSD 32-bit' 14 = 'FreeBSD 64-bit' 15 = 'Windows 2003 Enterprise 32-bit' 16 = 'Windows 2003 Enterprise 64-bit' 17 = 'Windows 2008 Enterprise 32-bit' 18 = 'Windows 2008 Enterprise 64-bit' 19 = 'Ubuntu 32-bit' 20 = 'Ubuntu 64-bit' 21 = 'Debian 64-bit' 22 = 'RedHat Enterprise Linux 64-bit' 25 = 'RedHat Enterprise Linux 5 64-bit' 27 = 'Windows 2012 Datacenter 64-bit' 28 = 'Windows 2012 R2 Datacenter 64-Bit' 31 = 'Ubuntu 12 64-Bit' 33 = 'CentOS 5 64-Bit' 35 = 'CentOS 6 64-Bit' 36 = 'Debian 6 64-Bit' 37 = 'Debian 7 64-Bit' 38 = 'RedHat 6 64-Bit' 39 = 'CoreOS' 40 = 'PXE Boot' 41 = 'Ubuntu 14 64-Bit' 42 = 'RedHat 7 64-Bit' 43 = 'Windows 2008 R2 Standard 64-Bit' 44 = 'Windows 2008 R2 Enterprise 64-Bit' 45 = 'Windows 2008 R2 Datacenter 64-Bit' } $enum.PowerState = @{ 0 = 'Stopped' 1 = 'Started' 2 = 'Paused' } switch ($action) { ArchiveServer { $enum.HelpUri += '#server-archive-server' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory } ChangePassword { $enum.HelpUri += '#server-change-password' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory $parameters += New-DynamicParameter -name CurrentPassword -mandatory $parameters += New-DynamicParameter -name NewPassword -mandatory } ConfigureServer { $enum.HelpUri += '#server-configure-server' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory $parameters += New-DynamicParameter -name HardwareGroupUUID -mandatory $parameters += New-DynamicParameter -name Cpu -mandatory -values 1,2,4 $parameters += New-DynamicParameter -name MemoryGB -mandatory -values 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 $parameters += New-DynamicParameter -name AdditionalStorageGB $parameters += New-DynamicParameter -name CustomFields -type ([object]) } ConvertServerToTemplate { $enum.HelpUri += '#server-convert-server-to-template' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory $parameters += New-DynamicParameter -name Password -mandatory $parameters += New-DynamicParameter -name TemplateAlias -mandatory } ConvertTemplateToServer { $enum.HelpUri += '#server-converttemplatetoserver' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory $parameters += New-DynamicParameter -name Password -mandatory $parameters += New-DynamicParameter -name HardwareGroupUUID -mandatory $parameters += New-DynamicParameter -name Network -mandatory } CreateServer { $enum.HelpUri += '#server-create-server' $parameters += New-DynamicParameter -name AccountAlias $parameters += New-DynamicParameter -name LocationAlias -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name Template -mandatory $parameters += New-DynamicParameter -name Alias -mandatory $parameters += New-DynamicParameter -name Description $parameters += New-DynamicParameter -name HardwareGroupUUID -mandatory $parameters += New-DynamicParameter -name ServerType -mandatory -values 1,2 $parameters += New-DynamicParameter -name ServiceLevel -mandatory -values 1,2 $parameters += New-DynamicParameter -name Cpu -mandatory $parameters += New-DynamicParameter -name MemoryGB -mandatory $parameters += New-DynamicParameter -name ExtraDriveGB -mandatory $parameters += New-DynamicParameter -name PrimaryDns $parameters += New-DynamicParameter -name SecondaryDns $parameters += New-DynamicParameter -name Network $parameters += New-DynamicParameter -name Password $parameters += New-DynamicParameter -name CustomFields -type ([object]) } DeleteDisk { $enum.HelpUri += '#server-delete-disk' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory $parameters += New-DynamicParameter -name ScsiBusID -mandatory $parameters += New-DynamicParameter -name ScsiDeviceID -mandatory $parameters += New-DynamicParameter -name OverrideFailsafes -type ([switch]) } DeleteServer { $enum.HelpUri += '#server-delete-server' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory } DeleteSnapshot { $enum.HelpUri += '#server-delete-snapshot' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory $parameters += New-DynamicParameter -name SnapshotName -mandatory } DeleteTemplate { $enum.HelpUri += '#server-deletetemplate' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory } GetAllServersByModifiedDates { $enum.HelpUri += '#server-getallserversbymodifieddates' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name HardwareGroupUUID $parameters += New-DynamicParameter -name Location -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name BeginDate $parameters += New-DynamicParameter -name EndDate } GetAllServersForAccountHierarchyByModifiedDates { $enum.HelpUri += '#server-get-all-servers-for-account-hierarchy-by-modified-date' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Location -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name BeginDate $parameters += New-DynamicParameter -name EndDate } GetAllServersForAccountHierarchy { $enum.HelpUri += '#server-getallserversforaccounthierarchy' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Location -values $DataCenterList -alias dc } GetAllServers { $enum.HelpUri += '#server-getallservers' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name HardwareGroupUUID $parameters += New-DynamicParameter -name Location -values $DataCenterList -alias dc } GetArchiveServers { $enum.HelpUri += '#server-getarchiveservers' } GetServerCredentials { $enum.HelpUri += '#server-getservercredentials' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory } GetServerTemplates { $enum.HelpUri += '#server-getservertemplates' } GetServer { $enum.HelpUri += '#server-getserver' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory } GetServersByModifiedDates { $enum.HelpUri += '#server-getserversbymodifieddates' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name HardwareGroupUUID -mandatory $parameters += New-DynamicParameter -name BeginDate $parameters += New-DynamicParameter -name EndDate } GetServers { $enum.HelpUri += '#server-getservers' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name HardwareGroupUUID -mandatory } GetSnapshots { $enum.HelpUri += '#server-getsnapshots' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory } ListArchivedServers { $enum.HelpUri += '#server-listarchiveservers' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Location -values $DataCenterList -alias dc } ListAvailableServerTemplates { $enum.HelpUri += '#server-listavailableservertemplates' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Location -values $DataCenterList -alias dc } ListDisks { $enum.HelpUri += '#server-listdisks' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory $parameters += New-DynamicParameter -name QueryGuestDiskNames } PauseServer { $enum.HelpUri += '#server-pauseserver' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory } PowerOffServer { $enum.HelpUri += '#server-poweroffserver' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory } PowerOnServer { $enum.HelpUri += '#server-poweronserver' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory } RebootServer { $enum.HelpUri += '#server-rebootserver' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory } ResetServer { $enum.HelpUri += '#server-resetserver' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory } ResizeDisk { $enum.HelpUri += '#server-resizedisk' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory $parameters += New-DynamicParameter -name ScsiBusID -mandatory $parameters += New-DynamicParameter -name ScsiDeviceID -mandatory $parameters += New-DynamicParameter -name ResizeGuestDisk -type ([switch]) $parameters += New-DynamicParameter -name NewSizeGB -mandatory } RestoreServer { $enum.HelpUri += '#server-restoreserver' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory $parameters += New-DynamicParameter -name HardwareGroupUUID -mandatory } RevertToSnapshot { $enum.HelpUri += '#server-reverttosnapshot' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory $parameters += New-DynamicParameter -name SnapshotName -mandatory } ServerMaintenance { $enum.HelpUri += '#server-servermaintenance' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory $parameters += New-DynamicParameter -name Enable -mandatory -type ([bool]) } ShutdownServer { $enum.HelpUri += '#server-shutdownserver' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory } SnapshotServer { $enum.HelpUri += '#server-snapshotserver' $parameters += New-DynamicParameter -name AccountAlias -alias alias $parameters += New-DynamicParameter -name Name -mandatory } } } SMTPRelay { switch -Exact ($action) { CreateAlias { $enum.HelpUri += '#smtp-relay-createalias' } DisableAlias { $enum.HelpUri += '#smtp-relay-disablealias' $parameters += New-DynamicParameter -name RelayAlias -mandatory } GetInvalidAddresses { $enum.HelpUri += '#smtp-relay-get-invalid-addresses' $parameters += New-DynamicParameter -name DomainAlias -mandatory $parameters += New-DynamicParameter -name StartDate -mandatory $parameters += New-DynamicParameter -name EndDate -mandatory } ListAliases { $enum.HelpUri += '#smtp-relay-listaliases' } RemoveAlias { $enum.HelpUri += '#smtp-relay-removealias' $parameters += New-DynamicParameter -name RelayAlias -mandatory } } } User { $enum.Roles = @{ 2 = 'Server Administrator' 3 = 'Billing Manager' 8 = 'DNS Manager' 9 = 'Account Administrator' 10 = 'Account Viewer' 12 = 'Network Manager' 13 = 'Security Manager' 14 = 'Server Operator' 15 = 'Server Scheduler' } switch -Exact ($action) { CreateUser { $enum.HelpUri += '#users-createuser' $parameters += New-DynamicParameter -name UserName -mandatory $parameters += New-DynamicParameter -name AccountAlias -mandatory -alias alias $parameters += New-DynamicParameter -name EmailAddress -mandatory $parameters += New-DynamicParameter -name FirstName -mandatory $parameters += New-DynamicParameter -name LastName -mandatory $parameters += New-DynamicParameter -name AlternateEmailAddress $parameters += New-DynamicParameter -name Title $parameters += New-DynamicParameter -name OfficeNumber $parameters += New-DynamicParameter -name MobileNumber $parameters += New-DynamicParameter -name AllowSMSAlerts $parameters += New-DynamicParameter -name FaxNumber $parameters += New-DynamicParameter -name SAMLUserName $parameters += New-DynamicParameter -name Roles -mandatory -type ([int16[]]) -values 2,3,8,9,10,12,13,14,15 $parameters += New-DynamicParameter -name TimeZoneID -values $enum.TimeZone } DeleteUser { $enum.HelpUri += '#users-deleteuser' $parameters += New-DynamicParameter -name UserName -mandatory } GetUserDetails { $enum.HelpUri += '#users-getuserdetails' $parameters += New-DynamicParameter -name AccountAlias -mandatory -alias alias $parameters += New-DynamicParameter -name UserName -mandatory } GetUsers { $enum.HelpUri += '#users-getusers' $parameters += New-DynamicParameter -name AccountAlias -mandatory -alias alias } SuspendUser { $enum.HelpUri += '#users-suspenduser' $parameters += New-DynamicParameter -name UserName -mandatory } UnsuspendUser { $enum.HelpUri += '#users-unsuspenduser' $parameters += New-DynamicParameter -name UserName -mandatory } UpdateUser { $enum.HelpUri += '#users-updateuser' $parameters += New-DynamicParameter -name UserName -mandatory $parameters += New-DynamicParameter -name EmailAddress -mandatory $parameters += New-DynamicParameter -name FirstName -mandatory $parameters += New-DynamicParameter -name LastName -mandatory $parameters += New-DynamicParameter -name AlternateEmailAddress $parameters += New-DynamicParameter -name Title $parameters += New-DynamicParameter -name OfficeNumber $parameters += New-DynamicParameter -name MobileNumber $parameters += New-DynamicParameter -name AllowSMSAlerts $parameters += New-DynamicParameter -name FaxNumber $parameters += New-DynamicParameter -name SAMLUserName $parameters += New-DynamicParameter -name TimeZoneID -values $enum.TimeZone $parameters += New-DynamicParameter -name Roles -type ([int16[]]) -values 2,3,8,9,10,12,13,14,15 } } } } # dictionary $dictionary = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary $parameters.ForEach{$dictionary.Add($_.Name,$_)} $dictionary } process { # if help is called, open help uri and stop processing if ($Help) { Start-Process $enum.HelpUri break } # construct URI $object = $PSCmdlet.ParameterSetName $uri = "https://api.ctl.io/REST/$object/$action/JSON" # convert dictionary to json and create body $body = @{} $dictionary.Keys | ForEach-Object -Process { $body.$_ = $dictionary.$_.Value } # create splat for Invoke-RestMethod $params = @{ Uri = $uri Method = 'POST' Body = $body ContentType = 'application/json' WebSession = $WebSession TimeoutSec = $TimeOut ErrorAction = 'Stop' } $accountAlias = if ($body.ContainsKey('AccountAlias')) { $body.AccountAlias } else { '<unknown>' } # verify if we should invoke anything but Get or List if ( $action -match '^(Get|List)' -or $Force -or $PSCmdlet.ShouldProcess($accountAlias,"$object/$action") ) { # invoke and return Write-Verbose -Message "Invoke-RestMethod params:`n$(ConvertTo-Json -InputObject $params)" $params.Body = $params.Body | ConvertTo-Json -Depth 3 -Compress $response = Invoke-RestMethod @params Write-Verbose -Message "Invoke-RestMethod response:`n$(ConvertTo-Json -InputObject $response)" if ($Json) { $response | ConvertTo-Json -Depth 10 } else { $response } } } } function Invoke-ClcControlApi2 { <# .SYNOPSIS Invoke an API v2 method against CenturyLink Cloud Control. .DESCRIPTION Invoke an API v2 method against CenturyLink Cloud Control. Defaults values for authenticated user are used in all calls for parameters accountAlias, clc-alias, dataCenter, userName parameters, if not explicitely specified. The function allows to call any published API v2 method and dynamically assigns required set of paramters. Use with PowerShell_ISE for best interactive experience. .PARAMETER content Use switch -Help for properties Parameter Content type [object] accepts values in any of the following formats: [string] (json) i.e.: '{ 'userName':'root', 'password':'P@ssw0rd1' }' [string], i.e.: 'NAME1' [string[]], i.e.: 'NAME1','NAME2' [hashtable], i.e.: @{ userName = 'root' password = 'P@ssw0rd1' } [PSCustomObject], i.e.: [pscustomobject]@{ userName = 'root' password = 'P@ssw0rd1' } .EXAMPLE # Create an alert policy. $actions = @( @{ action = 'email' settings = @{ recipients = @( 'dmitry.gancho@ctl.io' ) } } ) $triggers = @( @{ metric = 'cpu' duration = '00:05:00' threshold = 90 } ) $content = @{ name = 'My Alert Policy' actions = $actions triggers = $triggers } Invoke-ClcControlApi2 -AlertPolicies CreateAlertPolicy -content $content .EXAMPLE # Get alert policies. Invoke-ClcControlApi2 -AlertPolicies GetAlertPolicies .EXAMPLE # Get invoice info for specified month. Invoke-ClcControlApi2 -Billing GetInvoiceDataForAnAccountAlias -year 2015 -month 9 .EXAMPLE # Receive authentication infromation. Invoke-ClcControlApi2 -Authentication Login -content @{username='<USERNAME>';password='<PASSWORD>'} .EXAMPLE # List all server names in a datacenter. Notice re-use of autheniticated WebSession. $Alias = 'XXXX' $Dc = 'WA1' $WebSession = New-ClcControlApi2Session $DataCenter = Invoke-ClcControlApi2 -Data_Centers GetDataCenter -accountAlias $Alias -dataCenter $Dc -query @{GroupLinks=$true} -WebSession $WebSession $RootGroupId = $DataCenter.links.Where{$_.rel -eq 'group'}.id $RootGroup = Invoke-ClcControlApi2 -Groups GetGroup -accountAlias $Alias -groupId $RootGroupId -WebSession $WebSession $RootGroup.groups | Where-Object -Property serversCount -gt 0 | Foreach-Object -Process { $_.links.Where{$_.rel -eq 'server'}.id } .EXAMPLE # Reboot two servers. Invoke-ClcControlApi2 -PowerOperations RebootServer -accountAlias <ACCOUNTALIAS> -content <SERVER1>, <SERVER2> .EXAMPLE # Open API help website for method Servers\GetServer Invoke-ClcControlApi2 -Servers GetServer -Help .EXAMPLE # Set server maintenance mode. $content = @{ servers = @( @{ id = 'WA1DGTT801' inMaintenanceMode = $true } ) } Invoke-ClcControlApi2 -PowerOperations SetMaintenanceMode -content $content .EXAMPLE # Add secondary NIC to a server $ServerName = 'DC1XXXXSRV01' $NetworkName = '10.82.209.0/24' $Server = Invoke-ClcControlApi2 -Servers GetServer -accountAlias XXXX -serverId $ServerName $Network = Invoke-ClcControlApi2 -Networks GetNetworkList -alias $server.AccountAlias -dc $server.Location | Where-Object -Property cidr -eq $NetworkName Invoke-ClcControlApi2 -Servers AddSecondaryNetwork -alias $server.AccountAlias -serverId $ServerName -content @{networkId = $network.id} -Force # or, if specific IP to assign: $IpAddress = '10.82.209.100' Invoke-ClcControlApi2 -Servers AddSecondaryNetwork -alias $server.AccountAlias -serverId $ServerName -content @{netwrokId = $network.id; ipAddress = $IpAddress} -Force .EXAMPLE # Get Intra-DataCenter Firewall Policy List. Invoke-ClcControlApi2 -Firewall GetIntraDataCenterFirewallPolicyList -sourceAccountAlias XXXX -destinationAccountAlias ABCD -dataCenter VA1 .EXAMPLE # List SimpleBackup policies. Invoke-ClcControlApi2 -SimpleBackup GetPolicies | Select-Object -ExpandProperty results .EXAMPLE # Find SimpleBackup policy. Invoke-ClcControlApi2 -SimpleBackup GetPolicies -clc-alias DGTT -query @{limit=1;offset=1} .EXAMPLE # Get SimpleBackup policy. Invoke-ClcControlApi2 -SimpleBackup GetPolicy -clc-alias DGTT -accountPolicyId 20b3fc68-d5df-46bf-ac37-7e533c30a850 .EXAMPLE # Update SimpleBackup policy. $content = @{ backupIntervalHours = 20 excludedDirectoryPaths = @('/var') name = 'Test Linux' osType = 'Linux' paths = @('/') policyId = '20b3fc68-d5df-46bf-ac37-7e533c30a850' retentionDays = 3 status = 'ACTIVE' } Invoke-ClcControlApi2 -SimpleBackup UpdatePolicy -accountPolicyId 20b3fc68-d5df-46bf-ac37-7e533c30a850 -content $content .EXAMPLE # Get SimpleBackup restore points for a server. Note max timespan is 100 days. $serverName = 'WA1DGTT801' $server = Invoke-ClcControlApi2 -Servers GetServer -serverId $serverName $end = [datetime]::UtcNow $start = $end.AddDays(-100) $policy = Invoke-ClcControlApi2 -SimpleBackup GetPolicyDetailsByServer -query @{serverId=$server.Name} $query = @{ backupFinishedStartDate = $start.ToString('yyyy-MM-dd') backupFinishedEndDate = $end.ToString('yyyy-MM-dd') } $response = Invoke-ClcControlApi2 -SimpleBackup GetRestorePointDetails -accountPolicyId $policy.accountPolicyId -serverPolicyId $policy.serverPolicyId -query $query $response.Results .EXAMPLE $res = Invoke-ClcControlApi2 -Networks GetSitetoSiteVPNs -accountAlias HJS $res.Count | Should BeGreaterThan 0 .LINK https://www.ctl.io/api-docs/v2/ .NOTES Author : Dmitry Gancho Last edit : 3/29/2017 Version : 1.5 #> [CmdletBinding( SupportsShouldProcess, ConfirmImpact = 'High' )] [SuppressMessageAttribute('PSAvoidInvokingEmptyMembers', '')] Param ( #region Object parameters [Parameter( Mandatory, ParameterSetName = 'AlertPolicies' )] [ValidateSet( 'CreateAlertPolicy', 'DeleteAlertPolicy', 'GetAlertPolicies', 'GetAlertPolicy', 'UpdateAlertPolicy' )] [string]$AlertPolicies, [Parameter( Mandatory, ParameterSetName = 'AntiAffinityPolicies' )] [ValidateSet( 'CreateAntiAffinityPolicy', 'DeleteAntiAffinityPolicy', 'GetAntiAffinityPolicies', 'GetAntiAffinityPolicy', 'UpdateAntyAffinityPolicy' )] [string]$AntiAffinityPolicies, [Parameter( Mandatory, ParameterSetName = 'Authentication' )] [ValidateSet( 'Login' )] [string]$Authentication, [Parameter( Mandatory, ParameterSetName = 'AutoscalePolicies' )] [ValidateSet( 'GetVerticalAutoscalePolicies', 'GetVerticalAutoscalePolicy', 'RemoveVerticalAutoscalePolicyFromServer', 'SetVerticalAutoscalePolicyOnServer', 'ViewVerticalAutoscalePolicyOnServer' )] [string]$AutoscalePolicies, [Parameter( Mandatory, ParameterSetName = 'Billing' )] [ValidateSet( 'GetInvoiceDataForAnAccountAlias' )] [string]$Billing, [Parameter( Mandatory, ParameterSetName = 'CustomFields' )] [ValidateSet( 'GetCustomFields' )] [string]$CustomFields, # conflicts with Dynamic Parameter 'dataCenter' [Parameter( Mandatory, ParameterSetName = 'Data_Centers' )] [ValidateSet( 'GetDataCenterBareMetalCapabilities', 'GetDataCenterDeploymentCapabilities', 'GetDataCenterList', 'GetDataCenter' )] [string]$Data_Centers, [Parameter( Mandatory, ParameterSetName = 'Firewall' )] [ValidateSet( 'AddPublicIPAddress', 'CreateaCrossDataCenterFirewallPolicy', 'CreateanIntraDataCenterFirewallPolicy', 'DeleteaCrossDataCenterFirewallPolicy', 'DeleteanIntraDataCenterFirewallPolicy', 'GetCrossDataCenterFirewallPolicyList', 'GetCrossDataCenterFirewallPolicy', 'GetIntraDataCenterFirewallPolicyList', 'GetIntraDataCenterFirewallPolicy', 'GetPublicIPAddress', 'RemovePublicIPAddress', 'UpdateCrossDataCenterFirewallPolicy', 'UpdateIntraDataCenterFirewallPolicy', 'UpdatePublicIPAddress' )] [string]$Firewall, [Parameter( Mandatory, ParameterSetName = 'Groups' )] [ValidateSet( 'GetGroupScheduledActivities', 'GetGroup', 'SetGroupCustomFields', 'SetGroupDefaults', 'SetGroupHorizontalAutoscalePolicy', 'SetGroupName/Description', 'SetGroupParent', 'SetGroupScheduledActivities' )] [string]$Groups, [Parameter( Mandatory, ParameterSetName = 'GroupActions' )] [ValidateSet( 'ArchiveGroup', 'RestoreGroup' )] [string]$GroupActions, [Parameter( Mandatory, ParameterSetName = 'IntrusionPrevention' )] [ValidateSet( 'CreateIntrusionProtectionServiceNotifications', 'UpdateIntrusionProtectionServiceNotifications', 'GetIntrusionProtectionServiceNotifications', 'DeleteIntrusionProtectionServiceNotifications', 'InstallIntrusionProtectionServiceAgent', 'UninstallIntrusionProtectionServiceAgent' )] [string]$IntrusionPrevention, [Parameter( Mandatory, ParameterSetName = 'Networks' )] [ValidateSet( 'ClaimNetwork', 'GetIPAddressList', 'GetNetworkList', 'GetNetwork', 'ReleaseNetwork', 'CreateaSitetoSiteVPN', 'DeleteaSitetoSiteVPN', 'GetDetailsforaSitetoSiteVPN', 'GetSitetoSiteVPNs', 'UpdateaSitetoSiteVPN', 'UpdateNetwork' )] [string]$Networks, [Parameter( Mandatory, ParameterSetName = 'Patching' )] [ValidateSet( 'ApplyingPatchesToOperatingSystems', 'GetDetailsofPatchesAppliedtoaServerDuringaSingleExecution', 'GetaSummaryofAllPatchesDeployedtoaServer' )] [string]$Patching, [Parameter( Mandatory, ParameterSetName = 'PowerOperations' )] [ValidateSet( 'PauseServer', 'PowerOffServer', 'PowerOnServer', 'RebootServer', 'ResetServer', 'SetMaintenanceMode', 'ShutDownServer', 'StartMaintenanceMode', 'StopMaintenanceMode' )] [string]$PowerOperations, [Parameter( Mandatory, ParameterSetName = 'Queue' )] [ValidateSet( 'GetStatus' )] [string]$Queue, [Parameter( Mandatory, ParameterSetName = 'RelationalDatabase' )] [ValidateSet( 'CreateSubscriptionBackupOperation', 'CreateSubscriptionBackup', 'CreateSubscriptionNotificationOperation', 'CreateSubscriptionNotification', 'CreateSubscriptionOperation', 'CreateSubscription', 'DeleteSubscriptionBackup', 'DeleteSubscriptionNotification', 'DeleteSubscription', 'GetBilling', 'GetDatacenters', 'GetHistory', 'GetPromotions', 'GetSubscriptionBackups', 'GetSubscriptionCertificate', 'GetSubscriptionNotifications', 'GetSubscription', 'GetSubscriptions', 'PatchSubscription', 'UpdateSubscriptionNotification' )] [string]$RelationalDatabase, [Parameter( Mandatory, ParameterSetName = 'Servers' )] [ValidateSet( 'AddSecondaryNetwork', 'CloneServer', 'CreateServer', 'DeleteServer', 'GetAvailableServerImports', 'GetServerCredentials', 'GetServer', 'ImportServer', 'RemoveSecondaryNetwork', 'SetServerCPU/Memory', 'SetServerCredentials', 'SetServerCustomFields', 'SetServerDescription/Group', 'SetServerDisks' )] [string]$Servers, [Parameter( Mandatory, ParameterSetName = 'ServerActions' )] [ValidateSet( 'ArchiveServer', 'CreateSnapshot', 'DeleteSnapshot', 'ExecutePackage', 'RestoreServer', 'ReverttoSnapshot' )] [string]$ServerActions, [Parameter( Mandatory, ParameterSetName = 'SharedLoadBalancers' )] [ValidateSet( 'CreateLoadBalancerPool', 'CreateSharedLoadBalancer', 'DeleteLoadBalancerPool', 'DeleteSharedLoadBalancer', 'GetLoadBalancerNodes', 'GetLoadBalancerPool', 'GetLoadBalancerPools', 'GetSharedLoadBalancer', 'GetSharedLoadBalancers', 'UpdateLoadBalancerNodes', 'UpdateLoadBalancerPool', 'UpdateSharedLoadBalancer' )] [string]$SharedLoadBalancers, [Parameter( Mandatory, ParameterSetName = 'SimpleBackup' )] [ValidateSet( 'CreatePolicy', 'CreateServerPolicies', 'CreateServerPolicy', 'DeleteServerPolicy', 'GetAllPoliciesEligibleForServerId', 'GetAllRegions', 'GetDataCenterList', 'GetOsTypes', 'GetPolicies', 'GetPolicyDetailsByServer', 'GetPolicy', 'GetRestorePointDetails', 'GetServerPolicies', 'GetServerPolicy', 'GetServersByDataCenter', 'GetStoredDataByServerPolicy', 'PatchPolicy', 'UpdatePolicy' )] [string]$SimpleBackup, [Parameter( Mandatory, ParameterSetName = 'Webhooks' )] [ValidateSet( 'AddWebhookTargetUri', 'DeleteWebhookTargetUri', 'DeleteWebhook', 'GetWebhooks', 'SetWebhook' )] [string]$Webhooks, #endregion #region Other parameters [Parameter()] [Alias('ws')] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession = (New-ClcControlApi2Session), [Parameter()] [Alias('to')] [uint16]$TimeOut = 5, [Parameter()] [switch]$Force, [Parameter()] [switch]$Json, [Parameter()] [switch]$Help #endregion ) DynamicParam { # define params $enum = @{ HelpUri = 'https://www.ctl.io/api-docs/v2/' } # define object and action $object = $PSCmdlet.ParameterSetName $action = Get-Variable -Name $PSCmdlet.ParameterSetName -ValueOnly -ErrorAction Ignore # dynamic parameters collection $parameters = @() # define other parameters switch -regex ($object) { 'AlertPolicies' { switch -Exact ($action) { CreateAlertPolicy { $enum.HelpUri += '#alert-policies-create-alert-policy' $enum.Structure = 'POST https://api.ctl.io/v2/alertPolicies/{accountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } DeleteAlertPolicy { $enum.HelpUri += '#alert-policies-delete-alert-policy' $enum.Structure = 'DELETE https://api.ctl.io/v2/alertPolicies/{accountAlias}/{policyId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name policyId -mandatory -alias id } GetAlertPolicies { $enum.HelpUri += '#alert-policies-get-alert-policies' $enum.Structure = 'GET https://api.ctl.io/v2/alertPolicies/{accountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias } GetAlertPolicy { $enum.HelpUri += '#alert-policies-get-alert-policy' $enum.Structure = 'GET https://api.ctl.io/v2/alertPolicies/{accountAlias}/{policyId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name policyId -mandatory -alias id } UpdateAlertPolicy { $enum.HelpUri += '#alert-policies-update-alert-policy' $enum.Structure = 'PUT https://api.ctl.io/v2/alertPolicies/{accountAlias}/{policyId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name policyId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } } } 'AntiAffinityPolicies' { switch -Exact ($action) { CreateAntiAffinityPolicy { $enum.HelpUri += '#anti-affinity-policies-create-anti-affinity-policy' $enum.Structure = 'POST https://api.ctl.io/v2/antiAffinityPolicies/{accountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } DeleteAntiAffinityPolicy { $enum.HelpUri += '#anti-affinity-policies-delete-anti-affinity-policy' $enum.Structure = 'DELETE https://api.ctl.io/v2/antiAffinityPolicies/{accountAlias}/{policyId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name policyId -mandatory -alias id } GetAntiAffinityPolicies { $enum.HelpUri += '#anti-affinity-policies-get-anti-affinity-policies' $enum.Structure = 'GET https://api.ctl.io/v2/antiAffinityPolicies/{accountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias } GetAntiAffinityPolicy { $enum.HelpUri += '#anti-affinity-policies-get-anti-affinity-policy' $enum.Structure = 'GET https://api.ctl.io/v2/antiAffinityPolicies/{accountAlias}/{policyId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name policyId -mandatory -alias id } UpdateAntyAffinityPolicy { $enum.HelpUri += '#anti-affinity-policies-update-anti-affinity-policy' $enum.Structure = 'PUT https://api.ctl.io/v2/antiAffinityPolicies/{accountAlias}/{policyId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name policyId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } } } 'Authentication' { switch -Exact ($action) { Login { $enum.HelpUri += '#authentication-login' $enum.Structure = 'POST https://api.ctl.io/v2/authentication/login' $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } } } 'AutoscalePolicies' { switch -Exact ($action) { GetVerticalAutoscalePolicies { $enum.HelpUri += '#autoscale-policies' $enum.Structure = 'GET https://api.ctl.io/v2/autoscalePolicies/{accountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias } GetVerticalAutoscalePolicy { $enum.HelpUri += '#autoscale-policies-get-vertical-autoscale-policy' $enum.Structure = 'GET https://api.ctl.io/v2/autoscalePolicies/{accountAlias}/{policyId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name policyId -mandatory } RemoveVerticalAutoscalePolicyFromServer { $enum.HelpUri += '#autoscale-policies-remove-vertical-autoscale-policy-from-server' $enum.Structure = 'DELETE https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/cpuAutoscalePolicy' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name } SetVerticalAutoscalePolicyOnServer { $enum.HelpUri += '#autoscale-policies-set-vertical-autoscale-policy-on-server' $enum.Structure = 'PUT https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/cpuAutoscalePolicy' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } ViewVerticalAutoscalePolicyOnServer { $enum.HelpUri += '#autoscale-policies-view-vertical-autoscale-policy-on-server' $enum.Structure = 'GET https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/cpuAutoscalePolicy' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name } } } 'Billing' { switch -Exact ($action) { GetInvoiceDataForAnAccountAlias { $enum.HelpUri += '#billing-get-invoice-data-for-an-account-alias' $enum.Structure = 'GET https://api.ctl.io/v2/invoice/{accountAlias}/{year}/{month}?pricingAccount={pricingAccountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name year -mandatory $parameters += New-DynamicParameter -name month -mandatory $parameters += New-DynamicParameter -name pricingAccountAlias } } } 'CustomFields' { switch -Exact ($action) { GetCustomFields { $enum.HelpUri += '#custom-fields-get-custom-fields' $enum.Structure = 'GET https://api.ctl.io/v2/accounts/{accountAlias}/customFields' $parameters += New-DynamicParameter -name accountAlias -alias alias } } } 'Data_Centers' { switch -Exact ($action) { GetDataCenterBareMetalCapabilities { $enum.HelpUri += '#data-centers-get-data-center-bare-metal-capabilities' $enum.Structure = 'GET https://api.ctl.io/v2/datacenters/{accountAlias}/{dataCenter}/bareMetalCapabilities' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc } GetDataCenterDeploymentCapabilities { $enum.HelpUri += '#data-centers-get-data-center-deployment-capabilities' $enum.Structure = 'GET https://api.ctl.io/v2/datacenters/{accountAlias}/{dataCenter}/deploymentCapabilities' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc } GetDataCenterList { $enum.HelpUri += '#data-centers-get-data-center-list' $enum.Structure = 'GET https://api.ctl.io/v2/datacenters/{accountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias } GetDataCenter { $enum.HelpUri += '#data-centers-get-data-center' $enum.Structure = 'GET https://api.ctl.io/v2/datacenters/{accountAlias}/{dataCenter}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name query -type ([object]) } } } 'Firewall' { switch -Exact ($action) { AddPublicIPAddress { $enum.HelpUri += '#firewall-add-public-ip-address' $enum.Structure = 'POST https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/publicIPAddresses' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias name,id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } CreateaCrossDataCenterFirewallPolicy { $enum.HelpUri += '#firewall-create-a-cross-data-center-firewall-policy' $enum.Structure = 'POST https://api.ctl.io/v2-experimental/crossDcFirewallPolicies/{accountAlias}/{dataCenter}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } CreateanIntraDataCenterFirewallPolicy { $enum.HelpUri += '#firewall-create-an-intra-data-center-firewall-policy' $enum.Structure = 'POST https://api.ctl.io/v2-experimental/firewallPolicies/{accountAlias}/{dataCenter}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } DeleteaCrossDataCenterFirewallPolicy { $enum.HelpUri += '#firewall-delete-a-cross-data-center-firewall-policy' $enum.Structure = 'DELETE https://api.ctl.io/v2-experimental/crossDcFirewallPolicies/{accountAlias}/{dataCenter}/{policyId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name policyId -mandatory -alias id } DeleteanIntraDataCenterFirewallPolicy { $enum.HelpUri += '#firewall-delete-an-intra-data-center-firewall-policy' $enum.Structure = 'DELETE https://api.ctl.io/v2-experimental/firewallPolicies/{accountAlias}/{dataCenter}/{policyId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name policyId -mandatory -alias id } GetCrossDataCenterFirewallPolicyList { $enum.HelpUri += '#firewall-get-cross-data-center-firewall-policy-list' $enum.Structure = 'GET https://api.ctl.io/v2-experimental/crossDcFirewallPolicies/{accountAlias}/{dataCenter}?destinationAccountId={destinationAccountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name destinationAccountAlias } GetCrossDataCenterFirewallPolicy { $enum.HelpUri += '#firewall-get-cross-data-center-firewall-policy' $enum.Structure = 'GET https://api.ctl.io/v2-experimental/crossDcFirewallPolicies/{accountAlias}/{dataCenter}/{policyId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name policyId -mandatory -alias id } GetIntraDataCenterFirewallPolicyList { $enum.HelpUri += '#firewall-get-intra-data-center-firewall-policy-list' $enum.Structure = 'GET https://api.ctl.io/v2-experimental/firewallPolicies/{accountAlias}/{dataCenter}?destinationAccount={destinationAccountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name destinationAccountAlias } GetIntraDataCenterFirewallPolicy { $enum.HelpUri += '#firewall-get-intra-data-center-firewall-policy' $enum.Structure = 'GET https://api.ctl.io/v2-experimental/firewallPolicies/{accountAlias}/{dataCenter}/{policyId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name policyId -mandatory -alias id } GetPublicIPAddress { $enum.HelpUri += '#firewall-get-public-ip-address' $enum.Structure = 'GET https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/publicIPAddresses/{publicIP}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias name,id $parameters += New-DynamicParameter -name publicIP -mandatory -alias ip } RemovePublicIPAddress { $enum.HelpUri += '#firewall-remove-public-ip-address' $enum.Structure = 'DELETE https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/publicIPAddresses/{publicIP}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias name,id $parameters += New-DynamicParameter -name publicIP -mandatory -alias ip } UpdateCrossDataCenterFirewallPolicy { $enum.HelpUri += '#firewall-update-cross-data-center-firewall-policy' $enum.Structure = 'PUT https://api.ctl.io/v2-experimental/crossDcFirewallPolicies/{accountAlias}/{dataCenter}/{policyId}?enabled={enabled}' $enum.Warning = 'experimental' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name policyId -mandatory -alias id $parameters += New-DynamicParameter -name enabled -mandatory -values true,false } UpdateIntraDataCenterFirewallPolicy { $enum.HelpUri += '#firewall-update-intra-data-center-firewall-policy' $enum.Structure = 'PUT https://api.ctl.io/v2-experimental/firewallPolicies/{accountAlias}/{dataCenter}/{policyId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name policyId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } UpdatePublicIPAddress { $enum.HelpUri += '#firewall-update-public-ip-address' $enum.Structure = 'PUT https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/publicIPAddresses/{publicIP}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias name,id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } } } 'Groups' { switch -Exact ($action) { CreateGroup { $enum.HelpUri += '#groups-create-group' $enum.Structure = 'POST https://api.ctl.io/v2/groups/{accountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } DeleteGroup { $enum.HelpUri += '#groups-delete-group' $enum.Structure = 'DELETE https://api.ctl.io/v2/groups/{accountAlias}/{groupId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name groupId -mandatory -alias id } GetGroupBillingDetails { $enum.HelpUri += '#groups-get-group-billing-details' $enum.Structure = 'GET https://api.ctl.io/v2/groups/{accountAlias}/{groupId}/billing' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name groupId -mandatory -alias id } GetGroupHorizontalAutoscalePolicy { $enum.HelpUri += '#groups-get-group-horizontal-autoscale-policy' $enum.Structure = 'GET https://api.ctl.io/v2/groups/{accountAlias}/{groupId}/horizontalAutoscalePolicy/' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name groupId -mandatory -alias id } GetGroupMonitoringStatistics { $enum.HelpUri += '#groups-get-group-monitoring-statistics' $enum.Structure = 'GET https://api.ctl.io/v2/groups/{accountAlias}/{groupId}/statistics?type={type}&start={start}&end={end}&sampleInterval={sampleInterval}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name groupId -mandatory -alias id $parameters += New-DynamicParameter -name type -mandatory -values latest,hourly,realtime $parameters += New-DynamicParameter -name start -type ([datetime]) $parameters += New-DynamicParameter -name end -type ([datetime]) $parameters += New-DynamicParameter -name sampleInterval -type ([timespan]) } GetGroupScheduledActivities { $enum.HelpUri += '#groups-get-group-scheduled-activities' $enum.Structure = 'GET https://api.ctl.io/v2/groups/{accountAlias}/{groupId}/ScheduledActivities/' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name groupId -mandatory -alias id } GetGroup { $enum.HelpUri += '#groups-get-group' $enum.Structure = 'GET https://api.ctl.io/v2/groups/{accountAlias}/{groupId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name groupId -mandatory -alias id } SetGroupCustomFields { $enum.HelpUri += '#groups-set-group-custom-fields' $enum.Structure = 'PATCH https://api.ctl.io/v2/groups/{accountAlias}/{groupId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name groupId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } SetGroupDefaults { $enum.HelpUri += '#groups-set-group-defaults' $enum.Structure = 'POST https://api.ctl.io/v2/groups/{accountAlias}/{groupId}/defaults' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name groupId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } SetGroupHorizontalAutoscalePolicy { $enum.HelpUri += '#groups-set-group-horizontal-autoscale-policy' $enum.Structure = 'PUT https://api.ctl.io/v2/groups/{accountAlias}/{groupId}/horizontalAutoscalePolicy/' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name groupId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } SetGroupName/Description { $enum.HelpUri += '#groups-set-group-namedescription' $enum.Structure = 'PATCH https://api.ctl.io/v2/groups/{accountAlias}/{groupId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name groupId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } SetGroupParent { $enum.HelpUri += '#groups-set-group-parent' $enum.Structure = 'PATCH https://api.ctl.io/v2/groups/{accountAlias}/{groupId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name groupId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } SetGroupScheduledActivities { $enum.HelpUri += '#groups-set-group-scheduled-activities' $enum.Structure = 'POST https://api.ctl.io/v2/groups/{accountAlias}/{groupId}/ScheduledActivities/' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name groupId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } } } 'GroupActions' { switch -Exact ($action) { ArchiveGroup { $enum.HelpUri += '#group-actions-archive-group' $enum.Structure = 'POST https://api.ctl.io/v2/groups/{accountAlias}/{groupId}/archive' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name groupId -mandatory -alias id } RestoreGroup { $enum.HelpUri += '#group-actions-restore-group' $enum.Structure = 'POST https://api.ctl.io/v2/groups/{accountAlias}/{groupId}/restore' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name groupId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } } } 'IntrusionPrevention' { switch -Exact ($action) { CreateIntrusionProtectionServiceNotifications { $enum.HelpUri += '#intrusion-prevention-ips-configure-intrusion-protection-service-notifications' $enum.Structure = 'PUT https://api.client-security.ctl.io/ips/api/notifications/{accountAlias}/{serverName}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverName -mandatory $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } UpdateIntrusionProtectionServiceNotifications { $enum.HelpUri += '#intrusion-prevention-ips-configure-intrusion-protection-service-notifications' $enum.Structure = 'PUT https://api.client-security.ctl.io/ips/api/notifications/{accountAlias}/{serverName}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverName -mandatory $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } GetIntrusionProtectionServiceNotifications { $enum.HelpUri += '#intrusion-prevention-ips-configure-intrusion-protection-service-notifications' $enum.Structure = 'GET https://api.client-security.ctl.io/ips/api/notifications/{accountAlias}/{serverName}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverName -mandatory } DeleteIntrusionProtectionServiceNotifications { $enum.HelpUri += '#DELETE-prevention-ips-configure-intrusion-protection-service-notifications' $enum.Structure = 'GET https://api.client-security.ctl.io/ips/api/notifications/{accountAlias}/{serverName}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverName -mandatory } InstallIntrusionProtectionServiceAgent { $enum.HelpUri += '#intrusion-prevention-ips-install-intrusion-protection-service-agent' $enum.Structure = 'POST https://api.client-security.ctl.io/ips/api/app/' $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } UninstallIntrusionProtectionServiceAgent { $enum.HelpUri += '#intrusion-prevention-ips-uninstall-intrusion-protection-service-agent' $enum.Structure = 'DELETE https://api.client-security.ctl.io/ips/api/app/' $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } } } 'Networks' { switch -Exact ($action) { ClaimNetwork { $enum.HelpUri += '#networks-claim-network' $enum.Structure = 'POST https://api.ctl.io/v2-experimental/networks/{accountAlias}/{dataCenter}/claim' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc } GetIPAddressList { $enum.HelpUri += '#networks-get-ip-address-list' $enum.Structure = 'GET https://api.ctl.io/v2-experimental/networks/{accountAlias}/{dataCenter}/{networkId}/ipAddresses?type={type}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name networkId -mandatory -alias id $parameters += New-DynamicParameter -name type -values claimed,free,all } GetNetworkList { $enum.HelpUri += '#networks-get-network-list' $enum.Structure = 'GET https://api.ctl.io/v2-experimental/networks/{accountAlias}/{dataCenter}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc } GetNetwork { $enum.HelpUri += '#networks-get-network' $enum.Structure = 'GET https://api.ctl.io/v2-experimental/networks/{accountAlias}/{dataCenter}/{networkId}?ipAddresses={ipAddresses}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name networkId -mandatory -alias id $parameters += New-DynamicParameter -name ipAddresses -values none,claimed,free,all } ReleaseNetwork { $enum.HelpUri += '#networks-release-network' $enum.Structure = 'POST https://api.ctl.io/v2-experimental/networks/{accountAlias}/{dataCenter}/{networkId}/release' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name networkId -mandatory -alias id } CreateaSitetoSiteVPN { $enum.HelpUri += '#networks-create-a-site-to-site-vpn' $enum.Structure = 'POST https://api.ctl.io/v2/siteToSiteVpn?account={accountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } DeleteaSitetoSiteVPN { $enum.HelpUri += '#networks-delete-a-site-to-site-vpn' $enum.Structure = 'DELETE https://api.ctl.io/v2/siteToSiteVpn/{vpnId}?account={accountAlias}' $parameters += New-DynamicParameter -name vpnId -mandatory -alias id $parameters += New-DynamicParameter -name accountAlias -alias alias } GetDetailsforaSitetoSiteVPN { $enum.HelpUri += '#networks-get-details-for-a-site-to-site-vpn' $enum.Structure = 'GET https://api.ctl.io/v2/siteToSiteVpn/{vpnId}?account={accountAlias}' $parameters += New-DynamicParameter -name vpnId -mandatory -alias id $parameters += New-DynamicParameter -name accountAlias -alias alias } GetSitetoSiteVPNs { $enum.HelpUri += '#networks-get-site-to-site-vpns' $enum.Structure = 'GET https://api.ctl.io/v2/siteToSiteVpn?account={accountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias } UpdateaSitetoSiteVPN { $enum.HelpUri += '#networks-update-a-site-to-site-vpn' $enum.Structure = 'PUT https://api.ctl.io/v2/siteToSiteVpn/{vpnId}?account={accountAlias}' $parameters += New-DynamicParameter -name vpnId -mandatory -alias id $parameters += New-DynamicParameter -name accountAlias -mandatory -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } UpdateNetwork { $enum.HelpUri += '#networks-update-network' $enum.Structure = 'PUT https://api.ctl.io/v2-experimental/networks/{accountAlias}/{dataCenter}/{networkId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name networkId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } } } 'Patching' { switch -Exact ($action) { ApplyingPatchestoOperatingSystems { $enum.HelpUri += '#patching-applying-patches-to-operating-systems' $enum.Structure = 'POST https://api.ctl.io/v2/operations/{accountAlias}/servers/executePackage' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } GetDetailsofPatchesAppliedtoaServerDuringaSingleExecution { $enum.HelpUri += '#patching-get-details-of-patches-applied-to-a-server-during-a-single-execution' $enum.Structure = 'GET https://patching.useast.appfog.ctl.io/rest/servers/{accountAlias}/server/{serverID}/patch/{execution_id}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverID -mandatory $parameters += New-DynamicParameter -name execution_id -mandatory } GetaSummaryofAllPatchesDeployedtoaServer { $enum.HelpUri += '#patching-get-a-summary-of-all-patches-deployed-to-a-server' $enum.Structure = 'GET https://patching.useast.appfog.ctl.io/rest/servers/{accountAlias}/server/{serverID}/patch' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory } } } 'PowerOperations' { switch -Exact ($action) { PauseServer { $enum.HelpUri += '#power-operations-pause-server' $enum.Structure = 'POST https://api.ctl.io/v2/operations/{accountAlias}/servers/pause' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } PowerOffServer { $enum.HelpUri += '#power-operations-power-off-server' $enum.Structure = 'POST https://api.ctl.io/v2/operations/{accountAlias}/servers/powerOff' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } PowerOnServer { $enum.HelpUri += '#power-operations-power-on-server' $enum.Structure = 'POST https://api.ctl.io/v2/operations/{accountAlias}/servers/powerOn' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } RebootServer { $enum.HelpUri += '#power-operations-reboot-server' $enum.Structure = 'POST https://api.ctl.io/v2/operations/{accountAlias}/servers/reboot' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } ResetServer { $enum.HelpUri += '#power-operations-reset-server' $enum.Structure = 'POST https://api.ctl.io/v2/operations/{accountAlias}/servers/reset' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } SetMaintenanceMode { $enum.HelpUri += '#power-operations-set-maintenance-mode' $enum.Structure = 'POST https://api.ctl.io/v2/operations/{accountAlias}/servers/setMaintenance' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } ShutDownServer { $enum.HelpUri += '#power-operations-shut-down-serve' $enum.Structure = 'POST https://api.ctl.io/v2/operations/{accountAlias}/servers/shutDown' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } StartMaintenanceMode { $enum.HelpUri += '#power-operations-start-maintenance-mode' $enum.Structure = 'POST https://api.ctl.io/v2/operations/{accountAlias}/servers/startMaintenance' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } StopMaintenanceMode { $enum.HelpUri += '#power-operations-stop-maintenance-mode' $enum.Structure = 'POST https://api.ctl.io/v2/operations/{accountAlias}/servers/stopMaintenance' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } } } 'Queue' { switch -Exact ($action) { GetStatus { $enum.HelpUri += '#queue-get-status' # $enum.Structure = 'GET https://api.ctl.io/v2-experimental/operations/{accountAlias}/status/{statusId}' $enum.Structure = 'GET https://api.ctl.io/v2/operations/{accountAlias}/status/{statusId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name statusID -mandatory -alias id } } } 'RelationalDatabase' { switch -Exact ($action) { CreateSubscriptionBackupOperation { $enum.HelpUri += '#relational-database-rdbs-create-subscription-backup-operation' $enum.Structure = 'POST https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions/{subscriptionId}/backups/{backupId}/operations' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory $parameters += New-DynamicParameter -name backupId -mandatory $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } CreateSubscriptionBackup { $enum.HelpUri += '#relational-database-rdbs-create-subscription-backup' $enum.Structure = 'POST https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions/{subscriptionId}/backups' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory -alias id } CreateSubscriptionNotificationOperation { $enum.HelpUri += '#relational-database-rdbs-create-subscription-notification-operation' $enum.Structure = 'POST https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions/{subscriptionId}/notifications/{notificationId}/operations' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory $parameters += New-DynamicParameter -name notificationId -mandatory $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } CreateSubscriptionNotification { $enum.HelpUri += '#relational-database-rdbs-create-subscription-notification' $enum.Structure = 'POST https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions/{subscriptionId}/notifications' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } CreateSubscriptionOperation { $enum.HelpUri += '#relational-database-rdbs-create-subscription-operation' $enum.Structure = 'POST https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions/{subscriptionId}/operations' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } CreateSubscription { $enum.HelpUri += '#relational-database-rdbs-create-subscription' $enum.Structure = 'POST https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } DeleteSubscriptionBackup { $enum.HelpUri += '#relational-database-rdbs-delete-subscription-backup' $enum.Structure = 'DELETE https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions/{subscriptionId}/backups/{backupId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory $parameters += New-DynamicParameter -name backupId -mandatory } DeleteSubscriptionNotification { $enum.HelpUri += '#relational-database-rdbs-delete-subscription-notification' $enum.Structure = 'DELETE https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions/{subscriptionId}/notifications/{notificationId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory $parameters += New-DynamicParameter -name notificationId -mandatory } DeleteSubscription { $enum.HelpUri += '#relational-database-rdbs-delete-subscription' $enum.Structure = 'DELETE https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions/{subscriptionId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory -alias id } GetBilling { $enum.HelpUri += '#relational-database-rdbs-get-billing' $enum.Structure = 'GET https://api.rdbs.ctl.io/v1/{accountAlias}/billing?subscriptionId={subscriptionId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory -alias id } GetDatacenters { $enum.HelpUri += '#relational-database-rdbs-get-datacenters' $enum.Structure = 'GET https://api.rdbs.ctl.io/v1/datacenters' } GetHistory { $enum.HelpUri += '#relational-database-rdbs-get-history' $enum.Structure = 'GET https://api.rdbs.ctl.io/v1/{accountAlias}/history?subscriptionId={subscriptionId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -alias id } GetPromotions { $enum.HelpUri += '#relational-database-rdbs-get-promotions' $enum.Structure = 'GET https://api.rdbs.ctl.io/v1/{accountAlias}/promotions' $parameters += New-DynamicParameter -name accountAlias -alias alias } GetSubscriptionBackups { $enum.HelpUri += '#relational-database-rdbs-get-subscription-backups' $enum.Structure = 'GET https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions/{subscriptionId}/backups' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory -alias id } GetSubscriptionCertificate { $enum.HelpUri += '#relational-database-rdbs-get-subscription-certificate' $enum.Structure = 'GET https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions/{subscriptionId}/certificate' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory -alias id } GetSubscriptionNotifications { $enum.HelpUri += '#relational-database-rdbs-get-subscription-notifications' $enum.Structure = 'GET https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions/{subscriptionId}/notifications' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory -alias id } GetSubscription { $enum.HelpUri += '#relational-database-rdbs-get-subscription' $enum.Structure = 'GET https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions/{subscriptionId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory -alias id } GetSubscriptions { $enum.HelpUri += '#relational-database-rdbs-get-subscriptions' $enum.Structure = 'GET https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions?dataCenter={dataCenterId}&status={status}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenterId -alias dc -values $enum.DataCenterList $parameters += New-DynamicParameter -name status -values ACTIVE,BACKING_UP,CONFIGURING,DELETED,FAILED,PENDING,READY,RESTORING,SUCCESS,TERMINATED,UNKNOWN } PatchSubscription { $enum.HelpUri += '#relational-database-rdbs-patch-subscription' $enum.Structure = 'PATCH https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions/{subscriptionId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory -alias id $parameters += New-DynamicParameter -name content -type ([object]) } UpdateSubscriptionNotification { $enum.HelpUri += '#relational-database-rdbs-update-subscription-notification' $enum.Structure = 'PUT https://api.rdbs.ctl.io/v1/{accountAlias}/subscriptions/{subscriptionId}/notifications/{notificationId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name subscriptionId -mandatory -alias id $parameters += New-DynamicParameter -name notificationId -mandatory $parameters += New-DynamicParameter -name content -type ([object]) } } } 'Servers' { switch -Exact ($action) { AddSecondaryNetwork { $enum.HelpUri += '#servers-add-secondary-network' $enum.Structure = 'POST https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/networks' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } CloneServer { $enum.HelpUri += '#servers-clone-server' $enum.Structure = 'POST https://api.ctl.io/v2/servers/{accountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } CreateServer { $enum.HelpUri += '#servers-create-server' $enum.Structure = 'POST https://api.ctl.io/v2/servers/{accountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } DeleteServer { $enum.HelpUri += '#servers-delete-server' $enum.Structure = 'DELETE https://api.ctl.io/v2/servers/{accountAlias}/{serverId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name } GetAvailableServerImports { $enum.HelpUri += '#servers-get-available-server-imports' $enum.Structure = 'GET https://api.ctl.io/v2/vmImport/{accountAlias}/{dataCenter}/available' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList } GetServerCredentials { $enum.HelpUri += '#servers-get-server-credentials' $enum.Structure = 'GET https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/credentials' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name } GetServer { $enum.HelpUri += '#servers-get-server' $enum.Structure = 'GET https://api.ctl.io/v2/servers/{accountAlias}/{serverId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name } ImportServer { $enum.HelpUri += '#servers-import-server' $enum.Structure = 'POST https://api.ctl.io/v2/vmImport/{accountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } RemoveSecondaryNetwork { $enum.HelpUri += '#servers-remove-secondary-network' $enum.Structure = 'DELETE https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/networks/{networkId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name $parameters += New-DynamicParameter -name networkId -mandatory } SetServerCPU/Memory { $enum.HelpUri += '#servers-set-server-cpumemory' $enum.Structure = 'PATCH https://api.ctl.io/v2/servers/{accountAlias}/{serverId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } SetServerCredentials { $enum.HelpUri += '#servers-set-server-credentials' $enum.Structure = 'PATCH https://api.ctl.io/v2/servers/{accountAlias}/{serverId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } SetServerCustomFields { $enum.HelpUri += '#servers-set-server-custom-fields' $enum.Structure = 'PATCH https://api.ctl.io/v2/servers/{accountAlias}/{serverId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } SetServerDescription/Group { $enum.HelpUri += '#servers-set-server-descriptiongroup' $enum.Structure = 'PATCH https://api.ctl.io/v2/servers/{accountAlias}/{serverId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } SetServerDisks { $enum.HelpUri += '#servers-set-server-disks' $enum.Structure = 'PATCH https://api.ctl.io/v2/servers/{accountAlias}/{serverId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } } } 'ServerActions' { switch -Exact ($action) { ArchiveServer { $enum.HelpUri += '#server-actions-archive-server' $enum.Structure = 'POST https://api.ctl.io/v2/operations/{accountAlias}/servers/archive' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } CreateSnapshot { $enum.HelpUri += '#server-actions-create-snapshot' $enum.Structure = 'POST https://api.ctl.io/v2/operations/{accountAlias}/servers/createSnapshot' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } DeleteSnapshot { $enum.HelpUri += '#server-actions-delete-snapshot' $enum.Structure = 'DELETE https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/snapshots/{snapshotId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name $parameters += New-DynamicParameter -name snapshotId -mandatory } ExecutePackage { $enum.HelpUri += '#server-actions-execute-package' $enum.Structure = 'POST https://api.ctl.io/v2/operations/{accountAlias}/servers/executePackage' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } RestoreServer { $enum.HelpUri += '#server-actions-restore-server' $enum.Structure = 'POST https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/restore' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } ReverttoSnapshot { $enum.HelpUri += '#server-actions-revert-to-snapshot' $enum.Structure = 'POST https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/snapshots/{snapshotId}/restore' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name $parameters += New-DynamicParameter -name snapshotId -mandatory } } } 'SharedLoadBalancers' { switch -Exact ($action) { CreateLoadBalancerPool { $enum.HelpUri += '#shared-load-balancers-create-load-balancer-pool' $enum.Structure = 'POST https://api.ctl.io/v2/sharedLoadBalancers/{accountAlias}/{dataCenter}/{loadBalancerId}/pools' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name loadBalancerId -mandatory $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } CreateSharedLoadBalancer { $enum.HelpUri += '#shared-load-balancers-create-shared-load-balancer' $enum.Structure = 'POST https://api.ctl.io/v2/sharedLoadBalancers/{accountAlias}/{dataCenter}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } DeleteLoadBalancerPool { $enum.HelpUri += '#shared-load-balancers-delete-load-balancer-pool' $enum.Structure = 'DELETE https://api.ctl.io/v2/sharedLoadBalancers/{accountAlias}/{dataCenter}/{loadBalancerId}/pools/{poolId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name loadBalancerId -mandatory $parameters += New-DynamicParameter -name poolId -mandatory } DeleteSharedLoadBalancer { $enum.HelpUri += '#shared-load-balancers-delete-shared-load-balancer' $enum.Structure = 'DELETE https://api.ctl.io/v2/sharedLoadBalancers/{accountAlias}/{dataCenter}/{loadBalancerId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name loadBalancerId -mandatory } GetLoadBalancerNodes { $enum.HelpUri += '#shared-load-balancers-get-load-balancer-nodes' $enum.Structure = 'https://api.ctl.io/v2/sharedLoadBalancers/{accountAlias}/{dataCenter}/{loadBalancerId}/pools/{poolId}/nodes' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name loadBalancerId -mandatory $parameters += New-DynamicParameter -name poolId -mandatory } GetLoadBalancerPool { $enum.HelpUri += '#shared-load-balancers-get-load-balancer-pool' $enum.Structure = 'GET https://api.ctl.io/v2/sharedLoadBalancers/{accountAlias}/{dataCenter}/{loadBalancerId}/pools/{poolId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name loadBalancerId -mandatory $parameters += New-DynamicParameter -name poolId -mandatory } GetLoadBalancerPools { $enum.HelpUri += '#shared-load-balancers-get-load-balancer-pools' $enum.Structure = 'GET https://api.ctl.io/v2/sharedLoadBalancers/{accountAlias}/{dataCenter}/{loadBalancerId}/pools' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name loadBalancerId -mandatory } GetSharedLoadBalancer { $enum.HelpUri += '#shared-load-balancers-get-shared-load-balancer' $enum.Structure = 'GET https://api.ctl.io/v2/sharedLoadBalancers/{accountAlias}/{dataCenter}/{loadBalancerId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name loadBalancerId -mandatory } GetSharedLoadBalancers { $enum.HelpUri += '#shared-load-balancers-get-shared-load-balancers' $enum.Structure = 'GET https://api.ctl.io/v2/sharedLoadBalancers/{accountAlias}/{dataCenter}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc } UpdateLoadBalancerNodes { $enum.HelpUri += '#shared-load-balancers-update-load-balancer-nodes' $enum.Structure = 'PUT https://api.ctl.io/v2/sharedLoadBalancers/{accountAlias}/{dataCenter}/{loadBalancerId}/pools/{poolId}/nodes' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name loadBalancerId -mandatory $parameters += New-DynamicParameter -name poolId -mandatory $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } UpdateLoadBalancerPool { $enum.HelpUri += '#shared-load-balancers-update-load-balancer-pool' $enum.Structure = 'PUT https://api.ctl.io/v2/sharedLoadBalancers/{accountAlias}/{dataCenter}/{loadBalancerId}/pools/{poolId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name loadBalancerId -mandatory $parameters += New-DynamicParameter -name poolId -mandatory $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } UpdateSharedLoadBalancer { $enum.HelpUri += '#shared-load-balancers-update-shared-load-balancer' $enum.Structure = 'PUT https://api.ctl.io/v2/sharedLoadBalancers/{accountAlias}/{dataCenter}/{loadBalancerId}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name dataCenter -values $DataCenterList -alias dc $parameters += New-DynamicParameter -name loadBalancerId -mandatory $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } } } 'SimpleBackup' { switch -Exact ($action) { CreatePolicy { $enum.HelpUri += '#simple-backup-create-policy' $enum.Structure = 'POST https://api.backup.ctl.io/clc-backup-api/api/accountPolicies' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } CreateServerPolicies { $enum.HelpUri += '#simple-backup-create-server-policies' $enum.Structure = 'POST https://api.backup.ctl.io/clc-backup-api/api/accountPolicies/{accountPolicyId}/serverPolicies' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name accountPolicyId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } CreateServerPolicy { $enum.HelpUri += '#simple-backup-create-server-policy' $enum.Structure = 'POST https://api.backup.ctl.io/clc-backup-api/api/accountPolicies/{accountPolicyId}/serverPolicies' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name accountPolicyId -mandatory -alias id $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } DeleteServerPolicy { $enum.HelpUri += '#simple-backup-delete-server-policy' $enum.Structure = 'DELETE https://api.backup.ctl.io/clc-backup-api/api/accountPolicies/{accountPolicyId}/serverPolicies/{serverPolicyId}' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name accountPolicyId -mandatory $parameters += New-DynamicParameter -name serverPolicyId -mandatory } GetAllPoliciesEligibleForServerId { $enum.HelpUri += '#simple-backup-get-all-policies-eligible-for-serverid' $enum.Structure = 'GET https://api.backup.ctl.io/clc-backup-api/api/accountPolicies/servers/{serverId}' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name serverId -mandatory -alias id,name $parameters += New-DynamicParameter -name query -type ([object]) } GetAllRegions { $enum.HelpUri += '#simple-backup-get-all-regions' $enum.Structure = 'GET https://api.backup.ctl.io/clc-backup-api/api/regions' } GetDataCenterList { $enum.HelpUri += '#simple-backup-get-datacenter-list' $enum.Structure = 'GET https://api.backup.ctl.io/clc-backup-api/api/datacenters' } GetOsTypes { $enum.HelpUri += '#simple-backup-get-os-types' $enum.Structure = 'GET https://api.backup.ctl.io/clc-backup-api/api/osTypes' } GetPolicies { $enum.HelpUri += '#simple-backup-get-policies' $enum.Structure = 'GET https://api.backup.ctl.io/clc-backup-api/api/accountPolicies' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name query -type ([object]) } GetPolicyDetailsByServer { $enum.HelpUri += '#simple-backup-get-policy-details-by-server' $enum.Structure = 'GET https://api.backup.ctl.io/clc-backup-api/api/serverPolicyDetails' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name query -mandatory -type ([object]) } GetPolicy { $enum.HelpUri += '#simple-backup-get-policy' $enum.Structure = 'GET https://api.backup.ctl.io/clc-backup-api/api/accountPolicies/{accountPolicyId}' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name accountPolicyId -mandatory -alias id } GetRestorePointDetails { $enum.HelpUri += '#simple-backup-get-restore-point-details' $enum.Structure = 'GET https://api.backup.ctl.io/clc-backup-api/api/accountPolicies/{accountPolicyId}/serverPolicies/{serverPolicyId}/restorePointDetails' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name accountPolicyId -mandatory $parameters += New-DynamicParameter -name serverPolicyId -mandatory $parameters += New-DynamicParameter -name query -mandatory -type ([object]) } GetServerPolicies { $enum.HelpUri += '#simple-backup-get-server-policies' $enum.Structure = 'GET https://api.backup.ctl.io/clc-backup-api/api/accountPolicies/{accountPolicyId}/serverPolicies' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name accountPolicyId -mandatory -alias id } GetServerPolicy { $enum.HelpUri += '#simple-backup-get-server-policy' $enum.Structure = 'GET https://api.backup.ctl.io/clc-backup-api/api/accountPolicies/{accountPolicyId}/serverPolicies/{serverPolicyId}' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name accountPolicyId -mandatory $parameters += New-DynamicParameter -name serverPolicyId -mandatory } GetServersByDataCenter { $enum.HelpUri += '#simple-backup-get-servers-by-datacenter' $enum.Structure = 'GET https://api.backup.ctl.io/clc-backup-api//api/datacenters/{datacenter}/servers' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name datacenter -mandatory -values $DataCenterList -alias dc } GetStoredDataByServerPolicy { $enum.HelpUri += '#simple-backup-get-stored-data-by-server-policy' $enum.Structure = 'GET https://api.backup.ctl.io/clc-backup-api/api/accountPolicies/{accountPolicyId}/serverPolicies/{serverPolicyId}/storedData' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name accountPolicyId -mandatory $parameters += New-DynamicParameter -name serverPolicyId -mandatory $parameters += New-DynamicParameter -name query -mandatory -type ([object]) } PatchPolicy { $enum.HelpUri += '#simple-backup-patch-policy' $enum.Structure = 'PATCH https://api.backup.ctl.io/clc-backup-api/api/accountPolicies/{accountPolicyId}/serverPolicies/{serverPolicyId}' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name accountPolicyId -mandatory $parameters += New-DynamicParameter -name serverPolicyId -mandatory $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } UpdatePolicy { $enum.HelpUri += '#simple-backup-update-policy' $enum.Structure = 'PUT https://api.backup.ctl.io/clc-backup-api/api/accountPolicies/{accountPolicyId}' $parameters += New-DynamicParameter -name clc-alias -alias alias $parameters += New-DynamicParameter -name accountPolicyId -mandatory $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } } } 'Webhooks' { switch -Exact ($action) { AddWebhookTargetUri { $enum.HelpUri += '#webhooks-add-webhook-target-uri' $enum.Structure = 'POST https://api.ctl.io/v2/webhooks/{accountAlias}/{event}/configuration/targetUris' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name event -mandatory } DeleteWebhookTargetUri { $enum.HelpUri += '#webhooks-delete-webhook-target-uri' $enum.Structure = 'DELETE https://api.ctl.io/v2/webhooks/{accountAlias}/{event}/configuration/targetUris?targetUri={uri}' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name event -mandatory $parameters += New-DynamicParameter -name uri -mandatory } DeleteWebhook { $enum.HelpUri += '#webhooks-delete-webhook' $enum.Structure = 'DELETE https://api.ctl.io/v2/webhooks/{accountAlias}/{event}/configuration' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name event -mandatory } GetWebhooks { $enum.HelpUri += '#webhooks-get-webhooks' $enum.Structure = 'GET https://api.ctl.io/v2/webhooks/{accountAlias}' $parameters += New-DynamicParameter -name accountAlias -alias alias } SetWebhook { $enum.HelpUri += '#webhooks-set-webhook' $enum.Structure = 'PUT https://api.ctl.io/v2/webhooks/{accountAlias}/{event}/configuration' $parameters += New-DynamicParameter -name accountAlias -alias alias $parameters += New-DynamicParameter -name event -mandatory $parameters += New-DynamicParameter -name content -mandatory -type ([object]) } } } } # dictionary $dictionary = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary $parameters.ForEach{$dictionary.Add($_.Name,$_)} $dictionary } Begin { function convertToJson { param ([object]$object) $jsonpattern = '(^\[.*|\n\]$)|(^{.*|\n}$)' $object = if ($object -is [string] -and $object -match $jsonpattern) { # presume JSON $object } else { # everything else try to convert $object | ConvertTo-Json -Depth 10 -Compress } if ($object -notmatch $jsonpattern) { # ConvertTo-Json doesn't add [] for single values $object = "[$object]" } return $object } } Process { # if help is called, open help uri and exit if ($Help) { Start-Process $enum.HelpUri break } Write-Verbose -Message "ParameterSetName $($PSCmdlet.ParameterSetName)" # if Warning or experimental, display if ($enum.Structure -match 'experimental') { Write-Warning -Message "ClcControl APIv2 method '$($object)\$($action)' is experimental." } if ($enum.Warning) { Write-Warning -Message "ClcControl APIv2 method '$($object)\$($action)' is $($enum.Warning)." } # split structure $method, $uri = $enum.Structure -split '\s+' # set the default values of authenticated user from WebSession Headers @( 'accountAlias' 'clc-alias' 'dataCenter' 'userName' ).ForEach{ if ( $dictionary.ContainsKey($_) -and -not $dictionary.$_.Value ) { $dictionary.$_.Value = switch -Regex ($_) { 'accountAlias|clc-alias' { $WebSession.Headers.AccountAlias } 'dataCenter' { $WebSession.Headers.LocationAlias } 'userName' { $WebSession.Headers.UserName } } } } # split uri to uribase and uri query $uri, $uriquery = $uri -split '\?' # replace endpoint in uri if it's different in headers if ( $WebSession.Headers.ContainsKey('Endpoint') -and $uri -notmatch [regex]::Escape($WebSession.Headers.Endpoint) ) { $uri = $uri -replace '^https:\/{2}.*\/v2', "https://$($WebSession.Headers.Endpoint)/v2" } # replace placeholders {variableName} with values in uribase [regex]::Matches($uri,'{\w+}').Value | ForEach-Object -Process { $name = $_ -replace '{|}' $value = $dictionary.$name.Value if ($value -is [datetime]) { $value = $value.ToString('s') } $uri = $uri -replace $_, $value } # replace placeholders {variableName} with values in uriquery if ($uriquery) { $uriquery -split '&' | ForEach-Object ` -Begin { $queries = @() } ` -Process { $result = [regex]::Match($_,'{\w+}') $queries += if ($result.Success) { $name = $result.Value -replace '{|}' $value = $dictionary.$name.Value if ($value) { if ($value -is [datetime]) { $value = $value.ToString('s') } $_ -replace "{$name}", $value } } else { $_ } } ` -End { if ($queries) { $uri += '?' + ($queries -join '&') } } } # SBS API: add querystring to uri if ($dictionary.ContainsKey('query')) { $query = if ($dictionary.query.Value -is [string]) { $dictionary.query.Value | ConvertFrom-Json } else { [pscustomobject]$dictionary.query.Value } $queryString = $query.psobject.properties.ForEach{ "$($_.Name)=$($_.Value)" } -join '&' if ($queryString) { $uri += "?$queryString" } } # construct splat $params = @{ Uri = $uri Method = $method WebSession = $WebSession TimeoutSec = $TimeOut ErrorAction = 'Stop' } # SBS API: add 'clc-alias' to WebSession.Headers if ( $PSCmdlet.ParameterSetName -eq 'SimpleBackup' -and $params.WebSession.Headers.Keys -notcontains 'clc-alias' ) { $alias = if ($dictionary.'clc-alias'.Value) { $dictionary.'clc-alias'.Value } else { $WebSession.Headers.AccountAlias } $params.WebSession.Headers.Add('clc-alias',$alias) } # add content to body if ($dictionary.ContainsKey('content')) { $params += @{ Body = convertToJson $dictionary.Content.Value ContentType = 'application/json' } } # verify and INVOKE if ( ( $method -eq 'GET' -and $action -ne 'GetServerCredentials' ) -or $Force -or $PSCmdlet.ShouldProcess($uri,$action) ) { # invoke and return Write-Verbose -Message "Invoke-RestMethod params:$($params | Out-String)" # invoke $response = Invoke-RestMethod @params Write-Verbose -Message "Invoke-RestMethod response:$($response | Out-String)" if ($Json) { $response | ConvertTo-Json -Depth 10 } else { $response } } } } |