Skip to content

FQDN support for LocalNetworkGateway and VpnSiteLink objects #11482

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

Merged
merged 7 commits into from
Apr 10, 2020
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
1 change: 1 addition & 0 deletions src/Network/Network.Test/ScenarioTests/CortexTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ function Test-CortexCRUD
$vpnSite2AddressSpaces[1] = "192.169.3.0/24"
$vpnSiteLink1 = New-AzVpnSiteLink -Name $vpnSiteLink1Name -IpAddress "5.5.5.5" -LinkProviderName "SomeTelecomProvider1" -LinkSpeedInMbps "10"
$vpnSiteLink2 = New-AzVpnSiteLink -Name $vpnSiteLink2Name -IpAddress "5.5.5.6" -LinkProviderName "SomeTelecomProvider2" -LinkSpeedInMbps "10"

$createdVpnSite2 = New-AzVpnSite -ResourceGroupName $rgName -Name $vpnSite2Name -Location $rglocation -VirtualWan $virtualWan -AddressSpace $vpnSite2AddressSpaces -DeviceModel "SomeDevice" -DeviceVendor "SomeDeviceVendor" -VpnSiteLink @($vpnSiteLink1, $vpnSiteLink2)
$vpnSite2 = Get-AzVpnSite -ResourceGroupName $rgName -Name $vpnSite2Name
Assert-AreEqual $rgName $vpnSite2.ResourceGroupName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ function Test-LocalNetworkGatewayCRUD
{
# Create the resource group
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }

# Create and Get LocalNetworkGateway with Fqdn
$rnameFqdn = $rname + "Fqdn"
$job = New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rnameFqdn -location $location -AddressPrefix 192.168.0.0/16 -Fqdn "lng.ontoso.com" -AsJob
$job | Wait-Job
$actual = $job | Receive-Job
$expected = Get-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rnameFqdn
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual $expected.Name $actual.Name
Assert-AreEqual $expected.Fqdn $actual.Fqdn
Assert-AreEqual "192.168.0.0/16" $expected.LocalNetworkAddressSpace.AddressPrefixes[0]

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

# List LocalNetworkGateways
$list = Get-AzLocalNetworkGateway -ResourceGroupName $rgname
Assert-AreEqual 1 @($list).Count
Assert-AreEqual 2 @($list).Count
Assert-AreEqual $list[0].ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual $list[0].Name $actual.Name
Assert-AreEqual $list[0].Location $actual.Location
Assert-AreEqual "192.168.3.4" $list[0].GatewayIpAddress



# Set/Update LocalNetworkGateway
$job = Set-AzLocalNetworkGateway -LocalNetworkGateway $expected -AddressPrefix "200.168.0.0/16" -AsJob
$job | Wait-Job
Expand Down Expand Up @@ -86,15 +98,21 @@ function Test-LocalNetworkGatewayCRUD
$job | Wait-Job
$delete = $job | Receive-Job
Assert-AreEqual true $delete

# Delete LocalNetworkGateway
$job = Remove-AzLocalNetworkGateway -ResourceGroupName $actual.ResourceGroupName -name $rnameFqdn -PassThru -Force -AsJob
$job | Wait-Job
$delete = $job | Receive-Job
Assert-AreEqual true $delete

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

# Test error handling
Assert-ThrowsContains { Set-AzLocalNetworkGateway -LocalNetworkGateway $actual } "not found"
Assert-Throws { New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -PeerWeight -1 } "PeerWeight cannot be negative"
Assert-ThrowsContains { New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -Asn 64 } "ASN and BgpPeeringAddress must both be specified"
Assert-ThrowsContains { New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -BgpPeeringAddress "1.2.3.4" } "ASN and BgpPeeringAddress must both be specified"
Assert-Throws { New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rname -GatewayIpAddress 192.168.3.4 -location $location -PeerWeight -1 } "PeerWeight cannot be negative"
Assert-ThrowsContains { New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $rname -GatewayIpAddress 192.168.3.4 -location $location -Asn 64 } "ASN and BgpPeeringAddress must both be specified"
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"
}
finally
{
Expand Down

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
--->

## Upcoming Release
* Updated cmdlets to enable FQDN based LocalNetworkGateways and VpnSites
- `New-AzLocalNetworkGateway`
- `New-AzVpnSiteLink`

* Add Support for IPv6 address family in ExpressRouteCircuitConnectionConfig (Global Reach)
- Added Cmdlet
Expand Down
3 changes: 3 additions & 0 deletions src/Network/Network/Cortex/CortexParameterSetNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ internal static class CortexParameterSetNames
internal const string ByVpnSiteName = "ByVpnSiteName";
internal const string ByVpnSiteIpAddress = "ByVpnSiteIpAddress";
internal const string ByVpnSiteLinkObject = "ByVpnSiteLinkObject";

internal const string ByVpnSiteLinkIpAddress = "ByVpnSiteLinkIpAddress";
internal const string ByVpnSiteLinkFqdn = "ByVpnSiteLinkFqdn";

internal const string ByVpnConnectionObject = "ByVpnConnectionObject";
internal const string ByVpnConnectionResourceId = "ByVpnConnectionResourceId";
Expand Down
33 changes: 30 additions & 3 deletions src/Network/Network/Cortex/VpnSite/NewAzVpnSiteLinkCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ public class NewAzVpnSiteLinkCommand : NetworkBaseCmdlet
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(
Mandatory = true,
[Parameter(Mandatory = true,
ParameterSetName = CortexParameterSetNames.ByVpnSiteLinkIpAddress,
HelpMessage = "The Next Hop IpAddress.")]
[ValidateNotNullOrEmpty]
public string IPAddress { get; set; }

[Parameter(Mandatory = true,
ParameterSetName = CortexParameterSetNames.ByVpnSiteLinkFqdn,
HelpMessage = "The Next Hop Fqdn.")]
[ValidateNotNullOrEmpty]
public string Fqdn { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Link Provider Name.")]
Expand Down Expand Up @@ -64,9 +70,30 @@ public override void Execute()
var vpnSiteLink = new PSVpnSiteLink
{
Name = this.Name,
IpAddress = this.IPAddress
};

if (ParameterSetName.Contains(CortexParameterSetNames.ByVpnSiteLinkIpAddress))
{
System.Net.IPAddress ipAddress;
if (string.IsNullOrWhiteSpace(this.IPAddress) ||
!System.Net.IPAddress.TryParse(this.IPAddress, out ipAddress))
{
throw new PSArgumentException(Properties.Resources.InvalidIPAddress);
}

vpnSiteLink.IpAddress = this.IPAddress;
vpnSiteLink.Fqdn = string.Empty;
}
else if (ParameterSetName.Contains(CortexParameterSetNames.ByVpnSiteLinkFqdn))
{
if (string.IsNullOrWhiteSpace(this.Fqdn))
{
throw new PSArgumentException(Properties.Resources.InvalidFqdn);
}
vpnSiteLink.Fqdn = this.Fqdn;
vpnSiteLink.IpAddress = string.Empty;
}

if (BGPAsn > 0 || !string.IsNullOrWhiteSpace(BGPPeeringAddress))
{
vpnSiteLink.BgpProperties = ValidateAndCreatePSVpnLinkBgpSettings(BGPAsn, BGPPeeringAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ namespace Microsoft.Azure.Commands.Network
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "LocalNetworkGateway", SupportsShouldProcess = true),OutputType(typeof(PSLocalNetworkGateway))]
public class NewAzureLocalNetworkGatewayCommand : LocalNetworkGatewayBaseCmdlet
{
public const string ByLocalNetworkGatewayIpAddress = "ByLocalNetworkGatewayIpAddress";
public const string ByLocalNetworkGatewayFqdn = "ByLocalNetworkGatewayFqdn";

[Alias("ResourceName")]
[Parameter(
Mandatory = true,
Expand All @@ -53,11 +56,19 @@ public class NewAzureLocalNetworkGatewayCommand : LocalNetworkGatewayBaseCmdlet
public virtual string Location { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "IP address of local network gateway.")]
Mandatory = false,
ValueFromPipelineByPropertyName = true,
ParameterSetName = ByLocalNetworkGatewayIpAddress,
HelpMessage = "IP address of local network gateway.")]
public string GatewayIpAddress { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
ParameterSetName = ByLocalNetworkGatewayFqdn,
HelpMessage = "FQDN of local network gateway.")]
public string Fqdn { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
Expand Down Expand Up @@ -122,7 +133,17 @@ private PSLocalNetworkGateway CreateLocalNetworkGateway()
localnetGateway.Location = this.Location;
localnetGateway.LocalNetworkAddressSpace = new PSAddressSpace();
localnetGateway.LocalNetworkAddressSpace.AddressPrefixes = this.AddressPrefix?.ToList();
localnetGateway.GatewayIpAddress = this.GatewayIpAddress;

if (ParameterSetName.Contains(ByLocalNetworkGatewayIpAddress))
{
localnetGateway.GatewayIpAddress = this.GatewayIpAddress;
localnetGateway.Fqdn = string.Empty;
}
else if (ParameterSetName.Contains(ByLocalNetworkGatewayFqdn))
{
localnetGateway.Fqdn = this.Fqdn;
localnetGateway.GatewayIpAddress = string.Empty;
}

if (this.PeerWeight < 0)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Network/Network/Models/Cortex/PSVpnSiteLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class PSVpnSiteLink : PSChildResource
[Ps1Xml(Label = "Ip Address", Target = ViewControl.Table)]
public string IpAddress { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public string Fqdn { get; set; }

public PSVpnLinkProviderProperties LinkProperties { get; set; }

public PSVpnLinkBgpSettings BgpProperties { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions src/Network/Network/Models/PSLocalNetworkGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class PSLocalNetworkGateway : PSTopLevelResource
[Ps1Xml(Target = ViewControl.Table)]
public string GatewayIpAddress { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public string Fqdn { get; set; }

public PSAddressSpace LocalNetworkAddressSpace { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
Expand Down
4 changes: 4 additions & 0 deletions src/Network/Network/Network.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,10 @@
<Label>GatewayIpAddress</Label>
<PropertyName>GatewayIpAddress</PropertyName>
</ListItem>
<ListItem>
<Label>Fqdn</Label>
<PropertyName>Fqdn</PropertyName>
</ListItem>
<ListItem>
<Label>LocalNetworkAddressSpace</Label>
<PropertyName>AddressSpaceText</PropertyName>
Expand Down
11 changes: 10 additions & 1 deletion src/Network/Network/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Network/Network/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@
<data name="InvalidFlowLogResourceId" xml:space="preserve">
<value>Provided flowLog resourceId is invalid.</value>
</data>
<data name="InvalidFqdn" xml:space="preserve">
<value>The Fqdn specified is invalid.</value>
</data>
<data name="ExpressRoutePrivatePeeringNotFound" xml:space="preserve">
<value>Private Peering needs to be configured on the Express Route Circuit.</value>
</data>
Expand Down
28 changes: 26 additions & 2 deletions src/Network/Network/help/New-AzLocalNetworkGateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ Creates a Local Network Gateway

## SYNTAX

### ByLocalNetworkGatewayIpAddress
```
New-AzLocalNetworkGateway -Name <String> -ResourceGroupName <String> -Location <String>
[-GatewayIpAddress <String>] [-AddressPrefix <String[]>] [-Asn <UInt32>] [-BgpPeeringAddress <String>]
[-PeerWeight <Int32>] [-Tag <Hashtable>] [-Force] [-AsJob] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

### ByLocalNetworkGatewayFqdn
```
New-AzLocalNetworkGateway -Name <String> -ResourceGroupName <String> -Location <String> [-Fqdn <String>]
[-AddressPrefix <String[]>] [-Asn <UInt32>] [-BgpPeeringAddress <String>] [-PeerWeight <Int32>]
[-Tag <Hashtable>] [-Force] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```

## DESCRIPTION
The Local Network Gateway is the object representing your VPN device On-Premises.
The **New-AzLocalNetworkGateway** cmdlet creates the object representing your on-prem gateway
Expand Down Expand Up @@ -123,10 +132,25 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Fqdn
FQDN of local network gateway.

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

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -GatewayIpAddress
```yaml
Type: System.String
Parameter Sets: (All)
Parameter Sets: ByLocalNetworkGatewayIpAddress
Aliases:

Required: False
Expand Down Expand Up @@ -238,7 +262,7 @@ Accept wildcard characters: False
```

### CommonParameters
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).
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).

## INPUTS

Expand Down
25 changes: 24 additions & 1 deletion src/Network/Network/help/New-AzVpnSiteLink.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ Creates an Azure VpnSiteLink object.

## SYNTAX

### ByVpnSiteLinkIpAddress
```
New-AzVpnSiteLink -Name <String> -IPAddress <String> [-LinkProviderName <String>] [-LinkSpeedInMbps <UInt32>]
[-BGPAsn <UInt32>] [-BGPPeeringAddress <String>] [-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
```

### ByVpnSiteLinkFqdn
```
New-AzVpnSiteLink -Name <String> -Fqdn <String> [-LinkProviderName <String>] [-LinkSpeedInMbps <UInt32>]
[-BGPAsn <UInt32>] [-BGPPeeringAddress <String>] [-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
```

## DESCRIPTION
Creates an Azure VpnSiteLink object.

Expand Down Expand Up @@ -84,12 +92,27 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Fqdn
The Next Hop Fqdn.

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

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

### -IPAddress
The Next Hop IpAddress.

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

Required: True
Expand Down