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

Support for Preferred Routing Gateway for Virtual Hub #14761

Merged
merged 8 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
- `Update-AzVirtualNetworkGatewayNatRule`
- `Get-AzVirtualNetworkGatewayNatRule`
- `Remove-AzVirtualNetworkGatewayNatRule`
* Updated cmdlets to enable setting of PreferredRoutingGateway on VirtualHub.
- `New-AzVirtualHub`
- `Update-AzVirtualHub`

## Version 4.7.0
* Added new cmdlets to replace old product name `virtual router` with new name `route server` in the future.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Microsoft.Azure.Commands.Network
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using MNM = Microsoft.Azure.Management.Network.Models;

[Cmdlet(VerbsCommon.New,
ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VirtualHub",
Expand Down Expand Up @@ -97,6 +98,15 @@ public class NewAzureRmVirtualHubCommand : VirtualHubBaseCmdlet
[PSArgumentCompleter("Basic", "Standard")]
public string Sku { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Preferred Routing Gateway to Route On-Prem traffic from VNET")]
[ValidateSet(
MNM.PreferredRoutingGateway.ExpressRoute,
MNM.PreferredRoutingGateway.VpnGateway,
IgnoreCase = true)]
public string PreferredRoutingGateway { get; set; }

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

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

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

[Parameter(
Mandatory = false,
HelpMessage = "Preferred Routing Gateway to Route On-Prem traffic from VNET")]
[ValidateSet(
MNM.PreferredRoutingGateway.ExpressRoute,
MNM.PreferredRoutingGateway.VpnGateway,
IgnoreCase = true)]
public string PreferredRoutingGateway { get; set; }

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

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

//// Update the virtual hub
ConfirmAction(
Properties.Resources.SettingResourceMessage,
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 @@ -60,5 +60,8 @@ public class PSVirtualHub : PSTopLevelResource

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

[Ps1Xml(Label = "Preferred Routing Gateway", Target = ViewControl.Table)]
public string PreferredRoutingGateway { 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 @@ -4295,6 +4295,10 @@
<Label>Type</Label>
<PropertyName>Type</PropertyName>
</ListItem>
<ListItem>
<Label>PreferredRoutingGateway</Label>
<PropertyName>PreferredRoutingGateway</PropertyName>
</ListItem>
<ListItem>
<Label>ProvisioningState</Label>
<PropertyName>ProvisioningState</PropertyName>
Expand Down
79 changes: 61 additions & 18 deletions src/Network/Network/help/New-AzVirtualHub.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ 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>] [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-RouteTable <PSVirtualHubRouteTable[]>] [-Tag <Hashtable>] [-Sku <String>] [-PreferredRoutingGateway <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>] [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-RouteTable <PSVirtualHubRouteTable[]>] [-Tag <Hashtable>] [-Sku <String>] [-PreferredRoutingGateway <String>]
[-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand All @@ -50,6 +50,7 @@ VirtualNetworkConnections : {}
RouteTables : {}
Location : West US
Sku : Standard
PreferredRoutingGateway : ExpressRoute
Type : Microsoft.Network/virtualHubs
ProvisioningState : Succeeded
```
Expand All @@ -73,6 +74,7 @@ VirtualNetworkConnections : {}
RouteTables : {}
Location : West US
Sku : Standard
PreferredRoutingGateway : ExpressRoute
Type : Microsoft.Network/virtualHubs
ProvisioningState : Succeeded
```
Expand Down Expand Up @@ -101,6 +103,7 @@ VirtualNetworkConnections : {}
RouteTables : {}
Location : West US
Sku : Standard
PreferredRoutingGateway : ExpressRoute
Type : Microsoft.Network/virtualHubs
ProvisioningState : Succeeded
```
Expand All @@ -109,13 +112,37 @@ The above will create a resource group "testRG", a Virtual WAN and a Virtual Hub

This example is similar to Example 2, but also attaches a route table to the virtual hub.

### Example 4

```powershell
PS C:\> New-AzResourceGroup -Location "West US" -Name "testRG"
PS C:\> $virtualWan = New-AzVirtualWan -ResourceGroupName "testRG" -Name "myVirtualWAN" -Location "West US"
PS C:\> New-AzVirtualHub -VirtualWan $virtualWan -ResourceGroupName "testRG" -Name "westushub" -AddressPrefix "10.0.1.0/24" -PreferredRoutingGateway "VpnGateway"

VirtualWan : /subscriptions/{subscriptionId}resourceGroups/testRG/providers/Microsoft.Network/virtualWans/myVirtualWAN
ResourceGroupName : testRG
Name : westushub
Id : /subscriptions/{subscriptionId}resourceGroups/testRG/providers/Microsoft.Network/virtualHubs/westushub
AddressPrefix : 10.0.1.0/24
RouteTable :
Location : West US
Sku : Standard
PreferredRoutingGateway : VpnGateway
VirtualNetworkConnections : {}
Location : West US
Type : Microsoft.Network/virtualHubs
ProvisioningState : Succeeded
```

The above will create a resource group "testRG", a Virtual WAN and a Virtual Hub in West US in that resource group in Azure. The virtual hub will have preferred routing gateway as VPNGateway.

## PARAMETERS

### -AddressPrefix
The address space string for this virtual hub.

```yaml
Type: String
Type: System.String
Parameter Sets: (All)
Aliases:

Expand All @@ -130,7 +157,7 @@ Accept wildcard characters: False
Run cmdlet in the background

```yaml
Type: SwitchParameter
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Expand All @@ -145,7 +172,7 @@ Accept wildcard characters: False
The credentials, account, tenant, and subscription used for communication with Azure.

```yaml
Type: IAzureContextContainer
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Parameter Sets: (All)
Aliases: AzContext, AzureRmContext, AzureCredential

Expand All @@ -160,7 +187,7 @@ Accept wildcard characters: False
The hub virtual network connections associated with this Virtual Hub.

```yaml
Type: PSHubVirtualNetworkConnection[]
Type: Microsoft.Azure.Commands.Network.Models.PSHubVirtualNetworkConnection[]
Parameter Sets: (All)
Aliases:

Expand All @@ -175,7 +202,7 @@ Accept wildcard characters: False
location.

```yaml
Type: String
Type: System.String
Parameter Sets: (All)
Aliases:

Expand All @@ -190,7 +217,7 @@ Accept wildcard characters: False
The resource name.

```yaml
Type: String
Type: System.String
Parameter Sets: (All)
Aliases: ResourceName, VirtualHubName

Expand All @@ -201,11 +228,27 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -PreferredRoutingGateway
Preferred Routing Gateway to Route On-Prem traffic from VNET

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

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

### -ResourceGroupName
The resource group name.

```yaml
Type: String
Type: System.String
Parameter Sets: (All)
Aliases:

Expand All @@ -220,7 +263,7 @@ Accept wildcard characters: False
The route table associated with this Virtual Hub.

```yaml
Type: PSVirtualHubRouteTable
Type: Microsoft.Azure.Commands.Network.Models.PSVirtualHubRouteTable
Parameter Sets: (All)
Aliases:

Expand All @@ -235,7 +278,7 @@ Accept wildcard characters: False
The sku of the Virtual Hub.

```yaml
Type: String
Type: System.String
Parameter Sets: (All)
Aliases:

Expand All @@ -250,7 +293,7 @@ Accept wildcard characters: False
A hashtable which represents resource tags.

```yaml
Type: Hashtable
Type: System.Collections.Hashtable
Parameter Sets: (All)
Aliases:

Expand All @@ -265,7 +308,7 @@ Accept wildcard characters: False
The virtual wan object this hub is linked to.

```yaml
Type: PSVirtualWan
Type: Microsoft.Azure.Commands.Network.Models.PSVirtualWan
Parameter Sets: ByVirtualWanObject
Aliases:

Expand All @@ -280,7 +323,7 @@ Accept wildcard characters: False
The id of virtual wan object this hub is linked to.

```yaml
Type: String
Type: System.String
Parameter Sets: ByVirtualWanResourceId
Aliases:

Expand All @@ -295,7 +338,7 @@ Accept wildcard characters: False
Prompts you for confirmation before running the cmdlet.

```yaml
Type: SwitchParameter
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: cf

Expand All @@ -311,7 +354,7 @@ Shows what would happen if the cmdlet runs.
The cmdlet is not run.

```yaml
Type: SwitchParameter
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: wi

Expand Down
Loading