Skip to content

Commit d65ed1b

Browse files
zaynchen115msJinLeiLei Jin
authored
Add all post call to get effective routes (#21850)
* Cp1 * Add Tests * Fix helper files * More fix * Fix tests and session records * Rename new added cmdlets from plural to singular * Update help doc and change log for Az.Netowrk --------- Co-authored-by: msJinLei <[email protected]> Co-authored-by: Lei Jin <[email protected]>
1 parent 330896d commit d65ed1b

File tree

58 files changed

+5354
-1800
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+5354
-1800
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,14 @@ function Test-RouteMapCRUD
544544
$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name frontendSubnet -AddressPrefix "10.2.1.0/24"
545545
$backendSubnet = New-AzVirtualNetworkSubnetConfig -Name backendSubnet -AddressPrefix "10.2.2.0/24"
546546
$remoteVirtualNetwork = New-AzVirtualNetwork -Name $virtualNetworkName -ResourceGroupName $rgName -Location $rglocation -AddressPrefix "10.2.0.0/16" -Subnet $frontendSubnet,$backendSubnet
547-
New-AzVirtualHubVnetConnection -ResourceGroupName $rgName -VirtualHubName $virtualHubName -Name $virtualNetworkConnectionName -RemoteVirtualNetwork $remoteVirtualNetwork -RoutingConfiguration $testRoutingConfiguration
547+
$hubVnetCon1 = New-AzVirtualHubVnetConnection -ResourceGroupName $rgName -VirtualHubName $virtualHubName -Name $virtualNetworkConnectionName -RemoteVirtualNetwork $remoteVirtualNetwork -RoutingConfiguration $testRoutingConfiguration
548+
549+
$effectiveRoutes = Get-AzVHubEffectiveRoute -ResourceGroupName $rgName -VirtualHubName $virtualHubName -ResourceId $rt1.Id -VirtualWanResourceType 'RouteTable'
550+
Assert-AreEqual $effectiveRoutes.Value.Count 1
551+
552+
$inboundRoutes = Get-AzVHubInboundRoute -ResourceGroupName $rgName -VirtualHubName $virtualHubName -ResourceUri $hubVnetCon1.Id -VirtualWanConnectionType 'HubVirtualNetworkConnection'
553+
Assert-AreEqual $inboundRoutes.Value.Count 1
554+
Assert-AreEqual "10.2.0.0/16" $inboundRoutes.Value.Prefix
548555

549556
$routeMap = Get-AzRouteMap -ResourceGroupName $rgName -VirtualHubName $virtualHubName -Name $routeMapName
550557
Assert-AreEqual $routeMap.AssociatedInboundConnections.Count 1

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

Lines changed: 3608 additions & 1498 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
@@ -436,6 +436,8 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
436436
'Add-AzVirtualHubRoute', 'New-AzVirtualHubRouteTable',
437437
'Add-AzVirtualHubRouteTable', 'Get-AzVirtualHubRouteTable',
438438
'Remove-AzVirtualHubRouteTable', 'New-AzRoutingPolicy',
439+
'Get-AzVHubEffectiveRoute', 'Get-AzVHubInboundRoute',
440+
'Get-AzVHubOutboundRoute',
439441
'New-AzVirtualRouterAutoScaleConfiguration', 'Get-AzRoutingPolicy',
440442
'Add-AzRoutingPolicy', 'Remove-AzRoutingPolicy',
441443
'Set-AzRoutingPolicy', 'New-AzRoutingIntent', 'Get-AzRoutingIntent',

src/Network/Network/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
- `New-AzApplicationGatewayFirewallPolicySetting`
5151
* Added optional property `AuxiliarySku` to cmdlet `New-AzNetworkInterface` to help choose performance on an `AuxiliaryMode` enabled Network Interface.
5252
* Added a new value `AcceleratedConnections` for existing property `AuxiliaryMode` for `New-AzNetworkInterface`
53+
* Added new cmdlets to get virtual hub effective routes and in/outbound routes
54+
- `Get-AzVHubEffectiveRoute`
55+
- `Get-AzVHubInboundRoute`
56+
- `Get-AzVHubOutboundRoute`
5357

5458
## Version 5.7.0
5559
* Onboarded `Microsoft.HardwareSecurityModules/cloudHsmClusters` to private link cmdlets

src/Network/Network/Common/NetworkResourceManagerProfile.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,13 +1292,21 @@ private static void Initialize()
12921292
cfg.CreateMap<CNM.PSRouteMapRuleCriterion, MNM.Criterion>();
12931293
cfg.CreateMap<CNM.PSRouteMapRuleAction, MNM.Action>();
12941294
cfg.CreateMap<CNM.PSRouteMapRuleActionParameter, MNM.Parameter>();
1295+
cfg.CreateMap<CNM.PSVirtualHubEffectiveRouteList, MNM.VirtualHubEffectiveRouteList>();
1296+
cfg.CreateMap<CNM.PSVirtualHubEffectiveRoute, MNM.VirtualHubEffectiveRoute>();
1297+
cfg.CreateMap<CNM.PSVirtualHubEffectiveRouteMapRouteList, MNM.EffectiveRouteMapRouteList>();
1298+
cfg.CreateMap<CNM.PSVirtualHubEffectiveRouteMapRoute, MNM.EffectiveRouteMapRoute>();
12951299

12961300
// MNM to CNM
12971301
cfg.CreateMap<MNM.RouteMap, CNM.PSRouteMap>();
12981302
cfg.CreateMap<MNM.RouteMapRule, CNM.PSRouteMapRule>();
12991303
cfg.CreateMap<MNM.Criterion, CNM.PSRouteMapRuleCriterion>();
13001304
cfg.CreateMap<MNM.Action, CNM.PSRouteMapRuleAction > ();
13011305
cfg.CreateMap<MNM.Parameter, CNM.PSRouteMapRuleActionParameter> ();
1306+
cfg.CreateMap<MNM.VirtualHubEffectiveRouteList, CNM.PSVirtualHubEffectiveRouteList>();
1307+
cfg.CreateMap<MNM.VirtualHubEffectiveRoute, CNM.PSVirtualHubEffectiveRoute>();
1308+
cfg.CreateMap<MNM.EffectiveRouteMapRouteList, CNM.PSVirtualHubEffectiveRouteMapRouteList>();
1309+
cfg.CreateMap<MNM.EffectiveRouteMapRoute, CNM.PSVirtualHubEffectiveRouteMapRoute>();
13021310

13031311
// Virtual wan Point to site
13041312
// MNM to CNM
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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
16+
{
17+
using Microsoft.Azure.Commands.Common.Strategies;
18+
using Microsoft.Azure.Commands.Network.Models;
19+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
20+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
21+
using Microsoft.Azure.Management.Network;
22+
using Microsoft.Azure.Management.Network.Models;
23+
using System;
24+
using System.Collections.Generic;
25+
using System.Management.Automation;
26+
27+
[Cmdlet(VerbsCommon.Get,
28+
ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VHubInboundRoute",
29+
DefaultParameterSetName = CortexParameterSetNames.ByVirtualHubName),
30+
OutputType(typeof(PSVirtualHubEffectiveRouteMapRouteList))]
31+
public class GetAzureRmVHubInboundRoutesCommand : VirtualHubBaseCmdlet
32+
{
33+
[Parameter(
34+
Mandatory = true,
35+
ParameterSetName = CortexParameterSetNames.ByVirtualHubName,
36+
HelpMessage = "The resource group name.")]
37+
[ResourceGroupCompleter]
38+
public string ResourceGroupName { get; set; }
39+
40+
[Alias("ParentVirtualHubName", "ParentResourceName")]
41+
[Parameter(
42+
Mandatory = true,
43+
ParameterSetName = CortexParameterSetNames.ByVirtualHubName,
44+
HelpMessage = "The parent resource name.")]
45+
[ResourceNameCompleter("Microsoft.Network/virtualHubs", "ResourceGroupName")]
46+
public string VirtualHubName { get; set; }
47+
48+
[Alias("ParentObject", "ParentVirtualHub")]
49+
[Parameter(
50+
Mandatory = true,
51+
ValueFromPipeline = true,
52+
ParameterSetName = CortexParameterSetNames.ByVirtualHubObject,
53+
HelpMessage = "The parent resource.")]
54+
public PSVirtualHub VirtualHubObject { get; set; }
55+
56+
[Alias("VirtualHubId", "ParentVirtualHubId")]
57+
[Parameter(
58+
Mandatory = true,
59+
ValueFromPipelineByPropertyName = true,
60+
ParameterSetName = CortexParameterSetNames.ByVirtualHubResourceId,
61+
HelpMessage = "The parent resource id.")]
62+
[ResourceIdCompleter("Microsoft.Network/virtualHubs")]
63+
public string VirtualHubResourceId { get; set; }
64+
65+
[Parameter(
66+
Mandatory = false,
67+
HelpMessage = "Resource Uri of the connection that inbound routes are being requested.")]
68+
[ValidateNotNullOrEmpty]
69+
public string ResourceUri { get; set; }
70+
71+
[Parameter(
72+
Mandatory = false,
73+
HelpMessage = "VirtualWan Connection Type of the specified connection like VpnConnection, ExpressRouteConnection.")]
74+
[ValidateNotNullOrEmpty]
75+
public string VirtualWanConnectionType { get; set; }
76+
77+
public override void Execute()
78+
{
79+
base.Execute();
80+
81+
if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubObject, StringComparison.OrdinalIgnoreCase))
82+
{
83+
this.VirtualHubName = this.VirtualHubObject.Name;
84+
this.ResourceGroupName = this.VirtualHubObject.ResourceGroupName;
85+
}
86+
else if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubResourceId, StringComparison.OrdinalIgnoreCase))
87+
{
88+
var parsedResourceId = new ResourceIdentifier(this.VirtualHubResourceId);
89+
this.VirtualHubName = parsedResourceId.ResourceName;
90+
ResourceGroupName = parsedResourceId.ResourceGroupName;
91+
}
92+
93+
GetInboundRoutesParameters inboundRoutesParameters = new GetInboundRoutesParameters()
94+
{
95+
ResourceUri = this.ResourceUri,
96+
ConnectionType = this.VirtualWanConnectionType
97+
};
98+
99+
WriteObject(GetVirtualHubInboundRoutes(ResourceGroupName, VirtualHubName, inboundRoutesParameters));
100+
}
101+
}
102+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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
16+
{
17+
using Microsoft.Azure.Commands.Common.Strategies;
18+
using Microsoft.Azure.Commands.Network.Models;
19+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
20+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
21+
using Microsoft.Azure.Management.Network;
22+
using Microsoft.Azure.Management.Network.Models;
23+
using System;
24+
using System.Collections.Generic;
25+
using System.Management.Automation;
26+
27+
[Cmdlet(VerbsCommon.Get,
28+
ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VHubOutboundRoute",
29+
DefaultParameterSetName = CortexParameterSetNames.ByVirtualHubName),
30+
OutputType(typeof(PSVirtualHubEffectiveRouteMapRouteList))]
31+
public class GetAzureRmVHubOutboundRoutesCommand : VirtualHubBaseCmdlet
32+
{
33+
[Parameter(
34+
Mandatory = true,
35+
ParameterSetName = CortexParameterSetNames.ByVirtualHubName,
36+
HelpMessage = "The resource group name.")]
37+
[ResourceGroupCompleter]
38+
public string ResourceGroupName { get; set; }
39+
40+
[Alias("ParentVirtualHubName", "ParentResourceName")]
41+
[Parameter(
42+
Mandatory = true,
43+
ParameterSetName = CortexParameterSetNames.ByVirtualHubName,
44+
HelpMessage = "The parent resource name.")]
45+
[ResourceNameCompleter("Microsoft.Network/virtualHubs", "ResourceGroupName")]
46+
public string VirtualHubName { get; set; }
47+
48+
[Alias("ParentObject", "ParentVirtualHub")]
49+
[Parameter(
50+
Mandatory = true,
51+
ValueFromPipeline = true,
52+
ParameterSetName = CortexParameterSetNames.ByVirtualHubObject,
53+
HelpMessage = "The parent resource.")]
54+
public PSVirtualHub VirtualHubObject { get; set; }
55+
56+
[Alias("VirtualHubId", "ParentVirtualHubId")]
57+
[Parameter(
58+
Mandatory = true,
59+
ValueFromPipelineByPropertyName = true,
60+
ParameterSetName = CortexParameterSetNames.ByVirtualHubResourceId,
61+
HelpMessage = "The parent resource id.")]
62+
[ResourceIdCompleter("Microsoft.Network/virtualHubs")]
63+
public string VirtualHubResourceId { get; set; }
64+
65+
[Parameter(
66+
Mandatory = false,
67+
HelpMessage = "Resource Uri of the connection that inbound routes are being requested.")]
68+
[ValidateNotNullOrEmpty]
69+
public string ResourceUri { get; set; }
70+
71+
[Parameter(
72+
Mandatory = false,
73+
HelpMessage = "VirtualWan Connection Type of the specified connection like VpnConnection, ExpressRouteConnection.")]
74+
[ValidateNotNullOrEmpty]
75+
public string VirtualWanConnectionType { get; set; }
76+
77+
public override void Execute()
78+
{
79+
base.Execute();
80+
81+
if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubObject, StringComparison.OrdinalIgnoreCase))
82+
{
83+
this.VirtualHubName = this.VirtualHubObject.Name;
84+
this.ResourceGroupName = this.VirtualHubObject.ResourceGroupName;
85+
}
86+
else if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubResourceId, StringComparison.OrdinalIgnoreCase))
87+
{
88+
var parsedResourceId = new ResourceIdentifier(this.VirtualHubResourceId);
89+
this.VirtualHubName = parsedResourceId.ResourceName;
90+
ResourceGroupName = parsedResourceId.ResourceGroupName;
91+
}
92+
93+
GetOutboundRoutesParameters outboundRoutesParameters = new GetOutboundRoutesParameters()
94+
{
95+
ResourceUri = this.ResourceUri,
96+
ConnectionType = this.VirtualWanConnectionType
97+
};
98+
99+
WriteObject(GetVirtualHubOutboundRoutes(ResourceGroupName, VirtualHubName, outboundRoutesParameters));
100+
}
101+
}
102+
}

src/Network/Network/Cortex/VirtualHub/GetAzureRmVirtualHubEffectiveRoutesCommand.cs renamed to src/Network/Network/Cortex/VirtualHub/GetAzureRmVHubEffectiveRoutesCommand.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,19 @@ namespace Microsoft.Azure.Commands.Network
2525
using System.Management.Automation;
2626

2727
[Cmdlet(VerbsCommon.Get,
28-
ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VirtualHubEffectiveRoutes",
28+
ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VHubEffectiveRoute",
2929
DefaultParameterSetName = CortexParameterSetNames.ByVirtualHubName),
30-
OutputType(typeof(PSVirtualHub))]
31-
public class GetAzureRmVirtualHubEffectiveRoutesCommand : VirtualHubBaseCmdlet
30+
OutputType(typeof(PSVirtualHubEffectiveRouteList))]
31+
public class GetAzureRmVHubEffectiveRoutesCommand : VirtualHubBaseCmdlet
3232
{
3333
[Parameter(
3434
Mandatory = true,
3535
ParameterSetName = CortexParameterSetNames.ByVirtualHubName,
3636
HelpMessage = "The resource group name.")]
3737
[ResourceGroupCompleter]
38-
[ValidateNotNullOrEmpty]
3938
public string ResourceGroupName { get; set; }
4039

41-
[Alias("VirtualHubName", "ParentVirtualHubName", "ParentResourceName")]
40+
[Alias("ParentVirtualHubName", "ParentResourceName")]
4241
[Parameter(
4342
Mandatory = true,
4443
ParameterSetName = CortexParameterSetNames.ByVirtualHubName,
@@ -66,11 +65,13 @@ public class GetAzureRmVirtualHubEffectiveRoutesCommand : VirtualHubBaseCmdlet
6665
[Parameter(
6766
Mandatory = false,
6867
HelpMessage = "Resource Id whose effective routes are being requested.")]
68+
[ValidateNotNullOrEmpty]
6969
public string ResourceId { get; set; }
7070

7171
[Parameter(
7272
Mandatory = false,
7373
HelpMessage = "VirtualWan Resource Type of the specified resource like RouteTable, ExpressRouteConnection.")]
74+
[ValidateNotNullOrEmpty]
7475
public string VirtualWanResourceType { get; set; }
7576

7677
public override void Execute()
@@ -89,13 +90,13 @@ public override void Execute()
8990
ResourceGroupName = parsedResourceId.ResourceGroupName;
9091
}
9192

92-
EffectiveRoutesParameters pSEffectiveRoutesParameters = new EffectiveRoutesParameters()
93+
EffectiveRoutesParameters effectiveRoutesParameters = new EffectiveRoutesParameters()
9394
{
9495
ResourceId = this.ResourceId,
9596
VirtualWanResourceType = this.VirtualWanResourceType
9697
};
9798

98-
VirtualHubClient.GetEffectiveVirtualHubRoutes(ResourceGroupName, VirtualHubName, pSEffectiveRoutesParameters);
99+
WriteObject(GetVirtualHubEffectiveRouteList(ResourceGroupName, VirtualHubName, effectiveRoutesParameters));
99100
}
100101
}
101102
}

src/Network/Network/Cortex/VirtualHub/VirtualHubBaseCmdlet.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace Microsoft.Azure.Commands.Network
2222
using Microsoft.Azure.Commands.Network.Models;
2323
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
2424
using Microsoft.Azure.Management.Network;
25+
using Microsoft.Azure.Management.Network.Models;
2526
using MNM = Microsoft.Azure.Management.Network.Models;
2627

2728
public class VirtualHubBaseCmdlet : NetworkBaseCmdlet
@@ -161,5 +162,29 @@ public List<PSVirtualHub> ListVirtualHubs(string resourceGroupName)
161162

162163
return hubsToReturn;
163164
}
165+
166+
public PSVirtualHubEffectiveRouteList GetVirtualHubEffectiveRouteList(string resourceGroupName, string virtualHubName, EffectiveRoutesParameters effectiveRoutesParameters)
167+
{
168+
var effectiveRouteList = VirtualHubClient.GetEffectiveVirtualHubRoutes(resourceGroupName, virtualHubName, effectiveRoutesParameters);
169+
var pSEffectiveRouteList = NetworkResourceManagerProfile.Mapper.Map<PSVirtualHubEffectiveRouteList>(effectiveRouteList);
170+
171+
return pSEffectiveRouteList;
172+
}
173+
174+
public PSVirtualHubEffectiveRouteMapRouteList GetVirtualHubInboundRoutes(string resourceGroupName, string virtualHubName, GetInboundRoutesParameters inboundRoutesParameters)
175+
{
176+
var inboundRoutes = VirtualHubClient.GetInboundRoutes(resourceGroupName, virtualHubName, inboundRoutesParameters);
177+
var inboundRouteMapRouteList = NetworkResourceManagerProfile.Mapper.Map<PSVirtualHubEffectiveRouteMapRouteList>(inboundRoutes);
178+
179+
return inboundRouteMapRouteList;
180+
}
181+
182+
public PSVirtualHubEffectiveRouteMapRouteList GetVirtualHubOutboundRoutes(string resourceGroupName, string virtualHubName, GetOutboundRoutesParameters outboundRoutesParameters)
183+
{
184+
var outboundRoutes = VirtualHubClient.GetOutboundRoutes(resourceGroupName, virtualHubName, outboundRoutesParameters);
185+
var outboundRouteMapRouteList = NetworkResourceManagerProfile.Mapper.Map<PSVirtualHubEffectiveRouteMapRouteList>(outboundRoutes);
186+
187+
return outboundRouteMapRouteList;
188+
}
164189
}
165190
}

0 commit comments

Comments
 (0)