Skip to content

Commit 95847de

Browse files
authored
Merge pull request Azure#29 from viananth/AzureStack
Support should process for Create or Update
2 parents c97807d + e28c299 commit 95847de

File tree

3 files changed

+72
-51
lines changed

3 files changed

+72
-51
lines changed

src/StackAdmin/Azs.Network.Admin/Module/Azs.Network.Admin/Generated.PowerShell.Commands/SwaggerPathCommands/New-AzsNetworkQuota.ps1

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Licensed under the MIT License. See License.txt in the project root for license
5050
#>
5151
function New-AzsNetworkQuota {
5252
[OutputType([Microsoft.AzureStack.Management.Network.Admin.Models.Quota])]
53-
[CmdletBinding(DefaultParameterSetName = 'Quotas_CreateOrUpdate')]
53+
[CmdletBinding(DefaultParameterSetName = 'Quotas_CreateOrUpdate', SupportsShouldProcess = $true)]
5454
param(
5555
[Parameter(Mandatory = $true, ParameterSetName = 'Quotas_CreateOrUpdate')]
5656
[ValidateNotNullOrEmpty()]
@@ -92,7 +92,11 @@ function New-AzsNetworkQuota {
9292
[Parameter(Mandatory = $false, DontShow = $true)]
9393
[ValidateSet('None', 'Prepare', 'Commit', 'Abort')]
9494
[string]
95-
$MigrationPhase = 'Prepare'
95+
$MigrationPhase = 'Prepare',
96+
97+
[Parameter(Mandatory = $false)]
98+
[switch]
99+
$Force
96100
)
97101

98102
Begin {
@@ -141,22 +145,26 @@ function New-AzsNetworkQuota {
141145
}
142146
$Quota = New-QuotaObject @utilityCmdParams
143147

144-
if ('Quotas_CreateOrUpdate' -eq $PsCmdlet.ParameterSetName) {
145-
Write-Verbose -Message 'Performing operation CreateOrUpdateWithHttpMessagesAsync on $NetworkAdminClient.'
146-
$TaskResult = $NetworkAdminClient.Quotas.CreateOrUpdateWithHttpMessagesAsync($Location, $Name, $Quota)
147-
} else {
148-
Write-Verbose -Message 'Failed to map parameter set to operation method.'
149-
throw 'Module failed to find operation to execute.'
150-
}
151-
152-
if ($TaskResult) {
153-
$GetTaskResult_params = @{
154-
TaskResult = $TaskResult
148+
if ($PSCmdlet.ShouldProcess("$Name" , "Create new network quota")) {
149+
if (($Force.IsPresent -or $PSCmdlet.ShouldContinue("Create new network quota?", "Performing operation CreateOrUpdateWithHttpMessagesAsync on $Name."))) {
150+
if ('Quotas_CreateOrUpdate' -eq $PsCmdlet.ParameterSetName) {
151+
Write-Verbose -Message 'Performing operation CreateOrUpdateWithHttpMessagesAsync on $NetworkAdminClient.'
152+
$TaskResult = $NetworkAdminClient.Quotas.CreateOrUpdateWithHttpMessagesAsync($Location, $Name, $Quota)
153+
}
154+
else {
155+
Write-Verbose -Message 'Failed to map parameter set to operation method.'
156+
throw 'Module failed to find operation to execute.'
157+
}
158+
159+
if ($TaskResult) {
160+
$GetTaskResult_params = @{
161+
TaskResult = $TaskResult
162+
}
163+
Get-TaskResult @GetTaskResult_params
164+
}
155165
}
156-
Get-TaskResult @GetTaskResult_params
157166
}
158167
}
159-
160168
End {
161169
if ($tracerObject) {
162170
$global:DebugPreference = $oldDebugPreference

src/StackAdmin/Azs.Network.Admin/Module/Azs.Network.Admin/Generated.PowerShell.Commands/SwaggerPathCommands/Set-AzsNetworkQuota.ps1

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Licensed under the MIT License. See License.txt in the project root for license
5757
#>
5858
function Set-AzsNetworkQuota {
5959
[OutputType([Microsoft.AzureStack.Management.Network.Admin.Models.Quota])]
60-
[CmdletBinding(DefaultParameterSetName = 'Quotas')]
60+
[CmdletBinding(DefaultParameterSetName = 'Quotas', SupportsShouldProcess = $true)]
6161
param(
6262
[Parameter(Mandatory = $true, ParameterSetName = 'Quotas')]
6363
[ValidateNotNullOrEmpty()]
@@ -104,7 +104,11 @@ function Set-AzsNetworkQuota {
104104
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'InputObject')]
105105
[ValidateNotNullOrEmpty()]
106106
[Microsoft.AzureStack.Management.Network.Admin.Models.Quota]
107-
$InputObject
107+
$InputObject,
108+
109+
[Parameter(Mandatory = $false)]
110+
[switch]
111+
$Force
108112
)
109113

110114
Begin {
@@ -145,50 +149,58 @@ function Set-AzsNetworkQuota {
145149

146150
if ('ResourceId' -eq $PsCmdlet.ParameterSetName) {
147151
$GetArmResourceIdParameterValue_params['Id'] = $ResourceId
148-
} else {
152+
}
153+
else {
149154
$GetArmResourceIdParameterValue_params['Id'] = $InputObject.Id
150155
$Quota = $InputObject
151156
}
152157
$ArmResourceIdParameterValues = Get-ArmResourceIdParameterValue @GetArmResourceIdParameterValue_params
153158

154159
$Location = $ArmResourceIdParameterValues['location']
155160
$Name = $ArmResourceIdParameterValues['resourceName']
156-
} elseif (-not $PSBoundParameters.ContainsKey('Location')) {
161+
}
162+
elseif (-not $PSBoundParameters.ContainsKey('Location')) {
157163
$Location = (Get-AzureRMLocation).Location
158164
}
159165

160-
if ('Quotas' -eq $PsCmdlet.ParameterSetName -or 'InputObject' -eq $PsCmdlet.ParameterSetName -or 'ResourceId' -eq $PsCmdlet.ParameterSetName) {
161-
162-
if ($Quota -eq $null) {
163-
$Quota = Get-AzsNetworkQuota -Location $Location -Name $Name
164-
}
165-
166-
$flattenedParameters = @(
167-
'MaxNicsPerSubscription', 'MaxPublicIpsPerSubscription',
168-
'MaxVirtualNetworkGatewayConnectionsPerSubscription', 'MaxVnetsPerSubscription',
169-
'MaxVirtualNetworkGatewaysPerSubscription', 'MaxSecurityGroupsPerSubscription',
170-
'MaxLoadBalancersPerSubscription')
171-
# Update the Quota object
172-
$flattenedParameters | ForEach-Object {
173-
if ($PSBoundParameters.ContainsKey($_)) {
174-
$Quota.$($_) = $PSBoundParameters[$_]
166+
if ($PSCmdlet.ShouldProcess("$Name" , "Create or update network quota")) {
167+
if (($Force.IsPresent -or $PSCmdlet.ShouldContinue("Create or update network quota?", "Performing operation CreateOrUpdateWithHttpMessagesAsync on $Name."))) {
168+
169+
if ('Quotas' -eq $PsCmdlet.ParameterSetName -or 'InputObject' -eq $PsCmdlet.ParameterSetName -or 'ResourceId' -eq $PsCmdlet.ParameterSetName) {
170+
171+
if ($Quota -eq $null) {
172+
$Quota = Get-AzsNetworkQuota -Location $Location -Name $Name
173+
}
174+
175+
$flattenedParameters = @(
176+
'MaxNicsPerSubscription', 'MaxPublicIpsPerSubscription',
177+
'MaxVirtualNetworkGatewayConnectionsPerSubscription', 'MaxVnetsPerSubscription',
178+
'MaxVirtualNetworkGatewaysPerSubscription', 'MaxSecurityGroupsPerSubscription',
179+
'MaxLoadBalancersPerSubscription')
180+
# Update the Quota object
181+
$flattenedParameters | ForEach-Object {
182+
if ($PSBoundParameters.ContainsKey($_)) {
183+
$Quota.$($_) = $PSBoundParameters[$_]
184+
}
185+
}
186+
187+
Write-Verbose -Message 'Performing operation CreateOrUpdateWithHttpMessagesAsync on $NetworkAdminClient.'
188+
$TaskResult = $NetworkAdminClient.Quotas.CreateOrUpdateWithHttpMessagesAsync($Location, $Name, $Quota)
189+
}
190+
else {
191+
Write-Verbose -Message 'Failed to map parameter set to operation method.'
192+
throw 'Module failed to find operation to execute.'
175193
}
176-
}
177194

178-
Write-Verbose -Message 'Performing operation CreateOrUpdateWithHttpMessagesAsync on $NetworkAdminClient.'
179-
$TaskResult = $NetworkAdminClient.Quotas.CreateOrUpdateWithHttpMessagesAsync($Location, $Name, $Quota)
180-
} else {
181-
Write-Verbose -Message 'Failed to map parameter set to operation method.'
182-
throw 'Module failed to find operation to execute.'
183-
}
195+
if ($TaskResult) {
196+
$GetTaskResult_params = @{
197+
TaskResult = $TaskResult
198+
}
184199

185-
if ($TaskResult) {
186-
$GetTaskResult_params = @{
187-
TaskResult = $TaskResult
188-
}
189-
190-
Get-TaskResult @GetTaskResult_params
200+
Get-TaskResult @GetTaskResult_params
191201

202+
}
203+
}
192204
}
193205
}
194206

src/StackAdmin/Azs.Network.Admin/Tests/src/Network.Tests.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ InModuleScope Azs.Network.Admin {
209209
-MaxNicsPerSubscription 4 `
210210
-MaxSecurityGroupsPerSubscription 2 `
211211
-Name $Name `
212-
-Location local
212+
-Location local `
213+
-Force
213214
}
214215

215216
function DeleteQuota {
@@ -249,7 +250,7 @@ InModuleScope Azs.Network.Admin {
249250
$location = "local"
250251
$quotaName = "TestQuotaForRemoval"
251252

252-
$created = New-AzsNetworkQuota -Name $quotaName -Location $location
253+
$created = New-AzsNetworkQuota -Name $quotaName -Location $location -Force
253254
$quota = Get-AzsNetworkQuota -Name $quotaName -Location $location
254255

255256
$quota | Should Not be $null
@@ -269,7 +270,7 @@ InModuleScope Azs.Network.Admin {
269270
$location = "local"
270271
$quotaName = "TestQuotaForUpdate"
271272

272-
$quota = New-AzsNetworkQuota -Name $quotaName -Location $location
273+
$quota = New-AzsNetworkQuota -Name $quotaName -Location $location -Force
273274
$created = Get-AzsNetworkQuota -Name $quotaName -Location $location
274275

275276
$quota | Should Not be $null
@@ -278,7 +279,7 @@ InModuleScope Azs.Network.Admin {
278279
AssertQuotasAreSame -expected $quota -found $created
279280

280281
# Post update
281-
$updatedQuota = Set-AzsNetworkQuota -Name $quotaName -Location $location -MaxNicsPerSubscription 8
282+
$updatedQuota = Set-AzsNetworkQuota -Name $quotaName -Location $location -MaxNicsPerSubscription 8 -Force
282283
$getUpdatedQuota = Get-AzsNetworkQuota -Name $quotaName -Location $location
283284
AssertQuotasAreSame -expected $updatedQuota -found $getUpdatedQuota
284285

0 commit comments

Comments
 (0)