Skip to content

Commit 44e5777

Browse files
3vilbuff3rNeel Bhavsar
andauthored
[Network] Add New-AzExpressRoutePortLOA cmdlet (#12465)
* Add New-AzExpressRoutePortLOA cmdlet. * Add new cmdlet tests. * Remove unused variable. * Added help md files. * Supress static analysis warnings. * Change csproj for the SDK with LOA code. This swagger changes are merged into network-june-release * Added details in changelog * Revert "Change csproj for the SDK with LOA code." This reverts commit 763fb8a. * Added null validation for invalid ResourceId * Update SDK version to the latest * Add Error Suppresion * Change csproj * Trigger new build. * Fix merge conflict markers * Trigger CI build. Co-authored-by: Neel Bhavsar <[email protected]>
1 parent 865af59 commit 44e5777

File tree

7 files changed

+378
-1
lines changed

7 files changed

+378
-1
lines changed

src/Network/Network.Test/ScenarioTests/ExpressRoutePortTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,14 @@ public void TestExpressRoutePortIdentityCRUD()
4040
{
4141
TestRunner.RunTestScript("Test-ExpressRoutePortIdentityCRUD");
4242
}
43+
44+
[Fact(Skip = "Nfv-RP rollout in progress")]
45+
[Trait(Category.AcceptanceType, Category.CheckIn)]
46+
[Trait(Category.Owner, NrpTeamAlias.pgtm)]
47+
public void TestExpressRoutePortGenerateLOA()
48+
{
49+
TestRunner.RunTestScript("Test-ExpressRoutePortGenerateLOA");
50+
}
51+
4352
}
4453
}

src/Network/Network.Test/ScenarioTests/ExpressRoutePortTests.ps1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,44 @@ function Test-ExpressRoutePortIdentityCRUD
187187
}
188188
}
189189

190+
<#
191+
.SYNOPSIS
192+
Test creating new ExpressRoutePort
193+
#>
194+
function Test-ExpressRoutePortGenerateLOA
195+
{
196+
# Setup
197+
$rgname = Get-ResourceGroupName
198+
$rname = Get-ResourceName
199+
$resourceTypeParent = "Microsoft.Network/expressRoutePorts"
200+
201+
# Only available peering location and location for now.
202+
$rglocation = "eastus2euap"
203+
$location = "eastus2euap"
204+
$peeringLocation = "Good Grief"
205+
$encapsulation = "QinQ"
206+
$bandwidthInGbps = 25
207+
$customerName = "contoso"
208+
209+
try
210+
{
211+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation
212+
213+
# Create ExpressRoutePort
214+
$vExpressRoutePort = New-AzExpressRoutePort -ResourceGroupName $rgname -Name $rname -Location $location -PeeringLocation $peeringLocation -Encapsulation $encapsulation -BandwidthInGbps $bandwidthInGbps
215+
Assert-NotNull $vExpressRoutePort
216+
Assert-True { Check-CmdletReturnType "New-AzExpressRoutePort" $vExpressRoutePort }
217+
Assert-NotNull $vExpressRoutePort.Links
218+
Assert-True { $vExpressRoutePort.Links.Count -eq 2 }
219+
Assert-AreEqual $rname $vExpressRoutePort.Name
220+
221+
$loa = New-AzExpressRoutePortLOA -ResourceGroupName $rgname -PortName $rname -CustomerName $customerName -PassThru
222+
Assert-True { $loa -eq $true }
223+
}
224+
finally
225+
{
226+
# Cleanup
227+
Clean-ResourceGroup $rgname
228+
}
229+
}
190230

src/Network/Network/Az.Network.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
502502
'Get-AzNetworkVirtualApplianceSku',
503503
'New-AzVirtualApplianceSkuProperty',
504504
'New-AzCustomIpPrefix', 'Update-AzCustomIpPrefix',
505-
'Get-AzCustomIpPrefix', 'Remove-AzCustomIpPrefix'
505+
'Get-AzCustomIpPrefix', 'Remove-AzCustomIpPrefix',
506+
'New-AzExpressRoutePortLOA'
506507

507508

508509
# Variables to export from this module

src/Network/Network/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
--->
2020

2121
## Upcoming Release
22+
* Added new cmdlet for Azure Express Route Port
23+
- `New-AzExpressRoutePortLOA`
2224
* [Breaking Change] Updated below cmdlets to align resource virtual router and virtual hub
2325
- `New-AzVirtualRouter`:
2426
- Added -HostedSubnet parameter to support IP configuration child resource
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
16+
using Microsoft.Azure.Commands.Network.Models;
17+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
18+
using Microsoft.Azure.Management.Network;
19+
using System;
20+
using System.Management.Automation;
21+
using System.IO;
22+
using Microsoft.Azure.Management.Network.Models;
23+
using System.ComponentModel;
24+
using System.Security.Cryptography;
25+
26+
namespace Microsoft.Azure.Commands.Network
27+
{
28+
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ExpressRoutePortLOA", SupportsShouldProcess = false, DefaultParameterSetName = ResourceNameParameterSet), OutputType(typeof(bool))]
29+
public partial class NewAzureRmExpressRoutePortLOA : NetworkBaseCmdlet
30+
{
31+
private const string ResourceIdParameterSet = "ResourceIdParameterSet";
32+
private const string ResourceNameParameterSet = "ResourceNameParameterSet";
33+
private const string ResourceObjectParameterSet = "ResourceObjectParameterSet";
34+
private const string DefaultFileName = "LOA.pdf";
35+
36+
[Parameter(
37+
ParameterSetName = ResourceNameParameterSet,
38+
Mandatory = true,
39+
HelpMessage = "The express route port name.",
40+
ValueFromPipelineByPropertyName = false)]
41+
[ValidateNotNullOrEmpty]
42+
public string PortName { get; set; }
43+
44+
[Parameter(
45+
ParameterSetName = ResourceNameParameterSet,
46+
Mandatory = true,
47+
HelpMessage = "The resource group name of the express route port.",
48+
ValueFromPipelineByPropertyName = false)]
49+
[ResourceGroupCompleter]
50+
[ValidateNotNullOrEmpty]
51+
public string ResourceGroupName { get; set; }
52+
53+
[Parameter(
54+
ParameterSetName = ResourceObjectParameterSet,
55+
Mandatory = true,
56+
HelpMessage = "The express route port resource.",
57+
ValueFromPipelineByPropertyName = false)]
58+
[ValidateNotNullOrEmpty]
59+
public PSExpressRoutePort ExpressRoutePort { get; set; }
60+
61+
[Alias("ResourceId")]
62+
[Parameter(
63+
ParameterSetName = ResourceIdParameterSet,
64+
Mandatory = true,
65+
HelpMessage = "ResourceId of the express route port.",
66+
ValueFromPipelineByPropertyName = true)]
67+
[ValidateNotNullOrEmpty]
68+
public string Id { get; set; }
69+
70+
[Alias("Name")]
71+
[Parameter(
72+
Mandatory = true,
73+
HelpMessage = "The customer name to whom this Express Route Port is assigned to.",
74+
ValueFromPipelineByPropertyName = false)]
75+
[ValidateNotNullOrEmpty]
76+
public string CustomerName { get; set; }
77+
78+
[Parameter(
79+
Mandatory = false,
80+
HelpMessage = "The output filepath to store the Letter of Authorization to.",
81+
ValueFromPipelineByPropertyName = false)]
82+
public string Destination { get; set; }
83+
84+
[Parameter(Mandatory = false)]
85+
public SwitchParameter PassThru { get; set; }
86+
87+
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
88+
public SwitchParameter AsJob { get; set; }
89+
90+
public override void Execute()
91+
{
92+
base.Execute();
93+
94+
if (string.Equals(this.ParameterSetName, ResourceObjectParameterSet, StringComparison.OrdinalIgnoreCase))
95+
{
96+
ResourceGroupName = ExpressRoutePort.ResourceGroupName;
97+
PortName = ExpressRoutePort.Name;
98+
}
99+
if (string.Equals(this.ParameterSetName, ResourceIdParameterSet, StringComparison.OrdinalIgnoreCase))
100+
{
101+
var resourceInfo = new ResourceIdentifier(Id);
102+
ResourceGroupName = resourceInfo.ResourceGroupName;
103+
PortName = resourceInfo.ResourceName;
104+
}
105+
if(this.ResourceGroupName == null || this.PortName == null){
106+
Console.WriteLine("Empty resource group or port name.");
107+
return;
108+
}
109+
GenerateExpressRoutePortsLOARequest generateExpressRoutePortsLOARequest = new GenerateExpressRoutePortsLOARequest(CustomerName);
110+
var response = this.NetworkClient.NetworkManagementClient.ExpressRoutePorts.GenerateLOA(this.ResourceGroupName, this.PortName, generateExpressRoutePortsLOARequest);
111+
var decodedDocument = Convert.FromBase64String(response.EncodedContent);
112+
if (String.IsNullOrEmpty(Destination))
113+
{
114+
Destination = DefaultFileName;
115+
}
116+
if (!(Path.IsPathRooted(Destination)))
117+
{
118+
Destination = Directory.GetCurrentDirectory() + "\\" + Destination;
119+
}
120+
File.WriteAllBytes(Destination, decodedDocument);
121+
Console.WriteLine("Written Letter of Authorization To: " + Destination);
122+
if (PassThru)
123+
{
124+
WriteObject(true);
125+
}
126+
}
127+
}
128+
}

0 commit comments

Comments
 (0)