Skip to content

Commit 6d3a197

Browse files
authored
Merge pull request #10273 from naveenchekuri/network-october
Add CRUD for VirtualRouter top level resource and VirtualRouterPeer
2 parents f5bbf3d + 47a35e2 commit 6d3a197

27 files changed

+10392
-2
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.Network.Test.ScenarioTests;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Xunit;
18+
19+
namespace Commands.Network.Test.ScenarioTests
20+
{
21+
public class VirtualRouterTests : NetworkTestRunner
22+
{
23+
public VirtualRouterTests(Xunit.Abstractions.ITestOutputHelper output)
24+
: base(output)
25+
{
26+
}
27+
28+
[Fact]
29+
[Trait(Category.AcceptanceType, Category.CheckIn)]
30+
[Trait(Category.Owner, NrpTeamAlias.pgtm)]
31+
public void TestVirtualRouterCRUDMinimalParameters()
32+
{
33+
TestRunner.RunTestScript(string.Format("Test-VirtualRouterCRUD"));
34+
}
35+
}
36+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
function Check-CmdletReturnType
16+
{
17+
param($cmdletName, $cmdletReturn)
18+
19+
$cmdletData = Get-Command $cmdletName
20+
Assert-NotNull $cmdletData
21+
[array]$cmdletReturnTypes = $cmdletData.OutputType.Name | Foreach-Object { return ($_ -replace "Microsoft.Azure.Commands.Network.Models.","") }
22+
[array]$cmdletReturnTypes = $cmdletReturnTypes | Foreach-Object { return ($_ -replace "System.","") }
23+
$realReturnType = $cmdletReturn.GetType().Name -replace "Microsoft.Azure.Commands.Network.Models.",""
24+
return $cmdletReturnTypes -contains $realReturnType
25+
}
26+
27+
<#
28+
.SYNOPSIS
29+
Test creating new VirtualRouter
30+
#>
31+
function Test-VirtualRouterCRUD
32+
{
33+
# Setup
34+
$rgname = Get-ResourceGroupName
35+
$rname = Get-ResourceName
36+
$domainNameLabel = Get-ResourceName
37+
$vnetName = Get-ResourceName
38+
$publicIpName = Get-ResourceName
39+
$vnetGatewayConfigName = Get-ResourceName
40+
$rglocation = Get-ProviderLocation ResourceManagement "southcentralus"
41+
$resourceTypeParent = "Microsoft.Network/virtualNetworkGateways"
42+
$location = Get-ProviderLocation $resourceTypeParent "southcentralus"
43+
$virtualRouterName = Get-ResourceName
44+
45+
try
46+
{
47+
# Create the resource group
48+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
49+
50+
51+
# Create the Virtual Network
52+
$subnet = New-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix 10.0.0.0/24
53+
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
54+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
55+
$subnet = Get-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet
56+
57+
# Create the publicip
58+
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel
59+
60+
# Create & Get virtualnetworkgateway
61+
$vnetIpConfig = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet
62+
63+
$actual = New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType ExpressRoute -GatewaySku HighPerformance -VpnType RouteBased -VpnGatewayGeneration None -Force
64+
$expected = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
65+
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
66+
Assert-AreEqual $expected.Name $actual.Name
67+
Assert-AreEqual "ExpressRoute" $expected.GatewayType
68+
Assert-AreEqual "None" $expected.VpnGatewayGeneration
69+
70+
# Create Virtual Router
71+
$actualvr = New-AzVirtualRouter -ResourceGroupName $rgname -location $location -Name $virtualRouterName -HostedGateway $expected
72+
$expectedvr = Get-AzVirtualRouter -ResourceGroupName $rgname -RouterName $virtualRouterName
73+
Assert-AreEqual $expectedvr.ResourceGroupName $actualvr.ResourceGroupName
74+
Assert-AreEqual $expectedvr.Name $actualvr.Name
75+
76+
# List Virtual Routers
77+
$list = Get-AzVirtualRouter -ResourceGroupName $rgname
78+
Assert-AreEqual 1 @($list).Count
79+
Assert-AreEqual $list[0].ResourceGroupName $actualvr.ResourceGroupName
80+
Assert-AreEqual $list[0].Name $actualvr.Name
81+
Assert-AreEqual $list[0].Location $actualvr.Location
82+
83+
# Delete VR
84+
$deletevR = Remove-AzVirtualRouter -ResourceGroupName $rgname -RouterName $virtualRouterName -PassThru -Force
85+
Assert-AreEqual true $deletevR
86+
87+
# Delete virtualNetworkGateway
88+
$delete = Remove-AzVirtualNetworkGateway -ResourceGroupName $actual.ResourceGroupName -name $rname -PassThru -Force
89+
Assert-AreEqual true $delete
90+
91+
$list = Get-AzVirtualRouter -ResourceGroupName $rgname
92+
Assert-AreEqual 0 @($list).Count
93+
}
94+
finally
95+
{
96+
# Cleanup
97+
Clean-ResourceGroup $rgname
98+
}
99+
}
100+

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.VirtualRouterTests/TestVirtualRouterCRUDMinimalParameters.json

Lines changed: 7632 additions & 0 deletions
Large diffs are not rendered by default.

src/Network/Network/Az.Network.psd1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
420420
'Start-AzVirtualNetworkGatewayPacketCapture',
421421
'Stop-AzVirtualNetworkGatewayPacketCapture',
422422
'Start-AzVirtualNetworkGatewayConnectionPacketCapture',
423-
'Stop-AzVirtualNetworkGatewayConnectionPacketCapture'
423+
'Stop-AzVirtualNetworkGatewayConnectionPacketCapture',
424+
'New-AzVirtualRouter','Remove-AzVirtualRouter','Get-AzVirtualRouter',
425+
'Add-AzVirtualRouterPeer','Update-AzVirtualRouterPeer','Remove-AzVirtualRouterPeer', 'Get-AzVirtualRouterPeer'
424426

425427
# Variables to export from this module
426428
# VariablesToExport = @()

src/Network/Network/Common/NetworkResourceManagerProfile.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,37 @@ private static void MapSecurityRuleManagementToCommand<MnmType, CnmType>(MnmType
8989
}
9090
}
9191

92+
public class VirtualRouterConverter : ITypeConverter<MNM.VirtualRouter, CNM.PSVirtualRouter>
93+
{
94+
public CNM.PSVirtualRouter Convert(MNM.VirtualRouter source, CNM.PSVirtualRouter destination, ResolutionContext context)
95+
{
96+
var router = new CNM.PSVirtualRouter()
97+
{
98+
Id = source.Id,
99+
Name = source.Name,
100+
Etag = source.Etag,
101+
Location = source.Location,
102+
Type = source.Type,
103+
ProvisioningState = source.ProvisioningState,
104+
VirtualRouterAsn = (uint) source.VirtualRouterAsn
105+
};
106+
if (source.HostedGateway != null)
107+
{
108+
router.HostedGateway = new CNM.PSResourceId()
109+
{
110+
Id = source.HostedGateway.Id
111+
};
112+
}
113+
if (source.VirtualRouterIps != null)
114+
{
115+
router.VirtualRouterIps = source.VirtualRouterIps.ToList<string>();
116+
}
117+
118+
router.Peerings = new List<CNM.PSVirtualRouterPeer>();
119+
return router;
120+
}
121+
}
122+
92123
private static void MapSecurityRuleCommandToManagement<CnmType, MnmType>(CnmType cnmObj, MnmType mnmObj)
93124
{
94125
/*
@@ -1043,6 +1074,15 @@ private static void Initialize()
10431074
// MNM to CNM
10441075
cfg.CreateMap<MNM.BastionHost, CNM.PSBastion>();
10451076
cfg.CreateMap<MNM.BastionHostIPConfiguration, CNM.PSBastionIPConfiguration>();
1077+
1078+
// Virtual Router
1079+
// CNM to MNM
1080+
cfg.CreateMap<CNM.PSVirtualRouter, MNM.VirtualRouter>();
1081+
cfg.CreateMap<CNM.PSVirtualRouterPeer, MNM.VirtualRouterPeering>();
1082+
1083+
// MNM to CNM
1084+
cfg.CreateMap<MNM.VirtualRouter, CNM.PSVirtualRouter>().ConvertUsing(new VirtualRouterConverter());
1085+
cfg.CreateMap<MNM.VirtualRouterPeering, CNM.PSVirtualRouterPeer>();
10461086
});
10471087

10481088
_mapper = config.CreateMapper();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) Microsoft and contributors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
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+
//
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using Microsoft.Azure.Management.Network.Models;
16+
using Microsoft.WindowsAzure.Commands.Common.Attributes;
17+
using Newtonsoft.Json;
18+
using System.Collections.Generic;
19+
20+
namespace Microsoft.Azure.Commands.Network.Models
21+
{
22+
public partial class PSVirtualRouter : PSTopLevelResource
23+
{
24+
[Ps1Xml(Target = ViewControl.Table)]
25+
public PSResourceId HostedGateway { get; set; }
26+
[Ps1Xml(Target = ViewControl.Table)]
27+
public uint VirtualRouterAsn { get; set; }
28+
[Ps1Xml(Target = ViewControl.Table)]
29+
public List<string> VirtualRouterIps { get; set; }
30+
[Ps1Xml(Target = ViewControl.Table)]
31+
public string ProvisioningState { get; set; }
32+
public List<PSVirtualRouterPeer> Peerings { get; set; }
33+
34+
[JsonIgnore]
35+
public string PeeringsText
36+
{
37+
get { return JsonConvert.SerializeObject(Peerings, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
38+
}
39+
40+
[JsonIgnore]
41+
public string HostedGatewayText
42+
{
43+
get { return JsonConvert.SerializeObject(HostedGateway, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
44+
}
45+
}
46+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Microsoft and contributors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
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+
//
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using Microsoft.Azure.Management.Network.Models;
16+
using Microsoft.WindowsAzure.Commands.Common.Attributes;
17+
using Newtonsoft.Json;
18+
using System.Collections.Generic;
19+
20+
namespace Microsoft.Azure.Commands.Network.Models
21+
{
22+
public partial class PSVirtualRouterPeer : PSChildResource
23+
{
24+
[Ps1Xml(Target = ViewControl.Table)]
25+
public uint PeerAsn { get; set; }
26+
[Ps1Xml(Target = ViewControl.Table)]
27+
public string PeerIp { get; set; }
28+
[Ps1Xml(Target = ViewControl.Table)]
29+
public string ProvisioningState { get; set; }
30+
[Ps1Xml(Target = ViewControl.Table)]
31+
public string Type { get; set; }
32+
}
33+
}

src/Network/Network/Network.format.ps1xml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4326,5 +4326,105 @@
43264326
</ListEntries>
43274327
</ListControl>
43284328
</View>
4329+
<View>
4330+
<Name>Microsoft.Azure.Commands.Network.Models.PSVirtualRouter</Name>
4331+
<ViewSelectedBy>
4332+
<TypeName>Microsoft.Azure.Commands.Network.Models.PSVirtualRouter</TypeName>
4333+
</ViewSelectedBy>
4334+
<ListControl>
4335+
<ListEntries>
4336+
<ListEntry>
4337+
<ListItems>
4338+
<ListItem>
4339+
<Label>Name</Label>
4340+
<PropertyName>Name</PropertyName>
4341+
</ListItem>
4342+
<ListItem>
4343+
<Label>ResourceGroupName</Label>
4344+
<PropertyName>ResourceGroupName</PropertyName>
4345+
</ListItem>
4346+
<ListItem>
4347+
<Label>Location</Label>
4348+
<PropertyName>Location</PropertyName>
4349+
</ListItem>
4350+
<ListItem>
4351+
<Label>Id</Label>
4352+
<PropertyName>Id</PropertyName>
4353+
</ListItem>
4354+
<ListItem>
4355+
<Label>Etag</Label>
4356+
<PropertyName>Etag</PropertyName>
4357+
</ListItem>
4358+
<ListItem>
4359+
<Label>Type</Label>
4360+
<PropertyName>Type</PropertyName>
4361+
</ListItem>
4362+
<ListItem>
4363+
<Label>ProvisioningState</Label>
4364+
<PropertyName>ProvisioningState</PropertyName>
4365+
</ListItem>
4366+
<ListItem>
4367+
<Label>HostedGateway</Label>
4368+
<PropertyName>HostedGatewayText</PropertyName>
4369+
</ListItem>
4370+
<ListItem>
4371+
<Label>VirtualRouterAsn</Label>
4372+
<PropertyName>VirtualRouterAsn</PropertyName>
4373+
</ListItem>
4374+
<ListItem>
4375+
<Label>VirtualRouterIps</Label>
4376+
<PropertyName>VirtualRouterIps</PropertyName>
4377+
</ListItem>
4378+
<ListItem>
4379+
<Label>Peerings</Label>
4380+
<PropertyName>PeeringsText</PropertyName>
4381+
</ListItem>
4382+
</ListItems>
4383+
</ListEntry>
4384+
</ListEntries>
4385+
</ListControl>
4386+
</View>
4387+
<View>
4388+
<Name>Microsoft.Azure.Commands.Network.Models.PSVirtualRouterPeer</Name>
4389+
<ViewSelectedBy>
4390+
<TypeName>Microsoft.Azure.Commands.Network.Models.PSVirtualRouterPeer</TypeName>
4391+
</ViewSelectedBy>
4392+
<ListControl>
4393+
<ListEntries>
4394+
<ListEntry>
4395+
<ListItems>
4396+
<ListItem>
4397+
<Label>Name</Label>
4398+
<PropertyName>Name</PropertyName>
4399+
</ListItem>
4400+
<ListItem>
4401+
<Label>Id</Label>
4402+
<PropertyName>Id</PropertyName>
4403+
</ListItem>
4404+
<ListItem>
4405+
<Label>Etag</Label>
4406+
<PropertyName>Etag</PropertyName>
4407+
</ListItem>
4408+
<ListItem>
4409+
<Label>Type</Label>
4410+
<PropertyName>Type</PropertyName>
4411+
</ListItem>
4412+
<ListItem>
4413+
<Label>ProvisioningState</Label>
4414+
<PropertyName>ProvisioningState</PropertyName>
4415+
</ListItem>
4416+
<ListItem>
4417+
<Label>PeerAsn</Label>
4418+
<PropertyName>PeerAsn</PropertyName>
4419+
</ListItem>
4420+
<ListItem>
4421+
<Label>PeerIp</Label>
4422+
<PropertyName>PeerIp</PropertyName>
4423+
</ListItem>
4424+
</ListItems>
4425+
</ListEntry>
4426+
</ListEntries>
4427+
</ListControl>
4428+
</View>
43294429
</ViewDefinitions>
43304430
</Configuration>

0 commit comments

Comments
 (0)