Skip to content

Commit 51bcb4a

Browse files
Nilambariisra-fel
andauthored
VPN NAT for Virtual WAN feature changes (#13943)
* VPN NAT for Virtual WAN feature changes * Fix help files & network nuget package version update in related test projects * Fix help files * Update existing test with Gateway NAT feature changes validations * Test fix * Incorporate code review comments * Test changes * Latest test recording * Remove local package Co-authored-by: Yeming Liu <[email protected]>
1 parent 6389904 commit 51bcb4a

28 files changed

+6812
-32979
lines changed

src/Network/Network.Test/ScenarioTests/CortexTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public CortexTests(ITestOutputHelper output)
2727
{
2828
}
2929

30-
[Fact(Skip = "Authentication failed for auxiliary token: The '1' auxiliary tokens contains duplicates which are from the same tenant.")]
30+
[Fact]
3131
[Trait(Category.AcceptanceType, Category.CheckIn)]
3232
[Trait(Category.Owner, NrpTeamAlias.brooklynft)]
3333
public void TestCortexCRUD()

src/Network/Network.Test/ScenarioTests/CortexTests.ps1

Lines changed: 160 additions & 93 deletions
Large diffs are not rendered by default.

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.CortexTests/TestCortexCRUD.json

Lines changed: 4596 additions & 32848 deletions
Large diffs are not rendered by default.

src/Network/Network/Az.Network.psd1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
421421
'Reset-AzVpnGateway', 'Get-AzVpnGateway', 'Update-AzVpnGateway',
422422
'Remove-AzVpnGateway', 'Start-AzVpnGatewayPacketCapture',
423423
'Stop-AzVpnGatewayPacketCapture',
424+
'New-AzVpnGatewayNatRule', 'Update-AzVpnGatewayNatRule',
425+
'Remove-AzVpnGatewayNatRule', 'Get-AzVpnGatewayNatRule',
424426
'Start-AzVpnConnectionPacketCapture',
425427
'Stop-AzVpnConnectionPacketCapture', 'New-AzVpnSite',
426428
'New-AzVpnSiteLink', 'New-AzVpnSiteLinkConnection', 'Get-AzVpnSite',

src/Network/Network/ChangeLog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
--->
2020

2121
## Upcoming Release
22+
* Added new cmdlets for CRUD of VpnGatewayNATRule.
23+
- `New-AzAzVpnGatewayNatRule`
24+
- `Update-AzAzVpnGatewayNatRule`
25+
- `Get-AzAzVpnGatewayNatRule`
26+
- `Remove-AzAzVpnGatewayNatRule`
27+
* Updated cmdlets to set NATRule on VpnGateway resource and associate it with VpnSiteLinkConnection resource.
28+
- `New-AzVpnGateway`
29+
- `Update-AzVpnGateway`
30+
- `New-AzVpnSiteLinkConnection`
2231
* Updated cmdlets to enable setting of ConnectionMode on Virtual Network Gateway Connections.
2332
- `New-AzVirtualNetworkGatewayConnection`
2433
- `Set-AzVirtualNetworkGatewayConnection`

src/Network/Network/Common/NetworkResourceManagerProfile.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,8 @@ private static void Initialize()
10941094
cfg.CreateMap<CNM.PSVirtualHubRouteTable, MNM.VirtualHubRouteTableV2>();
10951095
cfg.CreateMap<CNM.PSVirtualHubRoute, MNM.VirtualHubRouteV2>();
10961096
cfg.CreateMap<CNM.PSVpnGateway, MNM.VpnGateway>();
1097+
cfg.CreateMap<CNM.PSVpnGatewayNatRule, MNM.VpnGatewayNatRule>();
1098+
cfg.CreateMap<CNM.PSVpnNatRuleMapping, MNM.VpnNatRuleMapping>();
10971099
cfg.CreateMap<CNM.PSVpnGatewayIpConfiguration, MNM.VpnGatewayIpConfiguration>();
10981100
cfg.CreateMap<CNM.PSVpnSiteLinkConnection, MNM.VpnSiteLinkConnection>();
10991101
cfg.CreateMap<CNM.PSVpnSiteLink, MNM.VpnSiteLink>();
@@ -1128,6 +1130,8 @@ private static void Initialize()
11281130
cfg.CreateMap<MNM.VirtualHubRouteTableV2, CNM.PSVirtualHubRouteTable>();
11291131
cfg.CreateMap<MNM.VirtualHubRouteV2, CNM.PSVirtualHubRoute>();
11301132
cfg.CreateMap<MNM.VpnGateway, CNM.PSVpnGateway>();
1133+
cfg.CreateMap<MNM.VpnGatewayNatRule, CNM.PSVpnGatewayNatRule>();
1134+
cfg.CreateMap<MNM.VpnNatRuleMapping, CNM.PSVpnNatRuleMapping>();
11311135
cfg.CreateMap<MNM.VpnGatewayIpConfiguration, CNM.PSVpnGatewayIpConfiguration>();
11321136
cfg.CreateMap<MNM.VpnConnection, CNM.PSVpnConnection>();
11331137
cfg.CreateMap<MNM.VpnSite, CNM.PSVpnSite>().AfterMap((src, dest) =>

src/Network/Network/Cortex/CortexParameterSetNames.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,9 @@ internal static class CortexParameterSetNames
7676
internal const string ByVHubRouteTableObject = "ByVHubRouteTableObject";
7777
internal const string ByVHubRouteTableResourceId = "ByVHubRouteTableResourceId";
7878
internal const string ByVHubRouteTableName = "ByVHubRouteTableName";
79+
80+
internal const string ByVpnGatewayNatRuleObject = "ByVpnGatewayNatRuleObject";
81+
internal const string ByVpnGatewayNatRuleResourceId = "ByVpnGatewayNatRuleResourceId";
82+
internal const string ByVpnGatewayNatRuleName = "ByVpnGatewayNatRuleName";
7983
}
8084
}

src/Network/Network/Cortex/VpnConnection/NewAzVpnSiteLinkConnectionCommand.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using MNM = Microsoft.Azure.Management.Network.Models;
77
using System.Security;
88
using Microsoft.WindowsAzure.Commands.Common;
9+
using System.Linq;
910

1011
[Cmdlet(
1112
VerbsCommon.New,
@@ -73,6 +74,16 @@ public class NewAzVpnSiteLinkConnectionCommand : NetworkBaseCmdlet
7374
HelpMessage = "Use policy based traffic selectors for this link connection.")]
7475
public SwitchParameter UsePolicyBasedTrafficSelectors { get; set; }
7576

77+
[Parameter(
78+
Mandatory = false,
79+
HelpMessage = "The list of ingress NAT rules that are associated with this link Connection.")]
80+
public PSResourceId[] IngressNatRule { get; set; }
81+
82+
[Parameter(
83+
Mandatory = false,
84+
HelpMessage = "The list of egress NAT rules that are associated with this link Connection.")]
85+
public PSResourceId[] EgressNatRule { get; set; }
86+
7687
public override void Execute()
7788
{
7889
base.Execute();
@@ -83,7 +94,9 @@ public override void Execute()
8394
EnableBgp = this.EnableBgp.IsPresent,
8495
UseLocalAzureIpAddress = this.UseLocalAzureIpAddress.IsPresent,
8596
UsePolicyBasedTrafficSelectors = this.UsePolicyBasedTrafficSelectors.IsPresent,
86-
RoutingWeight = Convert.ToInt32(this.RoutingWeight)
97+
RoutingWeight = Convert.ToInt32(this.RoutingWeight),
98+
IngressNatRules = IngressNatRule?.ToList(),
99+
EgressNatRules = EgressNatRule?.ToList()
87100
};
88101

89102
if (this.VpnSiteLink == null)

src/Network/Network/Cortex/VpnGateway/NewAzureRmVpnGatewayCommand.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public class NewAzureRmVpnGatewayCommand : VpnGatewayBaseCmdlet
8686
HelpMessage = "Flag to enable Routing Preference Internet on this VpnGateway.")]
8787
public SwitchParameter EnableRoutingPreferenceInternetFlag { get; set; }
8888

89+
[Parameter(
90+
Mandatory = false,
91+
HelpMessage = "The list of VpnGatewayNatRules that are associated with this VpnGateway.")]
92+
public PSVpnGatewayNatRule[] VpnGatewayNatRule { get; set; }
93+
8994
[Parameter(
9095
Mandatory = false,
9196
HelpMessage = "A hashtable which represents resource tags.")]
@@ -146,6 +151,13 @@ public override void Execute()
146151
vpnGateway.Connections.AddRange(this.VpnConnection);
147152
}
148153

154+
//// VpnGatewayNatRules, if specified
155+
vpnGateway.NatRules = new List<PSVpnGatewayNatRule>();
156+
if (this.VpnGatewayNatRule != null && this.VpnGatewayNatRule.Any())
157+
{
158+
vpnGateway.NatRules.AddRange(this.VpnGatewayNatRule);
159+
}
160+
149161
//// Scale unit, if specified
150162
vpnGateway.VpnGatewayScaleUnit = 0;
151163
if (this.VpnGatewayScaleUnit > 0)

src/Network/Network/Cortex/VpnGateway/UpdateAzureRmVpnGatewayCommand.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public class UpdateAzureRmVpnGatewayCommand : VpnGatewayBaseCmdlet
7676
HelpMessage = "The list of VpnConnections that this VpnGateway needs to have.")]
7777
public PSVpnConnection[] VpnConnection { get; set; }
7878

79+
[Parameter(
80+
Mandatory = false,
81+
HelpMessage = "The list of VpnGatewayNatRules that are associated with this VpnGateway.")]
82+
public PSVpnGatewayNatRule[] VpnGatewayNatRule { get; set; }
83+
7984
[Parameter(
8085
Mandatory = false,
8186
HelpMessage = "The scale unit for this VpnGateway.")]
@@ -135,6 +140,13 @@ public override void Execute()
135140
existingVpnGateway.Connections.AddRange(this.VpnConnection);
136141
}
137142

143+
//// Modify the natRules
144+
existingVpnGateway.NatRules = new List<PSVpnGatewayNatRule>();
145+
if (this.VpnGatewayNatRule != null && this.VpnGatewayNatRule.Any())
146+
{
147+
existingVpnGateway.NatRules.AddRange(this.VpnGatewayNatRule);
148+
}
149+
138150
//// Modify BgpPeeringAddress
139151
if (this.BgpPeeringAddress != null)
140152
{
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
namespace Microsoft.Azure.Commands.Network.Cortex.VpnGateway
16+
{
17+
using AutoMapper;
18+
using System;
19+
using System.Collections;
20+
using System.Collections.Generic;
21+
using System.Management.Automation;
22+
using System.Security;
23+
using Microsoft.Azure.Commands.Network.Models;
24+
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
25+
using Microsoft.Azure.Management.Network;
26+
using Microsoft.WindowsAzure.Commands.Common;
27+
using MNM = Microsoft.Azure.Management.Network.Models;
28+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
29+
using System.Linq;
30+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
31+
32+
[Cmdlet(VerbsCommon.Get,
33+
ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VpnGatewayNatRule",
34+
DefaultParameterSetName = CortexParameterSetNames.ByVpnGatewayName),
35+
OutputType(typeof(PSVpnGatewayNatRule))]
36+
public class GetAzureRmVpnGatewayNatRuleCommand : VpnGatewayNatRuleBaseCmdlet
37+
{
38+
[Parameter(
39+
Mandatory = true,
40+
ParameterSetName = CortexParameterSetNames.ByVpnGatewayName,
41+
HelpMessage = "The resource group name.")]
42+
[ResourceGroupCompleter]
43+
[ValidateNotNullOrEmpty]
44+
public string ResourceGroupName { get; set; }
45+
46+
[Alias("ParentVpnGatewayName", "VpnGatewayName")]
47+
[Parameter(
48+
Mandatory = true,
49+
ParameterSetName = CortexParameterSetNames.ByVpnGatewayName,
50+
HelpMessage = "The parent resource name.")]
51+
[ResourceNameCompleter("Microsoft.Network/vpnGateways", "ResourceGroupName")]
52+
[ValidateNotNullOrEmpty]
53+
public string ParentResourceName { get; set; }
54+
55+
[Alias("ParentVpnGateway", "VpnGateway")]
56+
[Parameter(
57+
Mandatory = true,
58+
ValueFromPipeline = true,
59+
ParameterSetName = CortexParameterSetNames.ByVpnGatewayObject,
60+
HelpMessage = "The parent VpnGateway for this VpnGatewayNatRule.")]
61+
[ValidateNotNullOrEmpty]
62+
public PSVpnGateway ParentObject { get; set; }
63+
64+
[Alias("ParentVpnGatewayId", "VpnGatewayId")]
65+
[Parameter(
66+
Mandatory = true,
67+
ValueFromPipelineByPropertyName = true,
68+
ParameterSetName = CortexParameterSetNames.ByVpnGatewayResourceId,
69+
HelpMessage = "The resource id of the parent VpnGateway for this VpnGatewayNatRule.")]
70+
[ValidateNotNullOrEmpty]
71+
[ResourceIdCompleter("Microsoft.Network/vpnGateways")]
72+
public string ParentResourceId { get; set; }
73+
74+
[Alias("ResourceName", "VpnGatewayNatRuleName")]
75+
[Parameter(
76+
Mandatory = false,
77+
HelpMessage = "The resource name.")]
78+
[ResourceNameCompleter("Microsoft.Network/vpnGateways/natRules", "ResourceGroupName", "ParentResourceName")]
79+
[ValidateNotNullOrEmpty]
80+
[SupportsWildcards]
81+
public string Name { get; set; }
82+
83+
public override void Execute()
84+
{
85+
base.Execute();
86+
87+
if (ParameterSetName.Equals(CortexParameterSetNames.ByVpnGatewayObject, StringComparison.OrdinalIgnoreCase))
88+
{
89+
this.ResourceGroupName = this.ParentObject.ResourceGroupName;
90+
this.ParentResourceName = this.ParentObject.Name;
91+
}
92+
else if (ParameterSetName.Equals(CortexParameterSetNames.ByVpnGatewayResourceId, StringComparison.OrdinalIgnoreCase))
93+
{
94+
var parsedResourceId = new ResourceIdentifier(this.ParentResourceId);
95+
this.ResourceGroupName = parsedResourceId.ResourceGroupName;
96+
this.ParentResourceName = parsedResourceId.ResourceName;
97+
}
98+
99+
if (ShouldGetByName(ResourceGroupName, Name))
100+
{
101+
WriteObject(this.GetVpnGatewayNatRule(this.ResourceGroupName, this.ParentResourceName, this.Name));
102+
}
103+
else
104+
{
105+
WriteObject(SubResourceWildcardFilter(Name, this.ListVpnGatewayNatRules(this.ResourceGroupName, this.ParentResourceName)), true);
106+
}
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)