Skip to content

[Network] Add New-AzExpressRoutePortLOA cmdlet #12465

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 18 commits into from
Sep 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,14 @@ public void TestExpressRoutePortIdentityCRUD()
{
TestRunner.RunTestScript("Test-ExpressRoutePortIdentityCRUD");
}

[Fact(Skip = "Nfv-RP rollout in progress")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.pgtm)]
public void TestExpressRoutePortGenerateLOA()
{
TestRunner.RunTestScript("Test-ExpressRoutePortGenerateLOA");
}

}
}
40 changes: 40 additions & 0 deletions src/Network/Network.Test/ScenarioTests/ExpressRoutePortTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,44 @@ function Test-ExpressRoutePortIdentityCRUD
}
}

<#
.SYNOPSIS
Test creating new ExpressRoutePort
#>
function Test-ExpressRoutePortGenerateLOA
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$resourceTypeParent = "Microsoft.Network/expressRoutePorts"

# Only available peering location and location for now.
$rglocation = "eastus2euap"
$location = "eastus2euap"
$peeringLocation = "Good Grief"
$encapsulation = "QinQ"
$bandwidthInGbps = 25
$customerName = "contoso"

try
{
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation

# Create ExpressRoutePort
$vExpressRoutePort = New-AzExpressRoutePort -ResourceGroupName $rgname -Name $rname -Location $location -PeeringLocation $peeringLocation -Encapsulation $encapsulation -BandwidthInGbps $bandwidthInGbps
Assert-NotNull $vExpressRoutePort
Assert-True { Check-CmdletReturnType "New-AzExpressRoutePort" $vExpressRoutePort }
Assert-NotNull $vExpressRoutePort.Links
Assert-True { $vExpressRoutePort.Links.Count -eq 2 }
Assert-AreEqual $rname $vExpressRoutePort.Name

$loa = New-AzExpressRoutePortLOA -ResourceGroupName $rgname -PortName $rname -CustomerName $customerName -PassThru
Assert-True { $loa -eq $true }
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

3 changes: 2 additions & 1 deletion src/Network/Network/Az.Network.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
'Get-AzNetworkVirtualApplianceSku',
'New-AzVirtualApplianceSkuProperty',
'New-AzCustomIpPrefix', 'Update-AzCustomIpPrefix',
'Get-AzCustomIpPrefix', 'Remove-AzCustomIpPrefix'
'Get-AzCustomIpPrefix', 'Remove-AzCustomIpPrefix',
'New-AzExpressRoutePortLOA'


# Variables to export from this module
Expand Down
2 changes: 2 additions & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
--->

## Upcoming Release
* Added new cmdlet for Azure Express Route Port
- `New-AzExpressRoutePortLOA`
* [Breaking Change] Updated below cmdlets to align resource virtual router and virtual hub
- `New-AzVirtualRouter`:
- Added -HostedSubnet parameter to support IP configuration child resource
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// 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.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.Network.Models;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.Management.Network;
using System;
using System.Management.Automation;
using System.IO;
using Microsoft.Azure.Management.Network.Models;
using System.ComponentModel;
using System.Security.Cryptography;

namespace Microsoft.Azure.Commands.Network
{
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ExpressRoutePortLOA", SupportsShouldProcess = false, DefaultParameterSetName = ResourceNameParameterSet), OutputType(typeof(bool))]
public partial class NewAzureRmExpressRoutePortLOA : NetworkBaseCmdlet
{
private const string ResourceIdParameterSet = "ResourceIdParameterSet";
private const string ResourceNameParameterSet = "ResourceNameParameterSet";
private const string ResourceObjectParameterSet = "ResourceObjectParameterSet";
private const string DefaultFileName = "LOA.pdf";

[Parameter(
ParameterSetName = ResourceNameParameterSet,
Mandatory = true,
HelpMessage = "The express route port name.",
ValueFromPipelineByPropertyName = false)]
[ValidateNotNullOrEmpty]
public string PortName { get; set; }

[Parameter(
ParameterSetName = ResourceNameParameterSet,
Mandatory = true,
HelpMessage = "The resource group name of the express route port.",
ValueFromPipelineByPropertyName = false)]
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Parameter(
ParameterSetName = ResourceObjectParameterSet,
Mandatory = true,
HelpMessage = "The express route port resource.",
ValueFromPipelineByPropertyName = false)]
[ValidateNotNullOrEmpty]
public PSExpressRoutePort ExpressRoutePort { get; set; }

[Alias("ResourceId")]
[Parameter(
ParameterSetName = ResourceIdParameterSet,
Mandatory = true,
HelpMessage = "ResourceId of the express route port.",
ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public string Id { get; set; }

[Alias("Name")]
[Parameter(
Mandatory = true,
HelpMessage = "The customer name to whom this Express Route Port is assigned to.",
ValueFromPipelineByPropertyName = false)]
[ValidateNotNullOrEmpty]
public string CustomerName { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "The output filepath to store the Letter of Authorization to.",
ValueFromPipelineByPropertyName = false)]
public string Destination { get; set; }

[Parameter(Mandatory = false)]
public SwitchParameter PassThru { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

public override void Execute()
{
base.Execute();

if (string.Equals(this.ParameterSetName, ResourceObjectParameterSet, StringComparison.OrdinalIgnoreCase))
{
ResourceGroupName = ExpressRoutePort.ResourceGroupName;
PortName = ExpressRoutePort.Name;
}
if (string.Equals(this.ParameterSetName, ResourceIdParameterSet, StringComparison.OrdinalIgnoreCase))
{
var resourceInfo = new ResourceIdentifier(Id);
ResourceGroupName = resourceInfo.ResourceGroupName;
PortName = resourceInfo.ResourceName;
}
if(this.ResourceGroupName == null || this.PortName == null){
Console.WriteLine("Empty resource group or port name.");
return;
}
GenerateExpressRoutePortsLOARequest generateExpressRoutePortsLOARequest = new GenerateExpressRoutePortsLOARequest(CustomerName);
var response = this.NetworkClient.NetworkManagementClient.ExpressRoutePorts.GenerateLOA(this.ResourceGroupName, this.PortName, generateExpressRoutePortsLOARequest);
var decodedDocument = Convert.FromBase64String(response.EncodedContent);
if (String.IsNullOrEmpty(Destination))
{
Destination = DefaultFileName;
}
if (!(Path.IsPathRooted(Destination)))
{
Destination = Directory.GetCurrentDirectory() + "\\" + Destination;
}
File.WriteAllBytes(Destination, decodedDocument);
Console.WriteLine("Written Letter of Authorization To: " + Destination);
if (PassThru)
{
WriteObject(true);
}
}
}
}
Loading