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

Add edge zone parameter to create network interface cmdlet #14213

Closed
wants to merge 20 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,13 @@ public void TestNetworkInterfaceVmss()
{
TestRunner.RunTestScript("Test-NetworkInterfaceVmss");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.sdnnrp)]
public void TestNetworkInterfaceEdgeZone()
{
TestRunner.RunTestScript("Test-NetworkInterfaceEdgeZone");
}
}
}
63 changes: 63 additions & 0 deletions src/Network/Network.Test/ScenarioTests/NetworkInterfaceTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1088,3 +1088,66 @@ function Test-NetworkInterfaceVmss
Clean-ResourceGroup $rgname;
}
}

function Test-NetworkInterfaceEdgeZone
{
# Setup
$rgname = Get-ResourceGroupName
$vnetName = Get-ResourceName
$subnetName = Get-ResourceName
$publicIpName = Get-ResourceName
$nicName = Get-ResourceName
$domainNameLabel = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$resourceTypeParent = "Microsoft.Network/networkInterfaces"
$location = Get-ProviderLocation $resourceTypeParent

try
{
# Create the resource group
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
$resourceGroupRetrieved = Get-AzResourceGroup -ResourceGroupName $rgname
Assert-NotNull $resourceGroupRetrieved

# Create the Virtual Network
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
$retrievedVnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
Assert-NotNull $retrievedVnet
$retrievedSubnet = Get-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet
Assert-NotNull $retrievedSubnet

# Create the publicip
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel
$publicIpRetrieved = Get-AzPublicIpAddress -Name $publicIpName -ResourceGroupName $rgname
Assert-NotNull $publicIpRetrieved

try
{
# Create NetworkInterface
$job = New-AzNetworkInterface -Name $nicName -ResourceGroupName $rgname -Location $location -Subnet $vnet.Subnets[0] -PublicIpAddress $publicip -AsJob -EdgeZone "EdgeZone0"
$job | Wait-Job

$expectedNic = Get-AzNetworkInterface -Name $nicName -ResourceGroupName $rgname

# Delete NetworkInterface
$job = Remove-AzNetworkInterface -ResourceGroupName $rgname -name $nicName -PassThru -Force -AsJob
$job | Wait-Job
$delete = $job | Receive-Job
Assert-AreEqual true $delete
}
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 .*' }
}


$list = Get-AzNetworkInterface -ResourceGroupName $rgname
Assert-AreEqual 0 @($list).Count
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}
37 changes: 37 additions & 0 deletions src/Network/Network/Models/PSExtendedLocation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Copyright (c) Microsoft. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

namespace Microsoft.Azure.Commands.Network.Models
{
using Microsoft.Azure.Management.Network.Models;

public class PSExtendedLocation
{
public PSExtendedLocation()
{ }

public PSExtendedLocation(string EdgeZone)
{
var extendedLocation = new ExtendedLocation(EdgeZone);

this.Name = extendedLocation.Name;
this.Type = ExtendedLocation.Type;
}

public string Name { get; set; }

public string Type { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/Network/Network/Models/PSNetworkInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public string PrivateEndpointText
get { return JsonConvert.SerializeObject(PrivateEndpoint, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}

public PSExtendedLocation ExtendedLocation { get; set; }

public bool ShouldSerializeIpConfigurations()
{
return !string.IsNullOrEmpty(this.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ public class NewAzureNetworkInterfaceCommand : NetworkInterfaceBaseCmdlet
HelpMessage = "A hashtable which represents resource tags.")]
public Hashtable Tag { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Edge zone of Network Interface.")]
[ValidateNotNullOrEmpty]
public string EdgeZone { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Do not ask for confirmation if you want to overwrite a resource")]
Expand Down Expand Up @@ -428,6 +435,11 @@ private PSNetworkInterface CreateNetworkInterface()
networkInterface.NetworkSecurityGroup.Id = this.NetworkSecurityGroupId;
}

if (!string.IsNullOrEmpty(this.EdgeZone))
{
networkInterface.ExtendedLocation = new PSExtendedLocation(this.EdgeZone);
}

var networkInterfaceModel = NetworkResourceManagerProfile.Mapper.Map<MNM.NetworkInterface>(networkInterface);

this.NullifyApplicationSecurityGroupIfAbsent(networkInterfaceModel);
Expand Down