Skip to content

Commit

Permalink
Add edge zone parameter to create network interface cmdlet (#15184)
Browse files Browse the repository at this point in the history
* Add edge zone parameter to create network interface cmdlet

* Regenerate new network interface help file

Co-authored-by: Will Ehrich <william.ehrich@microsoft.com>
  • Loading branch information
wdehrich and Will Ehrich authored Jun 10, 2021
1 parent 6583cb9 commit a6354aa
Show file tree
Hide file tree
Showing 7 changed files with 319 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public void TestNetworkInterfaceVmss()

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.sdnnrp)]
public void TestNetworkInterfaceInEdgeZone()
{
TestRunner.RunTestScript("Test-NetworkInterfaceInEdgeZone");
Expand Down
44 changes: 24 additions & 20 deletions src/Network/Network.Test/ScenarioTests/NetworkInterfaceTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1154,35 +1154,39 @@ function Test-NetworkInterfaceVmss

<#
.SYNOPSIS
Test that network interface can be put in an edge zone.
Test that network interface can be put in an edge zone. Subscriptions need to be explicitly whitelisted for access to edge zones.
#>
function Test-NetworkInterfaceInEdgeZone
{
$ResourceGroup = Get-ResourceGroupName;
$LocationName = "westus";
$EdgeZone = "microsoftlosangeles1";
$VMName = "MyVM";
$resourceGroup = Get-ResourceGroupName
$locationName = "westus"
$edgeZone = "microsoftlosangeles1"

try
{
New-AzResourceGroup -Name $ResourceGroup -Location $LocationName -Force;

$NetworkName = "MyNet";
$NICName = "MyNIC";
$SubnetName = "MySubnet";
$SubnetAddressPrefix = "10.0.0.0/24";
$VnetAddressPrefix = "10.0.0.0/16";

$SingleSubnet = New-AzVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix $SubnetAddressPrefix;
$Vnet = New-AzVirtualNetwork -Name $NetworkName -ResourceGroupName $ResourceGroup -Location $LocationName -EdgeZone $EdgeZone -AddressPrefix $VnetAddressPrefix -Subnet $SingleSubnet;
New-AzNetworkInterface -Name $NICName -ResourceGroupName $ResourceGroup -Location $LocationName -EdgeZone $EdgeZone -SubnetId $Vnet.Subnets[0].Id;

$NIC = Get-AzNetworkInterface -Name $NICName -ResourceGroupName $ResourceGroup
Assert-AreEqual $NIC.ExtendedLocation.Name $EdgeZone
New-AzResourceGroup -Name $resourceGroup -Location $locationName -Force

$networkName = "MyNet"
$nicName = "MyNIC"
$subnetName = "MySubnet"
$subnetAddressPrefix = "10.0.0.0/24"
$vnetAddressPrefix = "10.0.0.0/16"

$singleSubnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix $subnetAddressPrefix
$vnet = New-AzVirtualNetwork -Name $networkName -ResourceGroupName $resourceGroup -Location $locationName -EdgeZone $edgeZone -AddressPrefix $vnetAddressPrefix -Subnet $singleSubnet
New-AzNetworkInterface -Name $nicName -ResourceGroupName $resourceGroup -Location $locationName -EdgeZone $edgeZone -SubnetId $vnet.Subnets[0].Id

$nic = Get-AzNetworkInterface -Name $nicName -ResourceGroupName $resourceGroup
Assert-AreEqual $nic.ExtendedLocation.Name $edgeZone
Assert-AreEqual $nic.ExtendedLocation.Type "EdgeZone"
}
catch [Microsoft.Azure.Commands.Network.Common.NetworkCloudException]
{
Assert-NotNull { $_.Exception.Message -match 'Resource type .* does not support edge zone .* in location .* The supported edge zones are .*' }
}
finally
{
# Cleanup
Clean-ResourceGroup $ResourceGroup;
Clean-ResourceGroup $resourceGroup
}
}

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/Network/Network/Models/PSNetworkInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace Microsoft.Azure.Commands.Network.Models
{
using Microsoft.Azure.Management.Internal.Network.Common;
using Microsoft.Azure.Management.Network.Models;
using Newtonsoft.Json;
using System.Collections.Generic;
using WindowsAzure.Commands.Common.Attributes;
Expand All @@ -25,6 +24,7 @@ public class PSNetworkInterface : PSTopLevelResource, INetworkInterfaceReference
public PSResourceId VirtualMachine { get; set; }

public PSExtendedLocation ExtendedLocation { get; set; }

public List<PSNetworkInterfaceIPConfiguration> IpConfigurations { get; set; }

public List<PSNetworkInterfaceTapConfiguration> TapConfigurations { get; set; }
Expand Down Expand Up @@ -88,6 +88,12 @@ public string PrivateEndpointText
get { return JsonConvert.SerializeObject(PrivateEndpoint, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}

[JsonIgnore]
public string ExtendedLocationText
{
get { return JsonConvert.SerializeObject(ExtendedLocation, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}

public bool ShouldSerializeIpConfigurations()
{
return !string.IsNullOrEmpty(this.Name);
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 @@ -1822,6 +1822,10 @@
<Label>MacAddress</Label>
<PropertyName>MacAddress</PropertyName>
</ListItem>
<ListItem>
<Label>ExtendedLocation</Label>
<PropertyName>ExtendedLocationText</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public class NewAzureNetworkInterfaceCommand : NetworkInterfaceBaseCmdlet

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true)]
ValueFromPipelineByPropertyName = true,
HelpMessage = "The edge zone of the network interface")]
public string EdgeZone { get; set; }

[Parameter(
Expand Down Expand Up @@ -275,7 +276,7 @@ private PSNetworkInterface CreateNetworkInterface()
networkInterface.Name = this.Name;

networkInterface.Location = this.Location;
if (this.EdgeZone != null)
if (!string.IsNullOrEmpty(EdgeZone))
{
networkInterface.ExtendedLocation = new PSExtendedLocation(this.EdgeZone);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Network/Network/help/New-AzNetworkInterface.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Accept wildcard characters: False
```
### -EdgeZone
{{ Fill EdgeZone Description }}
The edge zone of the network interface
```yaml
Type: System.String
Expand Down

0 comments on commit a6354aa

Please sign in to comment.