diff --git a/src/Network/Network.Test/ScenarioTests/NetworkInterfaceTests.cs b/src/Network/Network.Test/ScenarioTests/NetworkInterfaceTests.cs index ed277c7cfd9d..af0847e543c9 100644 --- a/src/Network/Network.Test/ScenarioTests/NetworkInterfaceTests.cs +++ b/src/Network/Network.Test/ScenarioTests/NetworkInterfaceTests.cs @@ -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"); + } } } diff --git a/src/Network/Network.Test/ScenarioTests/NetworkInterfaceTests.ps1 b/src/Network/Network.Test/ScenarioTests/NetworkInterfaceTests.ps1 index f54825e67b66..87314d0867a3 100644 --- a/src/Network/Network.Test/ScenarioTests/NetworkInterfaceTests.ps1 +++ b/src/Network/Network.Test/ScenarioTests/NetworkInterfaceTests.ps1 @@ -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 + } +} diff --git a/src/Network/Network/Models/PSExtendedLocation.cs b/src/Network/Network/Models/PSExtendedLocation.cs new file mode 100644 index 000000000000..47300c7d4d25 --- /dev/null +++ b/src/Network/Network/Models/PSExtendedLocation.cs @@ -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; } + } +} diff --git a/src/Network/Network/Models/PSNetworkInterface.cs b/src/Network/Network/Models/PSNetworkInterface.cs index f51da0dfe175..1192f672a9eb 100644 --- a/src/Network/Network/Models/PSNetworkInterface.cs +++ b/src/Network/Network/Models/PSNetworkInterface.cs @@ -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); diff --git a/src/Network/Network/NetworkInterface/NewAzureNetworkInterfaceCommand.cs b/src/Network/Network/NetworkInterface/NewAzureNetworkInterfaceCommand.cs index c820141f0f7e..31710d520d66 100644 --- a/src/Network/Network/NetworkInterface/NewAzureNetworkInterfaceCommand.cs +++ b/src/Network/Network/NetworkInterface/NewAzureNetworkInterfaceCommand.cs @@ -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")] @@ -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(networkInterface); this.NullifyApplicationSecurityGroupIfAbsent(networkInterfaceModel);