Skip to content

Add CRUD for VirtualRouter top level resource and VirtualRouterPeer #10273

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 1 commit into from
Oct 16, 2019
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
36 changes: 36 additions & 0 deletions src/Network/Network.Test/ScenarioTests/VirtualRouterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// ----------------------------------------------------------------------------------
//
// 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.Network.Test.ScenarioTests;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

namespace Commands.Network.Test.ScenarioTests
{
public class VirtualRouterTests : NetworkTestRunner
{
public VirtualRouterTests(Xunit.Abstractions.ITestOutputHelper output)
: base(output)
{
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.pgtm)]
public void TestVirtualRouterCRUDMinimalParameters()
{
TestRunner.RunTestScript(string.Format("Test-VirtualRouterCRUD"));
}
}
}
100 changes: 100 additions & 0 deletions src/Network/Network.Test/ScenarioTests/VirtualRouterTests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# ----------------------------------------------------------------------------------
#
# 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.
# ----------------------------------------------------------------------------------

function Check-CmdletReturnType
{
param($cmdletName, $cmdletReturn)

$cmdletData = Get-Command $cmdletName
Assert-NotNull $cmdletData
[array]$cmdletReturnTypes = $cmdletData.OutputType.Name | Foreach-Object { return ($_ -replace "Microsoft.Azure.Commands.Network.Models.","") }
[array]$cmdletReturnTypes = $cmdletReturnTypes | Foreach-Object { return ($_ -replace "System.","") }
$realReturnType = $cmdletReturn.GetType().Name -replace "Microsoft.Azure.Commands.Network.Models.",""
return $cmdletReturnTypes -contains $realReturnType
}

<#
.SYNOPSIS
Test creating new VirtualRouter
#>
function Test-VirtualRouterCRUD
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$domainNameLabel = Get-ResourceName
$vnetName = Get-ResourceName
$publicIpName = Get-ResourceName
$vnetGatewayConfigName = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement "southcentralus"
$resourceTypeParent = "Microsoft.Network/virtualNetworkGateways"
$location = Get-ProviderLocation $resourceTypeParent "southcentralus"
$virtualRouterName = Get-ResourceName

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


# Create the Virtual Network
$subnet = New-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix 10.0.0.0/24
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
$subnet = Get-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet

# Create the publicip
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel

# Create & Get virtualnetworkgateway
$vnetIpConfig = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet

$actual = New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType ExpressRoute -GatewaySku HighPerformance -VpnType RouteBased -VpnGatewayGeneration None -Force
$expected = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual $expected.Name $actual.Name
Assert-AreEqual "ExpressRoute" $expected.GatewayType
Assert-AreEqual "None" $expected.VpnGatewayGeneration

# Create Virtual Router
$actualvr = New-AzVirtualRouter -ResourceGroupName $rgname -location $location -Name $virtualRouterName -HostedGateway $expected
$expectedvr = Get-AzVirtualRouter -ResourceGroupName $rgname -RouterName $virtualRouterName
Assert-AreEqual $expectedvr.ResourceGroupName $actualvr.ResourceGroupName
Assert-AreEqual $expectedvr.Name $actualvr.Name

# List Virtual Routers
$list = Get-AzVirtualRouter -ResourceGroupName $rgname
Assert-AreEqual 1 @($list).Count
Assert-AreEqual $list[0].ResourceGroupName $actualvr.ResourceGroupName
Assert-AreEqual $list[0].Name $actualvr.Name
Assert-AreEqual $list[0].Location $actualvr.Location

# Delete VR
$deletevR = Remove-AzVirtualRouter -ResourceGroupName $rgname -RouterName $virtualRouterName -PassThru -Force
Assert-AreEqual true $deletevR

# Delete virtualNetworkGateway
$delete = Remove-AzVirtualNetworkGateway -ResourceGroupName $actual.ResourceGroupName -name $rname -PassThru -Force
Assert-AreEqual true $delete

$list = Get-AzVirtualRouter -ResourceGroupName $rgname
Assert-AreEqual 0 @($list).Count
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/Network/Network/Az.Network.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
'Start-AzVirtualNetworkGatewayPacketCapture',
'Stop-AzVirtualNetworkGatewayPacketCapture',
'Start-AzVirtualNetworkGatewayConnectionPacketCapture',
'Stop-AzVirtualNetworkGatewayConnectionPacketCapture'
'Stop-AzVirtualNetworkGatewayConnectionPacketCapture',
'New-AzVirtualRouter','Remove-AzVirtualRouter','Get-AzVirtualRouter',
'Add-AzVirtualRouterPeer','Update-AzVirtualRouterPeer','Remove-AzVirtualRouterPeer', 'Get-AzVirtualRouterPeer'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
40 changes: 40 additions & 0 deletions src/Network/Network/Common/NetworkResourceManagerProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,37 @@ private static void MapSecurityRuleManagementToCommand<MnmType, CnmType>(MnmType
}
}

public class VirtualRouterConverter : ITypeConverter<MNM.VirtualRouter, CNM.PSVirtualRouter>
{
public CNM.PSVirtualRouter Convert(MNM.VirtualRouter source, CNM.PSVirtualRouter destination, ResolutionContext context)
{
var router = new CNM.PSVirtualRouter()
{
Id = source.Id,
Name = source.Name,
Etag = source.Etag,
Location = source.Location,
Type = source.Type,
ProvisioningState = source.ProvisioningState,
VirtualRouterAsn = (uint) source.VirtualRouterAsn
};
if (source.HostedGateway != null)
{
router.HostedGateway = new CNM.PSResourceId()
{
Id = source.HostedGateway.Id
};
}
if (source.VirtualRouterIps != null)
{
router.VirtualRouterIps = source.VirtualRouterIps.ToList<string>();
}

router.Peerings = new List<CNM.PSVirtualRouterPeer>();
return router;
}
}

private static void MapSecurityRuleCommandToManagement<CnmType, MnmType>(CnmType cnmObj, MnmType mnmObj)
{
/*
Expand Down Expand Up @@ -1043,6 +1074,15 @@ private static void Initialize()
// MNM to CNM
cfg.CreateMap<MNM.BastionHost, CNM.PSBastion>();
cfg.CreateMap<MNM.BastionHostIPConfiguration, CNM.PSBastionIPConfiguration>();

// Virtual Router
// CNM to MNM
cfg.CreateMap<CNM.PSVirtualRouter, MNM.VirtualRouter>();
cfg.CreateMap<CNM.PSVirtualRouterPeer, MNM.VirtualRouterPeering>();

// MNM to CNM
cfg.CreateMap<MNM.VirtualRouter, CNM.PSVirtualRouter>().ConvertUsing(new VirtualRouterConverter());
cfg.CreateMap<MNM.VirtualRouterPeering, CNM.PSVirtualRouterPeer>();
});

_mapper = config.CreateMapper();
Expand Down
46 changes: 46 additions & 0 deletions src/Network/Network/Generated/Models/PSVirtualRouter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft and contributors. 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.

using Microsoft.Azure.Management.Network.Models;
using Microsoft.WindowsAzure.Commands.Common.Attributes;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Microsoft.Azure.Commands.Network.Models
{
public partial class PSVirtualRouter : PSTopLevelResource
{
[Ps1Xml(Target = ViewControl.Table)]
public PSResourceId HostedGateway { get; set; }
[Ps1Xml(Target = ViewControl.Table)]
public uint VirtualRouterAsn { get; set; }
[Ps1Xml(Target = ViewControl.Table)]
public List<string> VirtualRouterIps { get; set; }
[Ps1Xml(Target = ViewControl.Table)]
public string ProvisioningState { get; set; }
public List<PSVirtualRouterPeer> Peerings { get; set; }

[JsonIgnore]
public string PeeringsText
{
get { return JsonConvert.SerializeObject(Peerings, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}

[JsonIgnore]
public string HostedGatewayText
{
get { return JsonConvert.SerializeObject(HostedGateway, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}
}
}
33 changes: 33 additions & 0 deletions src/Network/Network/Generated/Models/PSVirtualRouterPeer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft and contributors. 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.

using Microsoft.Azure.Management.Network.Models;
using Microsoft.WindowsAzure.Commands.Common.Attributes;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Microsoft.Azure.Commands.Network.Models
{
public partial class PSVirtualRouterPeer : PSChildResource
{
[Ps1Xml(Target = ViewControl.Table)]
public uint PeerAsn { get; set; }
[Ps1Xml(Target = ViewControl.Table)]
public string PeerIp { get; set; }
[Ps1Xml(Target = ViewControl.Table)]
public string ProvisioningState { get; set; }
[Ps1Xml(Target = ViewControl.Table)]
public string Type { get; set; }
}
}
100 changes: 100 additions & 0 deletions src/Network/Network/Network.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -4326,5 +4326,105 @@
</ListEntries>
</ListControl>
</View>
<View>
<Name>Microsoft.Azure.Commands.Network.Models.PSVirtualRouter</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Azure.Commands.Network.Models.PSVirtualRouter</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<Label>Name</Label>
<PropertyName>Name</PropertyName>
</ListItem>
<ListItem>
<Label>ResourceGroupName</Label>
<PropertyName>ResourceGroupName</PropertyName>
</ListItem>
<ListItem>
<Label>Location</Label>
<PropertyName>Location</PropertyName>
</ListItem>
<ListItem>
<Label>Id</Label>
<PropertyName>Id</PropertyName>
</ListItem>
<ListItem>
<Label>Etag</Label>
<PropertyName>Etag</PropertyName>
</ListItem>
<ListItem>
<Label>Type</Label>
<PropertyName>Type</PropertyName>
</ListItem>
<ListItem>
<Label>ProvisioningState</Label>
<PropertyName>ProvisioningState</PropertyName>
</ListItem>
<ListItem>
<Label>HostedGateway</Label>
<PropertyName>HostedGatewayText</PropertyName>
</ListItem>
<ListItem>
<Label>VirtualRouterAsn</Label>
<PropertyName>VirtualRouterAsn</PropertyName>
</ListItem>
<ListItem>
<Label>VirtualRouterIps</Label>
<PropertyName>VirtualRouterIps</PropertyName>
</ListItem>
<ListItem>
<Label>Peerings</Label>
<PropertyName>PeeringsText</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
<View>
<Name>Microsoft.Azure.Commands.Network.Models.PSVirtualRouterPeer</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Azure.Commands.Network.Models.PSVirtualRouterPeer</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<Label>Name</Label>
<PropertyName>Name</PropertyName>
</ListItem>
<ListItem>
<Label>Id</Label>
<PropertyName>Id</PropertyName>
</ListItem>
<ListItem>
<Label>Etag</Label>
<PropertyName>Etag</PropertyName>
</ListItem>
<ListItem>
<Label>Type</Label>
<PropertyName>Type</PropertyName>
</ListItem>
<ListItem>
<Label>ProvisioningState</Label>
<PropertyName>ProvisioningState</PropertyName>
</ListItem>
<ListItem>
<Label>PeerAsn</Label>
<PropertyName>PeerAsn</PropertyName>
</ListItem>
<ListItem>
<Label>PeerIp</Label>
<PropertyName>PeerIp</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
</ViewDefinitions>
</Configuration>
Loading