Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hub routing preference in virtual hub, deprecated PreferredRoutingGateway #17800

Merged
merged 11 commits into from
Apr 15, 2022
4 changes: 2 additions & 2 deletions src/Network/Network.Test/ScenarioTests/CortexTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function Test-CortexCRUD
Assert-NotNull $virtualWansAll

# Create the Virtual Hub
$createdVirtualHub = New-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHubName -Location $rglocation -AddressPrefix "192.168.1.0/24" -VirtualWan $virtualWan
$createdVirtualHub = New-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHubName -Location $rglocation -AddressPrefix "192.168.1.0/24" -VirtualWan $virtualWan -HubRoutingPreference "ASPath"
$virtualHub = Get-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHubName
Assert-AreEqual $rgName $virtualHub.ResourceGroupName
Assert-AreEqual $virtualHubName $virtualHub.Name
Expand All @@ -94,7 +94,7 @@ function Test-CortexCRUD
$route1 = New-AzVirtualHubRoute -AddressPrefix @("10.0.0.0/16", "11.0.0.0/16") -NextHopIpAddress "12.0.0.5"
$route2 = New-AzVirtualHubRoute -AddressPrefix @("13.0.0.0/16") -NextHopIpAddress "14.0.0.5"
$routeTable = New-AzVirtualHubRouteTable -Route @($route1, $route2)
Update-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHubName -RouteTable $routeTable
Update-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHubName -RouteTable $routeTable -HubRoutingPreference "ExpressRoute"
$virtualHub = Get-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHubName
Assert-AreEqual $rgName $virtualHub.ResourceGroupName
Assert-AreEqual $virtualHubName $virtualHub.Name
Expand Down
3 changes: 3 additions & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
* Added option parameter `AuthorizationKey` to cmdlet `New-AzExpressRouteCircuit` to allow creating ExpressRoute Circuit on a ExpressRoutePort with a different owner.
* Fixed `ArgumentNullException` in `Add-AzureRmRouteConfig` when `RouteTable.Routes` is null.
* Fix bug that can't display CustomIpPrefix in PublicIpPrefix.
* Updated cmdlets to add new property of `HubRoutingPreference` in VirtualHub and set property of `PreferredRoutingGateway` deprecated .
- `New-AzVirtualHub`
- `Update-AzVirtualHub`

## Version 4.16.0
* Added support for retrieving the state of packet capture even when the provisioning state of the packet capture was failure
Expand Down
2 changes: 1 addition & 1 deletion src/Network/Network/Cortex/CortexParameterSetNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ internal static class CortexParameterSetNames
internal const string ByHubBgpConnectionObject = "ByHubBgpConnectionObject";
internal const string ByHubBgpConnectionResourceId = "ByHubBgpConnectionResourceId";

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public class NewAzureRmVirtualHubCommand : VirtualHubBaseCmdlet
[PSArgumentCompleter("Basic", "Standard")]
public string Sku { get; set; }

public const String PreferredGWChangeDesc = "PreferredRoutingGateway parameter is deprecated. Use *HubRoutingPreference* property";
[CmdletParameterBreakingChange("PreferredRoutingGateway", ChangeDescription = PreferredGWChangeDesc)]
[Parameter(
Mandatory = false,
HelpMessage = "Preferred Routing Gateway to Route On-Prem traffic from VNET")]
Expand All @@ -107,6 +109,16 @@ public class NewAzureRmVirtualHubCommand : VirtualHubBaseCmdlet
IgnoreCase = true)]
public string PreferredRoutingGateway { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Virtual Hub Routing Preference to route traffic")]
[ValidateSet(
MNM.HubRoutingPreference.ExpressRoute,
MNM.HubRoutingPreference.VpnGateway,
MNM.HubRoutingPreference.ASPath,
IgnoreCase = true)]
public string HubRoutingPreference { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Run cmdlet in the background")]
Expand Down Expand Up @@ -183,6 +195,15 @@ public override void Execute()
virtualHub.PreferredRoutingGateway = this.PreferredRoutingGateway;
}

if (string.IsNullOrWhiteSpace(this.HubRoutingPreference))
{
virtualHub.HubRoutingPreference = "ExpressRoute";
}
else
{
virtualHub.HubRoutingPreference = this.HubRoutingPreference;
}

WriteObject(CreateOrUpdateVirtualHub(
this.ResourceGroupName,
this.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public class UpdateAzureRmVirtualHubCommand : VirtualHubBaseCmdlet
[PSArgumentCompleter("Basic", "Standard")]
public string Sku { get; set; }

public const String PreferredGWChangeDesc = "PreferredRoutingGateway parameter will be deprecated. Use *HubRoutingPreference* parameter";
[CmdletParameterBreakingChange("PreferredRoutingGateway", ChangeDescription = PreferredGWChangeDesc)]
[Parameter(
Mandatory = false,
HelpMessage = "Preferred Routing Gateway to Route On-Prem traffic from VNET")]
Expand All @@ -112,6 +114,16 @@ public class UpdateAzureRmVirtualHubCommand : VirtualHubBaseCmdlet
IgnoreCase = true)]
public string PreferredRoutingGateway { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Virtual Hub Routing Preference to route traffic")]
[ValidateSet(
MNM.HubRoutingPreference.ExpressRoute,
MNM.HubRoutingPreference.VpnGateway,
MNM.HubRoutingPreference.ASPath,
IgnoreCase = true)]
public string HubRoutingPreference { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Run cmdlet in the background")]
Expand Down Expand Up @@ -194,6 +206,11 @@ public override void Execute()
virtualHubToUpdate.PreferredRoutingGateway = this.PreferredRoutingGateway;
}

if (!string.IsNullOrWhiteSpace(this.HubRoutingPreference))
{
virtualHubToUpdate.HubRoutingPreference = this.HubRoutingPreference;
}

//// Update the virtual hub
ConfirmAction(
Properties.Resources.SettingResourceMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public IVirtualHubsOperations VirtualHubClient
public PSVirtualHub ToPsVirtualHub(Management.Network.Models.VirtualHub virtualHub)
{
var psVirtualHub = NetworkResourceManagerProfile.Mapper.Map<PSVirtualHub>(virtualHub);

psVirtualHub.Tag = TagsConversionHelper.CreateTagHashtable(virtualHub.Tags);

return psVirtualHub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public override void Execute()
throw new PSArgumentException(Properties.Resources.StaticRoutesNotSupportedForThisRoutingConfiguration);
}

vpnConnectionToModify.RoutingConfiguration = RoutingConfiguration;
vpnConnectionToModify.RoutingConfiguration = this.RoutingConfiguration;
}

if(!String.IsNullOrEmpty(this.VpnLinkConnectionMode))
Expand Down
3 changes: 3 additions & 0 deletions src/Network/Network/Models/Cortex/PSVirtualHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,8 @@ public class PSVirtualHub : PSTopLevelResource

[Ps1Xml(Label = "Preferred Routing Gateway", Target = ViewControl.Table)]
public string PreferredRoutingGateway { get; set; }

[Ps1Xml(Label = "Hub Routing Preference", Target = ViewControl.Table)]
public string HubRoutingPreference { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Network/Network/Network.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -4491,6 +4491,10 @@
<Label>PreferredRoutingGateway</Label>
<PropertyName>PreferredRoutingGateway</PropertyName>
</ListItem>
<ListItem>
<Label>HubRoutingPreference</Label>
<PropertyName>HubRoutingPreference</PropertyName>
</ListItem>
<ListItem>
<Label>ProvisioningState</Label>
<PropertyName>ProvisioningState</PropertyName>
Expand Down
30 changes: 25 additions & 5 deletions src/Network/Network/help/New-AzVirtualHub.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ Creates an Azure VirtualHub resource.
New-AzVirtualHub -ResourceGroupName <String> -Name <String> -VirtualWan <PSVirtualWan> -AddressPrefix <String>
-Location <String> [-HubVnetConnection <PSHubVirtualNetworkConnection[]>]
[-RouteTable <PSVirtualHubRouteTable[]>] [-Tag <Hashtable>] [-Sku <String>] [-PreferredRoutingGateway <String>]
[-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-HubRoutingPreference <String>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### ByVirtualWanResourceId
```
New-AzVirtualHub -ResourceGroupName <String> -Name <String> -VirtualWanId <String> -AddressPrefix <String>
-Location <String> [-HubVnetConnection <PSHubVirtualNetworkConnection[]>]
[-RouteTable <PSVirtualHubRouteTable[]>] [-Tag <Hashtable>] [-Sku <String>] [-PreferredRoutingGateway <String>]
[-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-HubRoutingPreference <String>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -53,6 +53,7 @@ RouteTables : {}
Location : West US
Sku : Standard
PreferredRoutingGateway : ExpressRoute
HubRoutingPreference : ExpressRoute
Type : Microsoft.Network/virtualHubs
ProvisioningState : Succeeded
```
Expand All @@ -79,6 +80,7 @@ RouteTables : {}
Location : West US
Sku : Standard
PreferredRoutingGateway : ExpressRoute
HubRoutingPreference : ExpressRoute
Type : Microsoft.Network/virtualHubs
ProvisioningState : Succeeded
```
Expand Down Expand Up @@ -110,6 +112,7 @@ RouteTables : {}
Location : West US
Sku : Standard
PreferredRoutingGateway : ExpressRoute
HubRoutingPreference : ExpressRoute
Type : Microsoft.Network/virtualHubs
ProvisioningState : Succeeded
```
Expand All @@ -123,9 +126,10 @@ This example is similar to Example 2, but also attaches a route table to the vir
```powershell
New-AzResourceGroup -Location "West US" -Name "testRG"
$virtualWan = New-AzVirtualWan -ResourceGroupName "testRG" -Name "myVirtualWAN" -Location "West US"
New-AzVirtualHub -VirtualWan $virtualWan -ResourceGroupName "testRG" -Name "westushub" -AddressPrefix "10.0.1.0/24" -PreferredRoutingGateway "VpnGateway"
New-AzVirtualHub -VirtualWan $virtualWan -ResourceGroupName "testRG" -Name "westushub" -AddressPrefix "10.0.1.0/24" -HubRoutingPreference "VpnGateway"
```


```output
VirtualWan : /subscriptions/{subscriptionId}resourceGroups/testRG/providers/Microsoft.Network/virtualWans/myVirtualWAN
ResourceGroupName : testRG
Expand All @@ -135,7 +139,7 @@ AddressPrefix : 10.0.1.0/24
RouteTable :
Location : West US
Sku : Standard
PreferredRoutingGateway : VpnGateway
HubRoutingPreference : VpnGateway
VirtualNetworkConnections : {}
Location : West US
Type : Microsoft.Network/virtualHubs
Expand Down Expand Up @@ -237,7 +241,7 @@ Accept wildcard characters: False
```

### -PreferredRoutingGateway
Preferred Routing Gateway to Route On-Prem traffic from VNET
Preferred Routing Gateway to Route On-Prem traffic from VNET (Deprecated, please use HubRoutingPreference)

```yaml
Type: System.String
Expand All @@ -252,6 +256,22 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -HubRoutingPreference
Virtual Hub Routing Preference to route traffic

```yaml
Type: System.String
Parameter Sets: (All)
Aliases:
Accepted values: ExpressRoute, VpnGateway, ASPath

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ResourceGroupName
The resource group name.

Expand Down
34 changes: 25 additions & 9 deletions src/Network/Network/help/Update-AzVirtualHub.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ Updates a virtual hub.
```
Update-AzVirtualHub -ResourceGroupName <String> -Name <String> [-AddressPrefix <String>]
[-HubVnetConnection <PSHubVirtualNetworkConnection[]>] [-RouteTable <PSVirtualHubRouteTable>]
[-Tag <Hashtable>] [-Sku <String>] [-PreferredRoutingGateway <String>] [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-Tag <Hashtable>] [-Sku <String>] [-PreferredRoutingGateway <String>] [-HubRoutingPreference <String>]
[-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### ByVirtualHubResourceId
```
Update-AzVirtualHub -ResourceId <String> [-AddressPrefix <String>]
[-HubVnetConnection <PSHubVirtualNetworkConnection[]>] [-RouteTable <PSVirtualHubRouteTable>]
[-Tag <Hashtable>] [-Sku <String>] [-PreferredRoutingGateway <String>] [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-Tag <Hashtable>] [-Sku <String>] [-PreferredRoutingGateway <String>] [-HubRoutingPreference <String>]
[-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### ByVirtualHubObject
```
Update-AzVirtualHub -InputObject <PSVirtualHub> [-AddressPrefix <String>]
[-HubVnetConnection <PSHubVirtualNetworkConnection[]>] [-RouteTable <PSVirtualHubRouteTable>]
[-Tag <Hashtable>] [-Sku <String>] [-PreferredRoutingGateway <String>] [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-Tag <Hashtable>] [-Sku <String>] [-PreferredRoutingGateway <String>] [-HubRoutingPreference <String>]
[-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -101,7 +101,7 @@ This example is similar to Example 1, but also attaches a route table to the vir
New-AzResourceGroup -Location "West US" -Name "testRG"
$virtualWan = New-AzVirtualWan -ResourceGroupName "testRG" -Name "myVirtualWAN" -Location "West US"
New-AzVirtualHub -VirtualWan $virtualWan -ResourceGroupName "testRG" -Name "westushub" -AddressPrefix "10.0.1.0/24"
Update-AzVirtualHub -ResourceGroupName "testRG" -Name "westushub" -PreferredRoutingGateway "VpnGateway"
Update-AzVirtualHub -ResourceGroupName "testRG" -Name "westushub" -HubRoutingPreference "VpnGateway"
```

```output
Expand All @@ -113,7 +113,7 @@ AddressPrefix : 10.0.1.0/24
RouteTable :
Location : West US
Sku : Standard
PreferredRoutingGateway : VpnGateway
HubRoutingPreference : VpnGateway
VirtualNetworkConnections : {}
Location : West US
Type : Microsoft.Network/virtualHubs
Expand Down Expand Up @@ -215,7 +215,7 @@ Accept wildcard characters: False
```

### -PreferredRoutingGateway
Preferred Routing Gateway to Route On-Prem traffic from VNET
Preferred Routing Gateway to Route On-Prem traffic from VNET (Deprecated, please use HubRoutingPreference)

```yaml
Type: System.String
Expand All @@ -230,6 +230,22 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -HubRoutingPreference
Virtual Hub Routing Preference to route traffic

```yaml
Type: System.String
Parameter Sets: (All)
Aliases:
Accepted values: ExpressRoute, VpnGateway, ASPath

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ResourceGroupName
The resource group name.

Expand Down