Skip to content

Commit ce253b1

Browse files
authored
Merge pull request #9093 from Nilambari/master1
Brooklyn Feature:- Custom routes set on Gateway.
2 parents 228540b + 0403e77 commit ce253b1

File tree

8 files changed

+1921
-1886
lines changed

8 files changed

+1921
-1886
lines changed

src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayTests.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,21 +601,28 @@ function Test-VirtualNetworkGatewayIkeV2
601601
$vnetIpConfig = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet
602602

603603
# Create & Get IkeV2 + SSTP virtualnetworkgateway
604-
New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -EnableBgp $false -GatewaySku VpnGw1 -VpnClientAddressPool 201.169.0.0/16 -VpnClientRootCertificates $rootCert
604+
New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -EnableBgp $false -GatewaySku VpnGw1 -VpnClientAddressPool 201.169.0.0/16 -VpnClientRootCertificates $rootCert -CustomRoute 192.168.0.0/24
605605
$actual = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
606606
Assert-AreEqual "VpnGw1" $actual.Sku.Tier
607607
$protocols = $actual.VpnClientConfiguration.VpnClientProtocols
608608
Assert-AreEqual 2 @($protocols).Count
609609
Assert-AreEqual "SSTP" $protocols[0]
610610
Assert-AreEqual "IkeV2" $protocols[1]
611611
Assert-AreEqual "201.169.0.0/16" $actual.VpnClientConfiguration.VpnClientAddressPool.AddressPrefixes
612+
Assert-AreEqual "192.168.0.0/24" $actual.CustomRoutes.AddressPrefixes
612613

613-
# Update gateway to IkeV2 only
614-
Set-AzVirtualNetworkGateway -VirtualNetworkGateway $actual -VpnClientProtocol IkeV2
614+
# Update gateway to IkeV2 only and update Custom routes
615+
Set-AzVirtualNetworkGateway -VirtualNetworkGateway $actual -VpnClientProtocol IkeV2 -CustomRoute 192.168.1.0/24
615616
$actual = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
616617
$protocols = $actual.VpnClientConfiguration.VpnClientProtocols
617618
Assert-AreEqual 1 @($protocols).Count
618619
Assert-AreEqual "IkeV2" $protocols[0]
620+
Assert-AreEqual "192.168.1.0/24" $actual.CustomRoutes.AddressPrefixes
621+
622+
# Update gateway to remove the Custom routes
623+
Set-AzVirtualNetworkGateway -VirtualNetworkGateway $actual -VpnClientProtocol IkeV2 -CustomRoute @()
624+
$actual = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
625+
Assert-Null $actual.CustomRoutes.AddressPrefixes
619626
}
620627
finally
621628
{

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayTests/VirtualNetworkGatewayIkeV2Test.json

Lines changed: 1823 additions & 1870 deletions
Large diffs are not rendered by default.

src/Network/Network/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
- Updated cmdlets
2828
- New-AzureVirtualNetworkSubnetConfigCommand
2929
- Add-AzureVirtualNetworkSubnetConfigCommand
30+
* Updated below commands for feature: Custom routes set/remove on Brooklyn Gateway.
31+
- Updated New-AzVirtualNetworkGateway: Added optional parameter -CustomRoute to set the address prefixes as custom routes to set on Gateway.
32+
- Updated Set-AzVirtualNetworkGateway: Added optional parameter -CustomRoute to set the address prefixes as custom routes to set on Gateway.
3033

3134
## Version 1.7.0
3235
* Updated cmdlets with plural nouns to singular, and deprecated plural names.

src/Network/Network/Models/PSVirtualNetworkGateway.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class PSVirtualNetworkGateway : PSTopLevelResource
4545

4646
public PSBgpSettings BgpSettings { get; set; }
4747

48+
public PSAddressSpace CustomRoutes { get; set; }
49+
4850
[JsonIgnore]
4951
public string IpConfigurationsText
5052
{
@@ -74,5 +76,11 @@ public string BgpSettingsText
7476
{
7577
get { return JsonConvert.SerializeObject(BgpSettings, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
7678
}
79+
80+
[JsonIgnore]
81+
public string CustomRoutesText
82+
{
83+
get { return JsonConvert.SerializeObject(CustomRoutes, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
84+
}
7785
}
7886
}

src/Network/Network/VirtualNetworkGateway/NewAzureVirtualNetworkGatewayCommand.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ public class NewAzureVirtualNetworkGatewayCommand : VirtualNetworkGatewayBaseCmd
214214
[ValidateNotNullOrEmpty]
215215
public SecureString RadiusServerSecret { get; set; }
216216

217+
[Parameter(
218+
Mandatory = false,
219+
ValueFromPipelineByPropertyName = true,
220+
HelpMessage = "Custom routes AddressPool specified by customer")]
221+
[ValidateNotNullOrEmpty]
222+
public string[] CustomRoute { get; set; }
223+
217224
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
218225
public SwitchParameter AsJob { get; set; }
219226

@@ -385,6 +392,16 @@ private PSVirtualNetworkGateway CreateVirtualNetworkGateway()
385392
}
386393
}
387394

395+
if (this.CustomRoute != null && this.CustomRoute.Any())
396+
{
397+
vnetGateway.CustomRoutes = new PSAddressSpace();
398+
vnetGateway.CustomRoutes.AddressPrefixes = this.CustomRoute?.ToList();
399+
}
400+
else
401+
{
402+
vnetGateway.CustomRoutes = null;
403+
}
404+
388405
// Map to the sdk object
389406
var vnetGatewayModel = NetworkResourceManagerProfile.Mapper.Map<MNM.VirtualNetworkGateway>(vnetGateway);
390407
vnetGatewayModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

src/Network/Network/VirtualNetworkGateway/UpdateAzureVirtualNetworkGatewayCommand.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
namespace Microsoft.Azure.Commands.Network
3030
{
31-
[Cmdlet("Set", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VirtualNetworkGateway",DefaultParameterSetName = VirtualNetworkGatewayParameterSets.Default, SupportsShouldProcess = true),OutputType(typeof(PSVirtualNetworkGateway))]
31+
[Cmdlet("Set", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VirtualNetworkGateway", DefaultParameterSetName = VirtualNetworkGatewayParameterSets.Default, SupportsShouldProcess = true), OutputType(typeof(PSVirtualNetworkGateway))]
3232
public class SetAzureVirtualNetworkGatewayCommand : VirtualNetworkGatewayBaseCmdlet
3333
{
3434
[Parameter(
@@ -148,6 +148,12 @@ public class SetAzureVirtualNetworkGatewayCommand : VirtualNetworkGatewayBaseCmd
148148
[ValidateNotNullOrEmpty]
149149
public SecureString RadiusServerSecret { get; set; }
150150

151+
[Parameter(
152+
Mandatory = false,
153+
ValueFromPipelineByPropertyName = true,
154+
HelpMessage = "Custom routes AddressPool specified by customer")]
155+
public string[] CustomRoute { get; set; }
156+
151157
[Parameter(
152158
Mandatory = true,
153159
ParameterSetName = VirtualNetworkGatewayParameterSets.UpdateResourceWithTags,
@@ -273,10 +279,19 @@ public override void Execute()
273279
throw new ArgumentException("PeerWeight must be a positive integer");
274280
}
275281

282+
if (this.CustomRoute != null && this.CustomRoute.Any())
283+
{
284+
this.VirtualNetworkGateway.CustomRoutes = new PSAddressSpace();
285+
this.VirtualNetworkGateway.CustomRoutes.AddressPrefixes = this.CustomRoute?.ToList();
286+
}
287+
else
288+
{
289+
this.VirtualNetworkGateway.CustomRoutes = null;
290+
}
291+
276292
// Map to the sdk object
277293
MNM.VirtualNetworkGateway sdkVirtualNetworkGateway = NetworkResourceManagerProfile.Mapper.Map<MNM.VirtualNetworkGateway>(this.VirtualNetworkGateway);
278-
279-
sdkVirtualNetworkGateway.Tags =
294+
sdkVirtualNetworkGateway.Tags =
280295
ParameterSetName.Contains(VirtualNetworkGatewayParameterSets.UpdateResourceWithTags) ?
281296
TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true) :
282297
TagsConversionHelper.CreateTagDictionary(this.VirtualNetworkGateway.Tag, validate: true);

src/Network/Network/help/New-AzVirtualNetworkGateway.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ New-AzVirtualNetworkGateway -Name <String> -ResourceGroupName <String> -Location
2121
[-GatewayDefaultSite <PSLocalNetworkGateway>] [-VpnClientAddressPool <String[]>]
2222
[-VpnClientProtocol <String[]>] [-VpnClientRootCertificates <PSVpnClientRootCertificate[]>]
2323
[-VpnClientRevokedCertificates <PSVpnClientRevokedCertificate[]>] [-VpnClientIpsecPolicy <PSIpsecPolicy[]>]
24-
[-Asn <UInt32>] [-PeerWeight <Int32>] [-Tag <Hashtable>] [-Force] [-AsJob]
24+
[-Asn <UInt32>] [-PeerWeight <Int32>] [-Tag <Hashtable>] [-Force] [-CustomRoute <String[]>] [-AsJob]
2525
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2626
```
2727

@@ -34,8 +34,8 @@ New-AzVirtualNetworkGateway -Name <String> -ResourceGroupName <String> -Location
3434
[-VpnClientProtocol <String[]>] [-VpnClientRootCertificates <PSVpnClientRootCertificate[]>]
3535
[-VpnClientRevokedCertificates <PSVpnClientRevokedCertificate[]>] [-VpnClientIpsecPolicy <PSIpsecPolicy[]>]
3636
[-Asn <UInt32>] [-PeerWeight <Int32>] [-Tag <Hashtable>] [-Force] -RadiusServerAddress <String>
37-
-RadiusServerSecret <SecureString> [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
38-
[<CommonParameters>]
37+
-RadiusServerSecret <SecureString> [-CustomRoute <String[]>] [-AsJob]
38+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
3939
```
4040

4141
## DESCRIPTION
@@ -60,7 +60,7 @@ $vnet = New-AzVirtualNetwork -AddressPrefix "10.254.0.0/27" -Location "UK West"
6060
$subnet = Get-AzVirtualNetworkSubnetConfig -name 'gatewaysubnet' -VirtualNetwork $vnet
6161
$ngwipconfig = New-AzVirtualNetworkGatewayIpConfig -Name ngwipconfig -SubnetId $subnet.Id -PublicIpAddressId $ngwpip.Id
6262
63-
New-AzVirtualNetworkGateway -Name myNGW -ResourceGroupName vnet-gateway -Location "UK West" -IpConfigurations $ngwIpConfig -GatewayType "Vpn" -VpnType "RouteBased" -GatewaySku "Basic"
63+
New-AzVirtualNetworkGateway -Name myNGW -ResourceGroupName vnet-gateway -Location "UK West" -IpConfigurations $ngwIpConfig -GatewayType "Vpn" -VpnType "RouteBased" -GatewaySku "Basic" -CustomRoute 192.168.0.0/24
6464
```
6565

6666
The above will create a resource group, request a Public IP Address, create a Virtual Network and
@@ -80,12 +80,12 @@ $subnet = Get-AzVirtualNetworkSubnetConfig -name 'gatewaysubnet' -VirtualNetwork
8080
$ngwipconfig = New-AzVirtualNetworkGatewayIpConfig -Name ngwipconfig -SubnetId $subnet.Id -PublicIpAddressId $ngwpip.Id
8181
$Secure_String_Pwd = ConvertTo-SecureString "TestRadiusServerPassword" -AsPlainText -Force
8282
83-
New-AzVirtualNetworkGateway -Name myNGW -ResourceGroupName vnet-gateway -Location "UK West" -IpConfigurations $ngwIpConfig -GatewayType "Vpn" -VpnType "RouteBased" -GatewaySku "Basic" -RadiusServerAddress "TestRadiusServer" -RadiusServerSecret $Secure_String_Pwd
83+
New-AzVirtualNetworkGateway -Name myNGW -ResourceGroupName vnet-gateway -Location "UK West" -IpConfigurations $ngwIpConfig -GatewayType "Vpn" -VpnType "RouteBased" -GatewaySku "Basic" -RadiusServerAddress "TestRadiusServer" -RadiusServerSecret $Secure_String_Pwd -CustomRoute 192.168.0.0/24
8484
```
8585

8686
The above will create a resource group, request a Public IP Address, create a Virtual Network and
8787
subnet and create a Virtual Network Gateway in Azure.
88-
The gateway will be called "myNGW" within the resource group "vnet-gateway" in the location "UK West" with the previously created IP configurations saved in the variable "ngwIPConfig," the gateway type of "VPN," the vpn type "RouteBased," and the sku "Basic." It also adds an external radius server with address "TestRadiusServer"
88+
The gateway will be called "myNGW" within the resource group "vnet-gateway" in the location "UK West" with the previously created IP configurations saved in the variable "ngwIPConfig," the gateway type of "VPN," the vpn type "RouteBased," and the sku "Basic." It also adds an external radius server with address "TestRadiusServer". It will also set custom routes specified by customers on gateway.
8989

9090
### 1: Create a Virtual Network Gateway with P2S settings
9191
```
@@ -99,12 +99,13 @@ $ngwipconfig = New-AzVirtualNetworkGatewayIpConfig -Name ngwipconfig -SubnetId $
9999
$rootCert = New-AzVpnClientRootCertificate -Name $clientRootCertName -PublicCertData $samplePublicCertData
100100
$vpnclientipsecpolicy = New-AzVpnClientIpsecPolicy -IpsecEncryption AES256 -IpsecIntegrity SHA256 -SALifeTimeSeconds 86471 -SADataSizeKilobytes 429496 -IkeEncryption AES256 -IkeIntegrity SHA384 -DhGroup DHGroup2 -PfsGroup PFS2
101101
102-
New-AzVirtualNetworkGateway -Name myNGW -ResourceGroupName vnet-gateway -Location "UK West" -IpConfigurations $ngwIpConfig -GatewayType "Vpn" -VpnType "RouteBased" -GatewaySku "VpnGw1" -VpnClientProtocol IkeV2 -VpnClientAddressPool 201.169.0.0/16 -VpnClientRootCertificates $rootCert -VpnClientIpsecPolicy $vpnclientipsecpolicy
102+
New-AzVirtualNetworkGateway -Name myNGW -ResourceGroupName vnet-gateway -Location "UK West" -IpConfigurations $ngwIpConfig -GatewayType "Vpn" -VpnType "RouteBased" -GatewaySku "VpnGw1" -VpnClientProtocol IkeV2 -VpnClientAddressPool 201.169.0.0/16 -VpnClientRootCertificates $rootCert -VpnClientIpsecPolicy $vpnclientipsecpolicy -CustomRoute 192.168.0.0/24
103103
```
104104

105105
The above will create a resource group, request a Public IP Address, create a Virtual Network and
106106
subnet and create a Virtual Network Gateway with P2S settings e.g. VpnProtocol,VpnClientAddressPool,VpnClientRootCertificates,VpnClientIpsecPolicy etc. in Azure.
107107
The gateway will be called "myNGW" within the resource group "vnet-gateway" in the location "UK West" with the previously created IP configurations saved in the variable "ngwIPConfig," the gateway type of "VPN," the vpn type "RouteBased," and the sku "VpnGw1." Vpn settings will be set on Gateway such as VpnProtocol set as Ikev2, VpnClientAddressPool as "201.169.0.0/16", VpnClientRootCertificate set as passed one: clientRootCertName and custom vpn ipsec policy passed in object:$vpnclientipsecpolicy
108+
It will also set custom routes specified by customers on gateway.
108109

109110
## PARAMETERS
110111

@@ -137,6 +138,21 @@ Accept pipeline input: True (ByPropertyName)
137138
Accept wildcard characters: False
138139
```
139140
141+
### -CustomRoute
142+
Custom routes AddressPool specified by customer
143+
144+
```yaml
145+
Type: System.String[]
146+
Parameter Sets: (All)
147+
Aliases:
148+
149+
Required: False
150+
Position: Named
151+
Default value: None
152+
Accept pipeline input: True (ByPropertyName)
153+
Accept wildcard characters: False
154+
```
155+
140156
### -DefaultProfile
141157
The credentials, account, tenant, and subscription used for communication with azure.
142158

src/Network/Network/help/Set-AzVirtualNetworkGateway.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ Set-AzVirtualNetworkGateway -VirtualNetworkGateway <PSVirtualNetworkGateway> [-G
1919
[-GatewayDefaultSite <PSLocalNetworkGateway>] [-VpnClientAddressPool <String[]>]
2020
[-VpnClientProtocol <String[]>] [-VpnClientRootCertificates <PSVpnClientRootCertificate[]>]
2121
[-VpnClientRevokedCertificates <PSVpnClientRevokedCertificate[]>] [-VpnClientIpsecPolicy <PSIpsecPolicy[]>]
22-
[-Asn <UInt32>] [-PeerWeight <Int32>] [-EnableActiveActiveFeature] [-DisableActiveActiveFeature] [-AsJob]
23-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
22+
[-Asn <UInt32>] [-PeerWeight <Int32>] [-EnableActiveActiveFeature] [-DisableActiveActiveFeature]
23+
[-CustomRoute <String[]>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
24+
[<CommonParameters>]
2425
```
2526

2627
### RadiusServerConfiguration
@@ -30,7 +31,7 @@ Set-AzVirtualNetworkGateway -VirtualNetworkGateway <PSVirtualNetworkGateway> [-G
3031
[-VpnClientProtocol <String[]>] [-VpnClientRootCertificates <PSVpnClientRootCertificate[]>]
3132
[-VpnClientRevokedCertificates <PSVpnClientRevokedCertificate[]>] [-VpnClientIpsecPolicy <PSIpsecPolicy[]>]
3233
[-Asn <UInt32>] [-PeerWeight <Int32>] [-EnableActiveActiveFeature] [-DisableActiveActiveFeature]
33-
-RadiusServerAddress <String> -RadiusServerSecret <SecureString> [-AsJob]
34+
-RadiusServerAddress <String> -RadiusServerSecret <SecureString> [-CustomRoute <String[]>] [-AsJob]
3435
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
3536
```
3637

@@ -167,6 +168,21 @@ Accept pipeline input: True (ByPropertyName)
167168
Accept wildcard characters: False
168169
```
169170
171+
### -CustomRoute
172+
Custom routes AddressPool specified by customer
173+
174+
```yaml
175+
Type: System.String[]
176+
Parameter Sets: (All)
177+
Aliases:
178+
179+
Required: False
180+
Position: Named
181+
Default value: None
182+
Accept pipeline input: True (ByPropertyName)
183+
Accept wildcard characters: False
184+
```
185+
170186
### -DefaultProfile
171187
The credentials, account, tenant, and subscription used for communication with azure.
172188

0 commit comments

Comments
 (0)