Skip to content

Commit 0696b2c

Browse files
author
Venkata M
committed
Add DDoS custom policy cmdlets, LB integration, tests, and help
1 parent fe636c0 commit 0696b2c

25 files changed

Lines changed: 9510 additions & 10 deletions

src/Network/Network.Management.Sdk/Generated/Models/DdosCustomPolicy.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ public DdosCustomPolicy()
104104
public System.Collections.Generic.IList<DdosDetectionRule> DetectionRules {get; set; }
105105

106106
/// <summary>
107-
/// Gets or sets the list of frontend IP configurations associated with the
108-
/// custom policy.
107+
/// Gets the list of frontend IP configurations associated with the
108+
/// custom policy. This list is read-only.
109109
/// </summary>
110-
[Newtonsoft.Json.JsonProperty(PropertyName = "properties.frontEndIpConfiguration")]
111-
public System.Collections.Generic.IList<SubResource> FrontEndIPConfiguration {get; set; }
110+
[Newtonsoft.Json.JsonProperty(PropertyName = "properties.frontendIpConfigurations")]
111+
public System.Collections.Generic.IList<SubResource> FrontEndIPConfiguration {get; private set; }
112112
}
113113
}

src/Network/Network.Management.Sdk/Generated/Models/DdosCustomPolicyPropertiesFormat.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public DdosCustomPolicyPropertiesFormat()
7676
public System.Collections.Generic.IList<DdosDetectionRule> DetectionRules {get; set; }
7777

7878
/// <summary>
79-
/// Gets or sets the list of frontend IP configurations associated with the
80-
/// custom policy.
79+
/// Gets the list of frontend IP configurations associated with the
80+
/// custom policy. This list is read-only.
8181
/// </summary>
82-
[Newtonsoft.Json.JsonProperty(PropertyName = "frontEndIpConfiguration")]
83-
public System.Collections.Generic.IList<SubResource> FrontEndIPConfiguration {get; set; }
82+
[Newtonsoft.Json.JsonProperty(PropertyName = "frontendIpConfigurations")]
83+
public System.Collections.Generic.IList<SubResource> FrontEndIPConfiguration {get; private set; }
8484
}
8585
}

src/Network/Network.Management.Sdk/Generated/Models/DdosSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,11 @@ public DdosSettings()
5656
/// </summary>
5757
[Newtonsoft.Json.JsonProperty(PropertyName = "ddosProtectionPlan")]
5858
public SubResource DdosProtectionPlan {get; set; }
59+
60+
/// <summary>
61+
/// Gets or sets the DDoS custom policy associated with the frontend IP configuration.
62+
/// </summary>
63+
[Newtonsoft.Json.JsonProperty(PropertyName = "ddosCustomPolicy")]
64+
public SubResource DdosCustomPolicy {get; set; }
5965
}
6066
}

src/Network/Network.Management.Sdk/Generated/Models/FrontendIPConfiguration.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,11 @@ public FrontendIPConfiguration()
210210
/// </summary>
211211
[Newtonsoft.Json.JsonProperty(PropertyName = "properties.gatewayLoadBalancer")]
212212
public SubResource GatewayLoadBalancer {get; set; }
213+
214+
/// <summary>
215+
/// Gets or sets the DDoS settings of the frontend IP configuration.
216+
/// </summary>
217+
[Newtonsoft.Json.JsonProperty(PropertyName = "properties.ddosSettings")]
218+
public DdosSettings DdosSettings {get; set; }
213219
}
214220
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Network.Test.ScenarioTests;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Xunit;
18+
19+
namespace Commands.Network.Test.ScenarioTests
20+
{
21+
public class DdosCustomPolicyTests : NetworkTestRunner
22+
{
23+
public DdosCustomPolicyTests(Xunit.Abstractions.ITestOutputHelper output)
24+
: base(output)
25+
{
26+
}
27+
28+
[Fact]
29+
[Trait(Category.AcceptanceType, Category.CheckIn)]
30+
[Trait(Category.Owner, NrpTeamAlias.ddos)]
31+
public void TestDdosCustomPolicyCrud()
32+
{
33+
TestRunner.RunTestScript(string.Format("Test-DdosCustomPolicyCRUD"));
34+
}
35+
36+
[Fact]
37+
[Trait(Category.AcceptanceType, Category.CheckIn)]
38+
[Trait(Category.Owner, NrpTeamAlias.ddos)]
39+
public void TestDdosCustomPolicyCrudWithTags()
40+
{
41+
TestRunner.RunTestScript(string.Format("Test-DdosCustomPolicyCRUDWithTags"));
42+
}
43+
44+
[Fact]
45+
[Trait(Category.AcceptanceType, Category.CheckIn)]
46+
[Trait(Category.Owner, NrpTeamAlias.ddos)]
47+
public void TestLoadBalancerFrontendWithDdosCustomPolicy()
48+
{
49+
TestRunner.RunTestScript(string.Format("Test-LoadBalancerFrontendWithDdosCustomPolicy"));
50+
}
51+
52+
[Fact]
53+
[Trait(Category.AcceptanceType, Category.CheckIn)]
54+
[Trait(Category.Owner, NrpTeamAlias.ddos)]
55+
public void TestAddLoadBalancerFrontendWithDdosCustomPolicy()
56+
{
57+
TestRunner.RunTestScript(string.Format("Test-AddLoadBalancerFrontendWithDdosCustomPolicy"));
58+
}
59+
}
60+
}
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
# ----------------------------------------------------------------------------------
2+
# Copyright Microsoft Corporation
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
# ----------------------------------------------------------------------------------
13+
14+
<#
15+
.SYNOPSIS
16+
DDoS custom policy management operations
17+
#>
18+
function Test-DdosCustomPolicyCRUD
19+
{
20+
$rgLocation = Get-ProviderLocation ResourceManagement
21+
$resourceTypeParent = "Microsoft.Network/DdosCustomPolicies"
22+
$location = Get-ProviderLocation $resourceTypeParent
23+
24+
$rgName = Get-ResourceGroupName
25+
$ddosCustomPolicyName = Get-ResourceName
26+
27+
try
28+
{
29+
# Create the resource group
30+
New-AzResourceGroup -Name $rgName -Location $location -Tags @{ testtag = "ddosCustomPolicy tag" }
31+
32+
# Create the DDoS custom policy
33+
$job = New-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName -Location $rgLocation -TrafficType Tcp -PacketsPerSecond 1000000 -AsJob
34+
$job | Wait-Job
35+
$ddosCustomPolicyNew = $job | Receive-Job
36+
37+
Assert-AreEqual $rgName $ddosCustomPolicyNew.ResourceGroupName
38+
Assert-AreEqual $ddosCustomPolicyName $ddosCustomPolicyNew.Name
39+
Assert-NotNull $ddosCustomPolicyNew.Location
40+
Assert-NotNull $ddosCustomPolicyNew.Etag
41+
Assert-NotNull $ddosCustomPolicyNew.ProvisioningState
42+
43+
# Get the DDoS custom policy
44+
$ddosCustomPolicyGet = Get-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName
45+
Assert-AreEqual $rgName $ddosCustomPolicyGet.ResourceGroupName
46+
Assert-AreEqual $ddosCustomPolicyName $ddosCustomPolicyGet.Name
47+
Assert-NotNull $ddosCustomPolicyGet.Location
48+
Assert-NotNull $ddosCustomPolicyGet.Etag
49+
50+
# Remove the DDoS custom policy
51+
$ddosCustomPolicyDelete = Remove-AzDdosCustomPolicy -Name $ddosCustomPolicyName -ResourceGroupName $rgName -PassThru
52+
Assert-AreEqual $true $ddosCustomPolicyDelete
53+
}
54+
finally
55+
{
56+
# Cleanup
57+
Clean-ResourceGroup $rgName
58+
}
59+
}
60+
61+
<#
62+
.SYNOPSIS
63+
DDoS custom policy creation with tags
64+
#>
65+
function Test-DdosCustomPolicyCRUDWithTags
66+
{
67+
$rgLocation = Get-ProviderLocation ResourceManagement
68+
$resourceTypeParent = "Microsoft.Network/DdosCustomPolicies"
69+
$location = Get-ProviderLocation $resourceTypeParent
70+
71+
$rgName = Get-ResourceGroupName
72+
$ddosCustomPolicyName = Get-ResourceName
73+
$tags = @{ Environment = "Test"; Project = "DdosCustomPolicy" }
74+
75+
try
76+
{
77+
# Create the resource group
78+
New-AzResourceGroup -Name $rgName -Location $location -Tags @{ testtag = "ddosCustomPolicy tag" }
79+
80+
# Create the DDoS custom policy with tags
81+
$ddosCustomPolicy = New-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName -Location $rgLocation -TrafficType Tcp -PacketsPerSecond 1000000 -Tag $tags
82+
83+
Assert-AreEqual $rgName $ddosCustomPolicy.ResourceGroupName
84+
Assert-AreEqual $ddosCustomPolicyName $ddosCustomPolicy.Name
85+
Assert-NotNull $ddosCustomPolicy.Tag
86+
Assert-AreEqual "Test" $ddosCustomPolicy.Tag["Environment"]
87+
Assert-AreEqual "DdosCustomPolicy" $ddosCustomPolicy.Tag["Project"]
88+
89+
# Get and verify tags
90+
$ddosCustomPolicyGet = Get-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName
91+
Assert-AreEqual "Test" $ddosCustomPolicyGet.Tag["Environment"]
92+
93+
# Remove the DDoS custom policy
94+
Remove-AzDdosCustomPolicy -Name $ddosCustomPolicyName -ResourceGroupName $rgName
95+
}
96+
finally
97+
{
98+
# Cleanup
99+
Clean-ResourceGroup $rgName
100+
}
101+
}
102+
103+
<#
104+
.SYNOPSIS
105+
Test DDoS custom policy linkage with Load Balancer Frontend IP Config
106+
#>
107+
function Test-LoadBalancerFrontendWithDdosCustomPolicy
108+
{
109+
$resourceTypeParent = "Microsoft.Network/loadBalancers"
110+
$location = Get-ProviderLocation $resourceTypeParent
111+
112+
$rgName = Get-ResourceGroupName
113+
$lbName = Get-ResourceName
114+
$pipName = Get-ResourceName
115+
$frontendName = Get-ResourceName
116+
$ddosCustomPolicyName = Get-ResourceName
117+
118+
try
119+
{
120+
# Create the resource group
121+
New-AzResourceGroup -Name $rgName -Location $location
122+
123+
# Create DDoS custom policy
124+
$ddosCustomPolicy = New-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName -Location $location -TrafficType Tcp -PacketsPerSecond 1000000
125+
126+
# Create Public IP Address
127+
$publicIp = New-AzPublicIpAddress -ResourceGroupName $rgName -Name $pipName -Location $location -AllocationMethod Static
128+
129+
# Create frontend IP config with DDoS custom policy
130+
$frontendIpConfig = New-AzLoadBalancerFrontendIpConfig -Name $frontendName -PublicIpAddress $publicIp -DdosCustomPolicyId $ddosCustomPolicy.Id
131+
132+
Assert-NotNull $frontendIpConfig
133+
Assert-AreEqual $frontendName $frontendIpConfig.Name
134+
135+
# Create Load Balancer backend pool
136+
$backendPool = New-AzLoadBalancerBackendAddressPoolConfig -Name "BackendPool"
137+
138+
# Create Load Balancer with frontend config
139+
$loadBalancer = New-AzLoadBalancer -ResourceGroupName $rgName -Name $lbName -Location $location `
140+
-FrontendIpConfiguration $frontendIpConfig -BackendAddressPool $backendPool
141+
142+
Assert-NotNull $loadBalancer
143+
Assert-AreEqual $lbName $loadBalancer.Name
144+
145+
# Verify frontend has DDoS custom policy
146+
$frontendFromLb = Get-AzLoadBalancerFrontendIpConfig -LoadBalancer $loadBalancer -Name $frontendName
147+
Assert-NotNull $frontendFromLb
148+
Assert-NotNull $frontendFromLb.DdosSettings
149+
Assert-NotNull $frontendFromLb.DdosSettings.DdosCustomPolicy
150+
Assert-AreEqual $ddosCustomPolicy.Id $frontendFromLb.DdosSettings.DdosCustomPolicy.Id
151+
152+
$ddosCustomPolicyGet = Get-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName
153+
Assert-NotNull $ddosCustomPolicyGet.FrontEndIPConfiguration
154+
Assert-AreEqual 1 $ddosCustomPolicyGet.FrontEndIPConfiguration.Count
155+
Assert-AreEqual $frontendFromLb.Id $ddosCustomPolicyGet.FrontEndIPConfiguration[0].Id
156+
157+
# Test Set-AzLoadBalancerFrontendIpConfig with new DDoS policy
158+
$ddosCustomPolicy2Name = Get-ResourceName
159+
$ddosCustomPolicy2 = New-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicy2Name -Location $location -TrafficType Tcp -PacketsPerSecond 1000000
160+
161+
$loadBalancer = Set-AzLoadBalancerFrontendIpConfig -LoadBalancer $loadBalancer -Name $frontendName `
162+
-PublicIpAddress $publicIp -DdosCustomPolicyId $ddosCustomPolicy2.Id
163+
164+
Set-AzLoadBalancer -LoadBalancer $loadBalancer | Out-Null
165+
$loadBalancerUpdated = Get-AzLoadBalancer -ResourceGroupName $rgName -Name $lbName
166+
$frontendIpConfig2 = Get-AzLoadBalancerFrontendIpConfig -LoadBalancer $loadBalancerUpdated -Name $frontendName
167+
168+
Assert-NotNull $frontendIpConfig2.DdosSettings
169+
Assert-AreEqual $ddosCustomPolicy2.Id $frontendIpConfig2.DdosSettings.DdosCustomPolicy.Id
170+
171+
# Cleanup
172+
Remove-AzLoadBalancer -ResourceGroupName $rgName -Name $lbName -Force
173+
Remove-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName
174+
Remove-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicy2Name
175+
}
176+
finally
177+
{
178+
# Cleanup
179+
Clean-ResourceGroup $rgName
180+
}
181+
}
182+
183+
<#
184+
.SYNOPSIS
185+
Test Add-AzLoadBalancerFrontendIpConfig with DDoS custom policy
186+
#>
187+
function Test-AddLoadBalancerFrontendWithDdosCustomPolicy
188+
{
189+
$resourceTypeParent = "Microsoft.Network/loadBalancers"
190+
$location = Get-ProviderLocation $resourceTypeParent
191+
192+
$rgName = Get-ResourceGroupName
193+
$lbName = Get-ResourceName
194+
$pipName1 = Get-ResourceName
195+
$pipName2 = Get-ResourceName
196+
$frontendName1 = Get-ResourceName
197+
$frontendName2 = Get-ResourceName
198+
$ddosCustomPolicyName = Get-ResourceName
199+
200+
try
201+
{
202+
# Create the resource group
203+
New-AzResourceGroup -Name $rgName -Location $location
204+
205+
# Create DDoS custom policy
206+
$ddosCustomPolicy = New-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName -Location $location -TrafficType Tcp -PacketsPerSecond 1000000
207+
208+
# Create first Public IP Address
209+
$publicIp1 = New-AzPublicIpAddress -ResourceGroupName $rgName -Name $pipName1 -Location $location -AllocationMethod Static
210+
211+
# Create first frontend IP config
212+
$frontendIpConfig1 = New-AzLoadBalancerFrontendIpConfig -Name $frontendName1 -PublicIpAddress $publicIp1
213+
214+
# Create Load Balancer backend pool
215+
$backendPool = New-AzLoadBalancerBackendAddressPoolConfig -Name "BackendPool"
216+
217+
# Create Load Balancer with first frontend config
218+
$loadBalancer = New-AzLoadBalancer -ResourceGroupName $rgName -Name $lbName -Location $location `
219+
-FrontendIpConfiguration $frontendIpConfig1 -BackendAddressPool $backendPool
220+
221+
# Create second Public IP Address
222+
$publicIp2 = New-AzPublicIpAddress -ResourceGroupName $rgName -Name $pipName2 -Location $location -AllocationMethod Static
223+
224+
# Add second frontend with DDoS custom policy
225+
Add-AzLoadBalancerFrontendIpConfig -LoadBalancer $loadBalancer -Name $frontendName2 `
226+
-PublicIpAddress $publicIp2 -DdosCustomPolicyId $ddosCustomPolicy.Id
227+
228+
$loadBalancer | Set-AzLoadBalancer
229+
230+
# Verify the LoadBalancer now has two frontends
231+
$loadBalancerUpdated = Get-AzLoadBalancer -ResourceGroupName $rgName -Name $lbName
232+
Assert-AreEqual 2 $loadBalancerUpdated.FrontendIpConfigurations.Count
233+
234+
# Verify second frontend has DDoS custom policy
235+
$frontendFromLb = Get-AzLoadBalancerFrontendIpConfig -LoadBalancer $loadBalancerUpdated -Name $frontendName2
236+
Assert-NotNull $frontendFromLb.DdosSettings
237+
Assert-AreEqual $ddosCustomPolicy.Id $frontendFromLb.DdosSettings.DdosCustomPolicy.Id
238+
239+
$ddosCustomPolicyGet = Get-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName
240+
Assert-NotNull $ddosCustomPolicyGet.FrontEndIPConfiguration
241+
Assert-AreEqual 1 $ddosCustomPolicyGet.FrontEndIPConfiguration.Count
242+
Assert-AreEqual $frontendFromLb.Id $ddosCustomPolicyGet.FrontEndIPConfiguration[0].Id
243+
244+
# Cleanup
245+
Remove-AzLoadBalancer -ResourceGroupName $rgName -Name $lbName -Force
246+
Remove-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName
247+
}
248+
finally
249+
{
250+
# Cleanup
251+
Clean-ResourceGroup $rgName
252+
}
253+
}

0 commit comments

Comments
 (0)