Skip to content

Commit 7a71ef7

Browse files
aknandagitAmit Kumar NandaNilambari
authored
FQDN support for LocalNetworkGateway and VpnSiteLink objects (#11482)
* FQDN support for LocalNetworkGateway and VpnSiteLink objects * Add test TestLocalNetworkGatewayCRUD recording * Added cortex CRUD session record * Fixed test failures Co-authored-by: Amit Kumar Nanda <[email protected]> Co-authored-by: Nilambari <[email protected]>
1 parent 72b61b5 commit 7a71ef7

File tree

14 files changed

+1359
-631
lines changed

14 files changed

+1359
-631
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ function Test-CortexCRUD
118118
$vpnSite2AddressSpaces[1] = "192.169.3.0/24"
119119
$vpnSiteLink1 = New-AzVpnSiteLink -Name $vpnSiteLink1Name -IpAddress "5.5.5.5" -LinkProviderName "SomeTelecomProvider1" -LinkSpeedInMbps "10"
120120
$vpnSiteLink2 = New-AzVpnSiteLink -Name $vpnSiteLink2Name -IpAddress "5.5.5.6" -LinkProviderName "SomeTelecomProvider2" -LinkSpeedInMbps "10"
121+
121122
$createdVpnSite2 = New-AzVpnSite -ResourceGroupName $rgName -Name $vpnSite2Name -Location $rglocation -VirtualWan $virtualWan -AddressSpace $vpnSite2AddressSpaces -DeviceModel "SomeDevice" -DeviceVendor "SomeDeviceVendor" -VpnSiteLink @($vpnSiteLink1, $vpnSiteLink2)
122123
$vpnSite2 = Get-AzVpnSite -ResourceGroupName $rgName -Name $vpnSite2Name
123124
Assert-AreEqual $rgName $vpnSite2.ResourceGroupName

src/Network/Network.Test/ScenarioTests/LocalNetworkGatewayTests.ps1

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ function Test-LocalNetworkGatewayCRUD
2929
{
3030
# Create the resource group
3131
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
32+
33+
# Create and Get LocalNetworkGateway with Fqdn
34+
$rnameFqdn = $rname + "Fqdn"
35+
$job = New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rnameFqdn -location $location -AddressPrefix 192.168.0.0/16 -Fqdn "lng.ontoso.com" -AsJob
36+
$job | Wait-Job
37+
$actual = $job | Receive-Job
38+
$expected = Get-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rnameFqdn
39+
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
40+
Assert-AreEqual $expected.Name $actual.Name
41+
Assert-AreEqual $expected.Fqdn $actual.Fqdn
42+
Assert-AreEqual "192.168.0.0/16" $expected.LocalNetworkAddressSpace.AddressPrefixes[0]
3243

3344
# Create & Get LocalNetworkGateway
3445
$job = New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -AddressPrefix 192.168.0.0/16 -GatewayIpAddress 192.168.3.4 -AsJob
@@ -43,12 +54,13 @@ function Test-LocalNetworkGatewayCRUD
4354

4455
# List LocalNetworkGateways
4556
$list = Get-AzLocalNetworkGateway -ResourceGroupName $rgname
46-
Assert-AreEqual 1 @($list).Count
57+
Assert-AreEqual 2 @($list).Count
4758
Assert-AreEqual $list[0].ResourceGroupName $actual.ResourceGroupName
4859
Assert-AreEqual $list[0].Name $actual.Name
4960
Assert-AreEqual $list[0].Location $actual.Location
5061
Assert-AreEqual "192.168.3.4" $list[0].GatewayIpAddress
51-
62+
63+
5264
# Set/Update LocalNetworkGateway
5365
$job = Set-AzLocalNetworkGateway -LocalNetworkGateway $expected -AddressPrefix "200.168.0.0/16" -AsJob
5466
$job | Wait-Job
@@ -86,15 +98,21 @@ function Test-LocalNetworkGatewayCRUD
8698
$job | Wait-Job
8799
$delete = $job | Receive-Job
88100
Assert-AreEqual true $delete
101+
102+
# Delete LocalNetworkGateway
103+
$job = Remove-AzLocalNetworkGateway -ResourceGroupName $actual.ResourceGroupName -name $rnameFqdn -PassThru -Force -AsJob
104+
$job | Wait-Job
105+
$delete = $job | Receive-Job
106+
Assert-AreEqual true $delete
89107

90108
$list = Get-AzLocalNetworkGateway -ResourceGroupName $actual.ResourceGroupName
91109
Assert-AreEqual 0 @($list).Count
92110

93111
# Test error handling
94112
Assert-ThrowsContains { Set-AzLocalNetworkGateway -LocalNetworkGateway $actual } "not found"
95-
Assert-Throws { New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -PeerWeight -1 } "PeerWeight cannot be negative"
96-
Assert-ThrowsContains { New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -Asn 64 } "ASN and BgpPeeringAddress must both be specified"
97-
Assert-ThrowsContains { New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -BgpPeeringAddress "1.2.3.4" } "ASN and BgpPeeringAddress must both be specified"
113+
Assert-Throws { New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rname -GatewayIpAddress 192.168.3.4 -location $location -PeerWeight -1 } "PeerWeight cannot be negative"
114+
Assert-ThrowsContains { New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rname -GatewayIpAddress 192.168.3.4 -location $location -Asn 64 } "ASN and BgpPeeringAddress must both be specified"
115+
Assert-ThrowsContains { New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rname -GatewayIpAddress 192.168.3.4 -location $location -BgpPeeringAddress "1.2.3.4" } "ASN and BgpPeeringAddress must both be specified"
98116
}
99117
finally
100118
{

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.LocalNetworkGatewayTests/TestLocalNetworkGatewayCRUD.json

Lines changed: 1201 additions & 615 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
@@ -19,6 +19,9 @@
1919
--->
2020

2121
## Upcoming Release
22+
* Updated cmdlets to enable FQDN based LocalNetworkGateways and VpnSites
23+
- `New-AzLocalNetworkGateway`
24+
- `New-AzVpnSiteLink`
2225

2326
* Add Support for IPv6 address family in ExpressRouteCircuitConnectionConfig (Global Reach)
2427
- Added Cmdlet

src/Network/Network/Cortex/CortexParameterSetNames.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ internal static class CortexParameterSetNames
4242
internal const string ByVpnSiteName = "ByVpnSiteName";
4343
internal const string ByVpnSiteIpAddress = "ByVpnSiteIpAddress";
4444
internal const string ByVpnSiteLinkObject = "ByVpnSiteLinkObject";
45+
46+
internal const string ByVpnSiteLinkIpAddress = "ByVpnSiteLinkIpAddress";
47+
internal const string ByVpnSiteLinkFqdn = "ByVpnSiteLinkFqdn";
4548

4649
internal const string ByVpnConnectionObject = "ByVpnConnectionObject";
4750
internal const string ByVpnConnectionResourceId = "ByVpnConnectionResourceId";

src/Network/Network/Cortex/VpnSite/NewAzVpnSiteLinkCommand.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@ public class NewAzVpnSiteLinkCommand : NetworkBaseCmdlet
3131
[ValidateNotNullOrEmpty]
3232
public string Name { get; set; }
3333

34-
[Parameter(
35-
Mandatory = true,
34+
[Parameter(Mandatory = true,
35+
ParameterSetName = CortexParameterSetNames.ByVpnSiteLinkIpAddress,
3636
HelpMessage = "The Next Hop IpAddress.")]
3737
[ValidateNotNullOrEmpty]
3838
public string IPAddress { get; set; }
3939

40+
[Parameter(Mandatory = true,
41+
ParameterSetName = CortexParameterSetNames.ByVpnSiteLinkFqdn,
42+
HelpMessage = "The Next Hop Fqdn.")]
43+
[ValidateNotNullOrEmpty]
44+
public string Fqdn { get; set; }
45+
4046
[Parameter(
4147
Mandatory = false,
4248
HelpMessage = "Link Provider Name.")]
@@ -64,9 +70,30 @@ public override void Execute()
6470
var vpnSiteLink = new PSVpnSiteLink
6571
{
6672
Name = this.Name,
67-
IpAddress = this.IPAddress
6873
};
6974

75+
if (ParameterSetName.Contains(CortexParameterSetNames.ByVpnSiteLinkIpAddress))
76+
{
77+
System.Net.IPAddress ipAddress;
78+
if (string.IsNullOrWhiteSpace(this.IPAddress) ||
79+
!System.Net.IPAddress.TryParse(this.IPAddress, out ipAddress))
80+
{
81+
throw new PSArgumentException(Properties.Resources.InvalidIPAddress);
82+
}
83+
84+
vpnSiteLink.IpAddress = this.IPAddress;
85+
vpnSiteLink.Fqdn = string.Empty;
86+
}
87+
else if (ParameterSetName.Contains(CortexParameterSetNames.ByVpnSiteLinkFqdn))
88+
{
89+
if (string.IsNullOrWhiteSpace(this.Fqdn))
90+
{
91+
throw new PSArgumentException(Properties.Resources.InvalidFqdn);
92+
}
93+
vpnSiteLink.Fqdn = this.Fqdn;
94+
vpnSiteLink.IpAddress = string.Empty;
95+
}
96+
7097
if (BGPAsn > 0 || !string.IsNullOrWhiteSpace(BGPPeeringAddress))
7198
{
7299
vpnSiteLink.BgpProperties = ValidateAndCreatePSVpnLinkBgpSettings(BGPAsn, BGPPeeringAddress);

src/Network/Network/LocalNetworkGateway/NewAzureLocalNetworkGatewayCommand.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ namespace Microsoft.Azure.Commands.Network
2828
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "LocalNetworkGateway", SupportsShouldProcess = true),OutputType(typeof(PSLocalNetworkGateway))]
2929
public class NewAzureLocalNetworkGatewayCommand : LocalNetworkGatewayBaseCmdlet
3030
{
31+
public const string ByLocalNetworkGatewayIpAddress = "ByLocalNetworkGatewayIpAddress";
32+
public const string ByLocalNetworkGatewayFqdn = "ByLocalNetworkGatewayFqdn";
33+
3134
[Alias("ResourceName")]
3235
[Parameter(
3336
Mandatory = true,
@@ -53,11 +56,19 @@ public class NewAzureLocalNetworkGatewayCommand : LocalNetworkGatewayBaseCmdlet
5356
public virtual string Location { get; set; }
5457

5558
[Parameter(
56-
Mandatory = false,
57-
ValueFromPipelineByPropertyName = true,
58-
HelpMessage = "IP address of local network gateway.")]
59+
Mandatory = false,
60+
ValueFromPipelineByPropertyName = true,
61+
ParameterSetName = ByLocalNetworkGatewayIpAddress,
62+
HelpMessage = "IP address of local network gateway.")]
5963
public string GatewayIpAddress { get; set; }
6064

65+
[Parameter(
66+
Mandatory = false,
67+
ValueFromPipelineByPropertyName = true,
68+
ParameterSetName = ByLocalNetworkGatewayFqdn,
69+
HelpMessage = "FQDN of local network gateway.")]
70+
public string Fqdn { get; set; }
71+
6172
[Parameter(
6273
Mandatory = false,
6374
ValueFromPipelineByPropertyName = true,
@@ -122,7 +133,17 @@ private PSLocalNetworkGateway CreateLocalNetworkGateway()
122133
localnetGateway.Location = this.Location;
123134
localnetGateway.LocalNetworkAddressSpace = new PSAddressSpace();
124135
localnetGateway.LocalNetworkAddressSpace.AddressPrefixes = this.AddressPrefix?.ToList();
125-
localnetGateway.GatewayIpAddress = this.GatewayIpAddress;
136+
137+
if (ParameterSetName.Contains(ByLocalNetworkGatewayIpAddress))
138+
{
139+
localnetGateway.GatewayIpAddress = this.GatewayIpAddress;
140+
localnetGateway.Fqdn = string.Empty;
141+
}
142+
else if (ParameterSetName.Contains(ByLocalNetworkGatewayFqdn))
143+
{
144+
localnetGateway.Fqdn = this.Fqdn;
145+
localnetGateway.GatewayIpAddress = string.Empty;
146+
}
126147

127148
if (this.PeerWeight < 0)
128149
{

src/Network/Network/Models/Cortex/PSVpnSiteLink.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public class PSVpnSiteLink : PSChildResource
1010
[Ps1Xml(Label = "Ip Address", Target = ViewControl.Table)]
1111
public string IpAddress { get; set; }
1212

13+
[Ps1Xml(Target = ViewControl.Table)]
14+
public string Fqdn { get; set; }
15+
1316
public PSVpnLinkProviderProperties LinkProperties { get; set; }
1417

1518
public PSVpnLinkBgpSettings BgpProperties { get; set; }

src/Network/Network/Models/PSLocalNetworkGateway.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public class PSLocalNetworkGateway : PSTopLevelResource
2323
[Ps1Xml(Target = ViewControl.Table)]
2424
public string GatewayIpAddress { get; set; }
2525

26+
[Ps1Xml(Target = ViewControl.Table)]
27+
public string Fqdn { get; set; }
28+
2629
public PSAddressSpace LocalNetworkAddressSpace { get; set; }
2730

2831
[Ps1Xml(Target = ViewControl.Table)]

src/Network/Network/Network.format.ps1xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,10 @@
11731173
<Label>GatewayIpAddress</Label>
11741174
<PropertyName>GatewayIpAddress</PropertyName>
11751175
</ListItem>
1176+
<ListItem>
1177+
<Label>Fqdn</Label>
1178+
<PropertyName>Fqdn</PropertyName>
1179+
</ListItem>
11761180
<ListItem>
11771181
<Label>LocalNetworkAddressSpace</Label>
11781182
<PropertyName>AddressSpaceText</PropertyName>

src/Network/Network/Properties/Resources.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Network/Network/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,9 @@
656656
<data name="InvalidFlowLogResourceId" xml:space="preserve">
657657
<value>Provided flowLog resourceId is invalid.</value>
658658
</data>
659+
<data name="InvalidFqdn" xml:space="preserve">
660+
<value>The Fqdn specified is invalid.</value>
661+
</data>
659662
<data name="ExpressRoutePrivatePeeringNotFound" xml:space="preserve">
660663
<value>Private Peering needs to be configured on the Express Route Circuit.</value>
661664
</data>

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ Creates a Local Network Gateway
1313

1414
## SYNTAX
1515

16+
### ByLocalNetworkGatewayIpAddress
1617
```
1718
New-AzLocalNetworkGateway -Name <String> -ResourceGroupName <String> -Location <String>
1819
[-GatewayIpAddress <String>] [-AddressPrefix <String[]>] [-Asn <UInt32>] [-BgpPeeringAddress <String>]
1920
[-PeerWeight <Int32>] [-Tag <Hashtable>] [-Force] [-AsJob] [-DefaultProfile <IAzureContextContainer>]
2021
[-WhatIf] [-Confirm] [<CommonParameters>]
2122
```
2223

24+
### ByLocalNetworkGatewayFqdn
25+
```
26+
New-AzLocalNetworkGateway -Name <String> -ResourceGroupName <String> -Location <String> [-Fqdn <String>]
27+
[-AddressPrefix <String[]>] [-Asn <UInt32>] [-BgpPeeringAddress <String>] [-PeerWeight <Int32>]
28+
[-Tag <Hashtable>] [-Force] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
29+
[<CommonParameters>]
30+
```
31+
2332
## DESCRIPTION
2433
The Local Network Gateway is the object representing your VPN device On-Premises.
2534
The **New-AzLocalNetworkGateway** cmdlet creates the object representing your on-prem gateway
@@ -123,10 +132,25 @@ Accept pipeline input: False
123132
Accept wildcard characters: False
124133
```
125134
135+
### -Fqdn
136+
FQDN of local network gateway.
137+
138+
```yaml
139+
Type: System.String
140+
Parameter Sets: ByLocalNetworkGatewayFqdn
141+
Aliases:
142+
143+
Required: False
144+
Position: Named
145+
Default value: None
146+
Accept pipeline input: True (ByPropertyName)
147+
Accept wildcard characters: False
148+
```
149+
126150
### -GatewayIpAddress
127151
```yaml
128152
Type: System.String
129-
Parameter Sets: (All)
153+
Parameter Sets: ByLocalNetworkGatewayIpAddress
130154
Aliases:
131155

132156
Required: False
@@ -238,7 +262,7 @@ Accept wildcard characters: False
238262
```
239263
240264
### CommonParameters
241-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
265+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
242266
243267
## INPUTS
244268

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,20 @@ Creates an Azure VpnSiteLink object.
1212

1313
## SYNTAX
1414

15+
### ByVpnSiteLinkIpAddress
1516
```
1617
New-AzVpnSiteLink -Name <String> -IPAddress <String> [-LinkProviderName <String>] [-LinkSpeedInMbps <UInt32>]
1718
[-BGPAsn <UInt32>] [-BGPPeeringAddress <String>] [-DefaultProfile <IAzureContextContainer>]
1819
[<CommonParameters>]
1920
```
2021

22+
### ByVpnSiteLinkFqdn
23+
```
24+
New-AzVpnSiteLink -Name <String> -Fqdn <String> [-LinkProviderName <String>] [-LinkSpeedInMbps <UInt32>]
25+
[-BGPAsn <UInt32>] [-BGPPeeringAddress <String>] [-DefaultProfile <IAzureContextContainer>]
26+
[<CommonParameters>]
27+
```
28+
2129
## DESCRIPTION
2230
Creates an Azure VpnSiteLink object.
2331

@@ -84,12 +92,27 @@ Accept pipeline input: False
8492
Accept wildcard characters: False
8593
```
8694
95+
### -Fqdn
96+
The Next Hop Fqdn.
97+
98+
```yaml
99+
Type: System.String
100+
Parameter Sets: ByVpnSiteLinkFqdn
101+
Aliases:
102+
103+
Required: True
104+
Position: Named
105+
Default value: None
106+
Accept pipeline input: False
107+
Accept wildcard characters: False
108+
```
109+
87110
### -IPAddress
88111
The Next Hop IpAddress.
89112
90113
```yaml
91114
Type: System.String
92-
Parameter Sets: (All)
115+
Parameter Sets: ByVpnSiteLinkIpAddress
93116
Aliases:
94117

95118
Required: True

0 commit comments

Comments
 (0)