diff --git a/src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayTests.cs b/src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayTests.cs index 7367222f7093..aa94d057887a 100644 --- a/src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayTests.cs +++ b/src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayTests.cs @@ -83,6 +83,14 @@ public void VirtualNetworkGatewayRouteApiTest() TestRunner.RunTestScript("Test-VirtualNetworkGatewayBgpRouteApi"); } + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + [Trait(Category.Owner, NrpTeamAlias.brooklynft_subset3)] + public void VirtualNetworkGatewayEffectiveRouteApiTest() + { + TestRunner.RunTestScript("Test-VirtualNetworkGatewayEffectiveRouteApi"); + } + [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] [Trait(Category.Owner, NrpTeamAlias.brooklynft_subset3)] diff --git a/src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayTests.ps1 b/src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayTests.ps1 index b31b8465c11f..15669706b4a3 100644 --- a/src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayTests.ps1 +++ b/src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayTests.ps1 @@ -648,6 +648,54 @@ function Test-VirtualNetworkGatewayBgpRouteApi } } +<# +.SYNOPSIS +Virtual network gateway effective route API test +#> +function Test-VirtualNetworkGatewayEffectiveRouteApi +{ + # Setup + $rgname = Get-ResourceGroupName + $gwname = Get-ResourceName + $domainNameLabel = Get-ResourceName + $vnetName = Get-ResourceName + $publicIpName = Get-ResourceName + $vnetGatewayConfigName = Get-ResourceName + $rgLocation = Get-ProviderLocation ResourceManagement + $resourceTypeParent = "Microsoft.Network/virtualNetworkGateways" + $location = Get-ProviderLocation $resourceTypeParent + + try + { + $resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation + $subnet = New-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix 10.0.0.0/24 + $vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet + $vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname + $subnet = Get-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet + $publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel + $vnetIpConfig = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet + $gw = New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $gwname -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -GatewaySku Standard + $gw = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $gwname + + $job = Get-AzVirtualNetworkGatewayEffectiveRoute -ResourceGroupName $rgname -VirtualNetworkGatewayName $gwname -AsJob + $job | Wait-Job + $effectiveRoutes = $job | Receive-Job + + if($effectiveRoutes -and $effectiveRoutes.Length -gt 0) + { + forEach($route in $effectiveRoutes) + { + Assert-NotNull $route.LocalAddress "LocalAddress should not be null" + Assert-NotNull $route.NextHopType "NextHopType should not be null" + } + } + } + finally + { + Clean-ResourceGroup $rgname + } +} + <# .SYNOPSIS Virtual network gateway P2S API test diff --git a/src/Network/Network/Az.Network.psd1 b/src/Network/Network/Az.Network.psd1 index c4f48b7dd8ad..81cfdf39b920 100644 --- a/src/Network/Network/Az.Network.psd1 +++ b/src/Network/Network/Az.Network.psd1 @@ -299,6 +299,7 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate', 'Get-AzVirtualNetworkGateway', 'Get-AzVirtualNetworkGatewayAdvertisedRoute', 'Get-AzVirtualNetworkGatewayBGPPeerStatus', + 'Get-AzVirtualNetworkGatewayEffectiveRoute', 'Get-AzVirtualNetworkGatewayConnection', 'Get-AzVirtualNetworkGatewayConnectionIkeSa', 'Get-AzVirtualNetworkGatewayConnectionSharedKey', diff --git a/src/Network/Network/ChangeLog.md b/src/Network/Network/ChangeLog.md index 67da45eb9ed5..0d3e1f68bc0c 100644 --- a/src/Network/Network/ChangeLog.md +++ b/src/Network/Network/ChangeLog.md @@ -19,6 +19,7 @@ ---> ## Upcoming Release +* Added new cmdlet `Get-AzVirtualNetworkGatewayEffectiveRoute` to retrieve effective routes for a Virtual Network Gateway ## Version 7.25.1 * Onboarded `Microsoft.DataReplication/replicationVaults` to Private Link Common Cmdlets diff --git a/src/Network/Network/Common/NetworkResourceManagerProfile.cs b/src/Network/Network/Common/NetworkResourceManagerProfile.cs index 04af6bf67c38..4ccf704f6338 100644 --- a/src/Network/Network/Common/NetworkResourceManagerProfile.cs +++ b/src/Network/Network/Common/NetworkResourceManagerProfile.cs @@ -1301,6 +1301,7 @@ private static void Initialize() }); cfg.CreateMap(); cfg.CreateMap(); + cfg.CreateMap(); cfg.CreateMap() .ForMember( dest => dest.PublicIPAddress, @@ -1394,6 +1395,7 @@ private static void Initialize() cfg.CreateMap(); cfg.CreateMap(); cfg.CreateMap(); + cfg.CreateMap(); cfg.CreateMap() .ForMember( dest => dest.PublicIpAddress, diff --git a/src/Network/Network/Generated/Models/PSGatewayEffectiveRoute.cs b/src/Network/Network/Generated/Models/PSGatewayEffectiveRoute.cs new file mode 100644 index 000000000000..67fd52c3d941 --- /dev/null +++ b/src/Network/Network/Generated/Models/PSGatewayEffectiveRoute.cs @@ -0,0 +1,38 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.WindowsAzure.Commands.Common.Attributes; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace Microsoft.Azure.Commands.Network.Models +{ + public partial class PSGatewayEffectiveRoute + { + [Ps1Xml(Target = ViewControl.Table)] + public string LocalAddress { get; set; } + + [Ps1Xml(Target = ViewControl.Table)] + public List AddressPrefixes { get; set; } + + [Ps1Xml(Target = ViewControl.Table)] + public string NextHopIpAddress { get; set; } + + /// + /// Gets or sets the next hop type. Possible values include: 'Tunnel', 'VirtualNetwork'. + /// + [Ps1Xml(Target = ViewControl.Table)] + public string NextHopType { get; set; } + } +} diff --git a/src/Network/Network/VirtualNetworkGateway/GetAzureVirtualNetworkGatewayEffectiveRouteCommand.cs b/src/Network/Network/VirtualNetworkGateway/GetAzureVirtualNetworkGatewayEffectiveRouteCommand.cs new file mode 100644 index 000000000000..970738aa6e34 --- /dev/null +++ b/src/Network/Network/VirtualNetworkGateway/GetAzureVirtualNetworkGatewayEffectiveRouteCommand.cs @@ -0,0 +1,60 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using Microsoft.Azure.Commands.Network.Models; +using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; +using Microsoft.Azure.Management.Network; +using System.Collections.Generic; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Network +{ + [Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VirtualNetworkGatewayEffectiveRoute"), OutputType(typeof(PSGatewayEffectiveRoute))] + public class GetVirtualNetworkGatewayEffectiveRouteCommand : VirtualNetworkGatewayBaseCmdlet + { + [Alias("ResourceName")] + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Virtual network gateway name")] + [ResourceNameCompleter("Microsoft.Network/virtualNetworkGateways", "ResourceGroupName")] + [ValidateNotNullOrEmpty] + public virtual string VirtualNetworkGatewayName { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Virtual network gateway resource group's name")] + [ResourceGroupCompleter] + [ValidateNotNullOrEmpty] + public virtual string ResourceGroupName { get; set; } + + [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] + public SwitchParameter AsJob { get; set; } + + public override void Execute() + { + base.Execute(); + + List effectiveRoutes = new List(); + foreach (var route in this.VirtualNetworkGatewayClient.GetEffectiveRoutes(this.ResourceGroupName, this.VirtualNetworkGatewayName).Value) + { + effectiveRoutes.Add(NetworkResourceManagerProfile.Mapper.Map(route)); + } + + WriteObject(effectiveRoutes, true); + } + } +}