From fa0dbb5ce2e9355b32baa9ef4d3dc36ae701896e Mon Sep 17 00:00:00 2001 From: Abhishek Shah Date: Thu, 18 Feb 2021 19:27:57 -0800 Subject: [PATCH] Connection Mode Support for VPN Link Connections (#14183) * Skeleton Code * Minor fixes * Adding test Co-authored-by: Abhishek Shah --- .../ScenarioTests/CortexTests.ps1 | 3 ++- src/Network/Network/ChangeLog.md | 3 +++ .../NewAzVpnSiteLinkConnectionCommand.cs | 18 +++++++++++++----- .../UpdateAzureRmVpnConnectionCommand.cs | 14 ++++++++++++++ .../Models/Cortex/PSVpnSiteLinkConnection.cs | 3 +++ .../help/New-AzVpnSiteLinkConnection.md | 15 ++++++++++++++- .../Network/help/Update-AzVpnConnection.md | 19 ++++++++++++++++--- 7 files changed, 65 insertions(+), 10 deletions(-) diff --git a/src/Network/Network.Test/ScenarioTests/CortexTests.ps1 b/src/Network/Network.Test/ScenarioTests/CortexTests.ps1 index 6fd946b7f0d5..fa92b29b1ef1 100644 --- a/src/Network/Network.Test/ScenarioTests/CortexTests.ps1 +++ b/src/Network/Network.Test/ScenarioTests/CortexTests.ps1 @@ -241,7 +241,7 @@ function Test-CortexCRUD # Create the VpnConnection with site with links $natRule2 = Get-AzVpnGatewayNatRule -ResourceGroupName $rgName -ParentResourceName $vpnGatewayName -Name "NatRule2" $vpnSiteLinkConnection1 = New-AzVpnSiteLinkConnection -Name $vpnLink1ConnectionName -VpnSiteLink $vpnSite2.VpnSiteLinks[0] -ConnectionBandwidth 100 -EgressNatRule $natRule2 - $vpnSiteLinkConnection2 = New-AzVpnSiteLinkConnection -Name $vpnLink2ConnectionName -VpnSiteLink $vpnSite2.VpnSiteLinks[1] -ConnectionBandwidth 10 + $vpnSiteLinkConnection2 = New-AzVpnSiteLinkConnection -Name $vpnLink2ConnectionName -VpnSiteLink $vpnSite2.VpnSiteLinks[1] -ConnectionBandwidth 10 -VpnLinkConnectionMode "Default" $createdVpnConnection2 = New-AzVpnConnection -ResourceGroupName $rgName -ParentResourceName $vpnGatewayName -Name $vpnConnection2Name -VpnSite $vpnSite2 -VpnSiteLinkConnection @($vpnSiteLinkConnection1, $vpnSiteLinkConnection2) $vpnConnection2 = Get-AzVpnConnection -ResourceGroupName $rgName -ParentResourceName $vpnGatewayName -Name $vpnConnection2Name @@ -249,6 +249,7 @@ function Test-CortexCRUD Assert-AreEqual 2 $vpnConnection2.VpnLinkConnections.Count Assert-AreEqual 1 $vpnConnection2.VpnLinkConnections[0].EgressNatRules.Count Assert-AreEqual 0 $vpnConnection2.VpnLinkConnections[0].IngressNatRules.Count + Assert-AreEqual "Default" $vpnConnection2.VpnLinkConnections[1].VpnLinkConnectionMode $natRule2 = Get-AzVpnGatewayNatRule -ResourceGroupName $rgName -ParentResourceName $vpnGatewayName -Name "NatRule2" Assert-AreEqual 0 $natRule2.IngressVpnSiteLinkConnections.count diff --git a/src/Network/Network/ChangeLog.md b/src/Network/Network/ChangeLog.md index f72fb19dd513..88a8e690f8e1 100644 --- a/src/Network/Network/ChangeLog.md +++ b/src/Network/Network/ChangeLog.md @@ -21,6 +21,9 @@ ## Upcoming Release * Updated format list and format table views for Get-AzVirtualNetworkGatewayConnectionIkeSa * Updated `set-azExpressRouteGateway` to allow parameter -MinScaleUnits without specifying -MaxScaleUnits +* Updated cmdlets to enable setting of VpnLinkConnectionMode on VpnSiteLinkConnections. + - `New-AzVpnSiteLinkConnection` + - `Update-AzVpnConnection` ## Version 4.5.0 * Added new cmdlets for CRUD of VpnGatewayNATRule. diff --git a/src/Network/Network/Cortex/VpnConnection/NewAzVpnSiteLinkConnectionCommand.cs b/src/Network/Network/Cortex/VpnConnection/NewAzVpnSiteLinkConnectionCommand.cs index f067c1c35e0f..89dd17323d34 100644 --- a/src/Network/Network/Cortex/VpnConnection/NewAzVpnSiteLinkConnectionCommand.cs +++ b/src/Network/Network/Cortex/VpnConnection/NewAzVpnSiteLinkConnectionCommand.cs @@ -7,6 +7,7 @@ using System.Security; using Microsoft.WindowsAzure.Commands.Common; using System.Linq; + using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; [Cmdlet( VerbsCommon.New, @@ -30,8 +31,8 @@ public class NewAzVpnSiteLinkConnectionCommand : NetworkBaseCmdlet public PSVpnSiteLink VpnSiteLink { get; set; } [Parameter( - Mandatory = false, - HelpMessage = "The shared key required to set this link connection up.")] + Mandatory = false, + HelpMessage = "The shared key required to set this link connection up.")] [ValidateNotNullOrEmpty] public SecureString SharedKey { get; set; } @@ -51,8 +52,8 @@ public class NewAzVpnSiteLinkConnectionCommand : NetworkBaseCmdlet public PSIpsecPolicy IpSecPolicy { get; set; } [Parameter( - Mandatory = false, - HelpMessage = "Gateway connection protocol:IKEv1/IKEv2")] + Mandatory = false, + HelpMessage = "Gateway connection protocol:IKEv1/IKEv2")] [ValidateSet( MNM.VirtualNetworkGatewayConnectionProtocol.IKEv1, MNM.VirtualNetworkGatewayConnectionProtocol.IKEv2, @@ -84,6 +85,12 @@ public class NewAzVpnSiteLinkConnectionCommand : NetworkBaseCmdlet HelpMessage = "The list of egress NAT rules that are associated with this link Connection.")] public PSResourceId[] EgressNatRule { get; set; } + [Parameter( + Mandatory = false, + HelpMessage = "The connection mode for this link connection.")] + [PSArgumentCompleter("Default", "ResponderOnly", "InitiatorOnly")] + public string VpnLinkConnectionMode { get; set; } + public override void Execute() { base.Execute(); @@ -96,7 +103,8 @@ public override void Execute() UsePolicyBasedTrafficSelectors = this.UsePolicyBasedTrafficSelectors.IsPresent, RoutingWeight = Convert.ToInt32(this.RoutingWeight), IngressNatRules = IngressNatRule?.ToList(), - EgressNatRules = EgressNatRule?.ToList() + EgressNatRules = EgressNatRule?.ToList(), + VpnLinkConnectionMode = this.VpnLinkConnectionMode }; if (this.VpnSiteLink == null) diff --git a/src/Network/Network/Cortex/VpnConnection/UpdateAzureRmVpnConnectionCommand.cs b/src/Network/Network/Cortex/VpnConnection/UpdateAzureRmVpnConnectionCommand.cs index dcb63c625c8c..56e8c73acca5 100644 --- a/src/Network/Network/Cortex/VpnConnection/UpdateAzureRmVpnConnectionCommand.cs +++ b/src/Network/Network/Cortex/VpnConnection/UpdateAzureRmVpnConnectionCommand.cs @@ -124,6 +124,12 @@ public class UpdateAzureRmVpnConnectionCommand : VpnConnectionBaseCmdlet HelpMessage = "The routing configuration for this vpn connection")] public PSRoutingConfiguration RoutingConfiguration { get; set; } + [Parameter( + Mandatory = false, + HelpMessage = "The connection mode for the link connections.")] + [PSArgumentCompleter("Default", "ResponderOnly", "InitiatorOnly")] + public string VpnLinkConnectionMode { get; set; } + [Parameter( Mandatory = false, HelpMessage = "Run cmdlet in the background")] @@ -231,6 +237,14 @@ public override void Execute() vpnConnectionToModify.RoutingConfiguration = RoutingConfiguration; } + if(!String.IsNullOrEmpty(this.VpnLinkConnectionMode)) + { + foreach(var vpnSiteLinkConnection in vpnConnectionToModify.VpnLinkConnections) + { + vpnSiteLinkConnection.VpnLinkConnectionMode = this.VpnLinkConnectionMode; + } + } + ConfirmAction( Properties.Resources.SettingResourceMessage, this.Name, diff --git a/src/Network/Network/Models/Cortex/PSVpnSiteLinkConnection.cs b/src/Network/Network/Models/Cortex/PSVpnSiteLinkConnection.cs index 8d51086234dc..dab9760c9dfc 100644 --- a/src/Network/Network/Models/Cortex/PSVpnSiteLinkConnection.cs +++ b/src/Network/Network/Models/Cortex/PSVpnSiteLinkConnection.cs @@ -49,6 +49,9 @@ public class PSVpnSiteLinkConnection : PSChildResource [Ps1Xml(Label = "EgressNatRules", Target = ViewControl.Table)] public List EgressNatRules { get; set; } + [Ps1Xml(Label = "VpnLinkConnectionMode", Target = ViewControl.Table)] + public string VpnLinkConnectionMode { get; set; } + [JsonIgnore] public string IngressNatRulesText { diff --git a/src/Network/Network/help/New-AzVpnSiteLinkConnection.md b/src/Network/Network/help/New-AzVpnSiteLinkConnection.md index 1dff97b7563c..fd9d62fe75bd 100644 --- a/src/Network/Network/help/New-AzVpnSiteLinkConnection.md +++ b/src/Network/Network/help/New-AzVpnSiteLinkConnection.md @@ -16,7 +16,7 @@ Creates an Azure VpnSiteLinkConnection object. New-AzVpnSiteLinkConnection -Name -VpnSiteLink [-SharedKey ] [-ConnectionBandwidth ] [-RoutingWeight ] [-IpSecPolicy ] [-VpnConnectionProtocolType ] [-EnableBgp] [-UseLocalAzureIpAddress] [-UsePolicyBasedTrafficSelectors] - [-IngressNatRule ] [-EgressNatRule ] + [-IngressNatRule ] [-EgressNatRule ] [-VpnLinkConnectionMode ] [-DefaultProfile ] [] ``` @@ -233,6 +233,19 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -VpnLinkConnectionMode +The connection mode for this link connection. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: +Required: False +Position: Named +Default value: Default +Accept wildcard characters: False +``` + ### -VpnSiteLink The vpn site link object to connect to. diff --git a/src/Network/Network/help/Update-AzVpnConnection.md b/src/Network/Network/help/Update-AzVpnConnection.md index a06e8f558112..4c56efaea4ce 100644 --- a/src/Network/Network/help/Update-AzVpnConnection.md +++ b/src/Network/Network/help/Update-AzVpnConnection.md @@ -17,7 +17,7 @@ Updates a VPN connection. Update-AzVpnConnection -ResourceGroupName -ParentResourceName -Name [-SharedKey ] [-ConnectionBandwidthInMbps ] [-IpSecPolicy ] [-EnableBgp ] [-UseLocalAzureIpAddress ] [-UsePolicyBasedTrafficSelectors ] - [-VpnSiteLinkConnection ] [-EnableInternetSecurity ] [-RoutingConfiguration ] [-AsJob] + [-VpnSiteLinkConnection ] [-EnableInternetSecurity ] [-RoutingConfiguration ] [-VpnLinkConnectionMode ] [-AsJob] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` @@ -26,7 +26,7 @@ Update-AzVpnConnection -ResourceGroupName -ParentResourceName Update-AzVpnConnection -ResourceId [-SharedKey ] [-ConnectionBandwidthInMbps ] [-IpSecPolicy ] [-EnableBgp ] [-UseLocalAzureIpAddress ] [-UsePolicyBasedTrafficSelectors ] [-VpnSiteLinkConnection ] - [-EnableInternetSecurity ] [-RoutingConfiguration ] [-AsJob] [-DefaultProfile ] [-WhatIf] [-Confirm] + [-EnableInternetSecurity ] [-RoutingConfiguration ] [-VpnLinkConnectionMode ] [-AsJob] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` @@ -35,7 +35,7 @@ Update-AzVpnConnection -ResourceId [-SharedKey ] [-Connec Update-AzVpnConnection -InputObject [-SharedKey ] [-ConnectionBandwidthInMbps ] [-IpSecPolicy ] [-EnableBgp ] [-UseLocalAzureIpAddress ] [-UsePolicyBasedTrafficSelectors ] - [-VpnSiteLinkConnection ] [-EnableInternetSecurity ] [-RoutingConfiguration ] [-AsJob] + [-VpnSiteLinkConnection ] [-EnableInternetSecurity ] [-RoutingConfiguration ] [-VpnLinkConnectionMode ] [-AsJob] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` @@ -397,6 +397,19 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -VpnLinkConnectionMode +The connection mode for all VpnSiteLinkConnections in this VpnConnection + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: +Required: False +Position: Named +Default value: Default +Accept wildcard characters: False +``` + ### -Confirm Prompts you for confirmation before running the cmdlet.