Skip to content

Commit 7a23b38

Browse files
author
Hovsep
committed
Merge pull request Azure#2383 from lamchester/dev
Update Set-AzureRmLocalNetworkGateway and add Set-AzureRmVirtualNetworkGateway
2 parents fd6ca08 + e690dd6 commit 7a23b38

File tree

10 files changed

+8939
-375
lines changed

10 files changed

+8939
-375
lines changed

src/ResourceManager/Network/Commands.Network.Test/Commands.Network.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@
348348
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayConnectionTests\TestVirtualNetworkGatewayConnectionWithBgpCRUD.json">
349349
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
350350
</None>
351+
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayTests\TestSetVirtualNetworkGatewayCRUD.json">
352+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
353+
</None>
351354
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayTests\TestVirtualNetworkExpressRouteGatewayCRUD.json">
352355
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
353356
</None>

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/LocalNetworkGatewayTests.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ function Test-LocalNetworkGatewayCRUD
5252
$expected = Get-AzureRmLocalNetworkGateway -ResourceGroupName $rgname -name $rname
5353
Assert-AreEqual "200.168.0.0/16" $expected.LocalNetworkAddressSpace.AddressPrefixes[0]
5454

55+
# Add BGP settings using Set-AzureRmLocalNetworkGateway
56+
$asn = 1234
57+
$bgpPeeringAddress = "1.2.3.4"
58+
$peerWeight = 15
59+
$actual = Set-AzureRmLocalNetworkGateway -LocalNetworkGateway $expected -Asn $asn -BgpPeeringAddress $bgpPeeringAddress -PeerWeight $peerWeight
60+
$expected = Get-AzureRmLocalNetworkGateway -ResourceGroupName $rgname -name $rname
61+
Assert-AreEqual $asn $expected.BgpSettings.Asn
62+
Assert-AreEqual $bgpPeeringAddress $expected.BgpSettings.BgpPeeringAddress
63+
Assert-AreEqual $peerWeight $expected.BgpSettings.PeerWeight
64+
65+
# Update BGP settings
66+
$asn = 1337
67+
$actual = Set-AzureRmLocalNetworkGateway -LocalNetworkGateway $expected -Asn $asn
68+
$expected = Get-AzureRmLocalNetworkGateway -ResourceGroupName $rgname -name $rname
69+
Assert-AreEqual $asn $expected.BgpSettings.Asn
70+
5571
# Delete LocalNetworkGateway
5672
$delete = Remove-AzureRmLocalNetworkGateway -ResourceGroupName $actual.ResourceGroupName -name $rname -PassThru -Force
5773
Assert-AreEqual true $delete

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/VirtualNetworkGatewayTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public void TestVirtualNetworkExpressRouteGatewayCRUD()
2626
NetworkResourcesController.NewInstance.RunPsTest("Test-VirtualNetworkExpressRouteGatewayCRUD");
2727
}
2828

29-
3029
[Fact]
3130
[Trait(Category.AcceptanceType, Category.CheckIn)]
3231
public void TestVirtualNetworkGatewayCRUD()
@@ -40,5 +39,11 @@ public void TestVirtualNetworkGatewayP2SAndSKU()
4039
{
4140
NetworkResourcesController.NewInstance.RunPsTest("Test-VirtualNetworkGatewayP2SAndSKU");
4241
}
42+
43+
[Fact]
44+
public void TestSetVirtualNetworkGatewayCRUD()
45+
{
46+
NetworkResourcesController.NewInstance.RunPsTest("Test-SetVirtualNetworkGatewayCRUD");
47+
}
4348
}
4449
}

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/VirtualNetworkGatewayTests.ps1

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,74 @@ function Test-VirtualNetworkGatewayCRUD
142142
}
143143
}
144144

145+
<#
146+
.SYNOPSIS
147+
Virtual network gateway tests
148+
#>
149+
function Test-SetVirtualNetworkGatewayCRUD
150+
{
151+
# Setup
152+
$rgname = Get-ResourceGroupName
153+
$rname = Get-ResourceName
154+
$domainNameLabel = Get-ResourceName
155+
$lngName = Get-ResourceName
156+
$connName = Get-ResourceName
157+
$vnetName = Get-ResourceName
158+
$publicIpName = Get-ResourceName
159+
$vnetGatewayConfigName = Get-ResourceName
160+
$rglocation = Get-ProviderLocation ResourceManagement
161+
$resourceTypeParent = "Microsoft.Network/virtualNetworkGateways"
162+
$location = Get-ProviderLocation $resourceTypeParent
163+
164+
try
165+
{
166+
# Create the resource group
167+
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $rglocation -Tags @{Name = "testtag"; Value = "testval"}
168+
169+
# Create the Virtual Network
170+
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix 10.0.0.0/24
171+
$vnet = New-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
172+
$vnet = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname
173+
$subnet = Get-AzureRmVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet
174+
175+
# Create the publicip
176+
$publicip = New-AzureRmPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel
177+
178+
# Create & Get virtualnetworkgateway
179+
$vnetIpConfig = New-AzureRmVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet
180+
New-AzureRmVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -EnableBgp $false -GatewaySku Standard
181+
$gateway = Get-AzureRmVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
182+
183+
# test Set-AzureRmVirtualNetworkGateway
184+
# resize
185+
# $sku = "HighPerformance"
186+
# $gateway = Set-AzureRmVirtualNetworkGateway -VirtualNetworkGateway $gateway -GatewaySku $sku
187+
# Assert-AreEqual $sku $gateway.Sku.Name
188+
189+
# default site - put a local network gateway and set it as the default site
190+
$lng = New-AzureRmLocalNetworkGateway -ResourceGroupName $rgname -Name $lngName -Location $location -GatewayIpAddress "1.2.3.4" -AddressPrefix "172.16.1.0/24"
191+
$gateway = Set-AzureRmVirtualNetworkGateway -VirtualNetworkGateway $gateway -GatewayDefaultSite $lng
192+
Assert-AreEqual $lng.Id $gateway.GatewayDefaultSite.Id
193+
194+
# VPN client things
195+
$vpnClientAddressSpace = "192.168.1.0/24"
196+
$gateway = Set-AzureRmVirtualNetworkGateway -VirtualNetworkGateway $gateway -VpnClientAddressPool $vpnClientAddressSpace
197+
Assert-AreEqual $vpnClientAddressSpace $gateway.VpnClientConfiguration.VpnClientAddressPool.AddressPrefixes
198+
199+
# BGP settings
200+
$asn = 1337
201+
$peerweight = 5
202+
$gateway = Set-AzureRmVirtualNetworkGateway -VirtualNetworkGateway $gateway -Asn $asn -PeerWeight $peerweight
203+
Assert-AreEqual $asn $gateway.BgpSettings.Asn
204+
Assert-AreEqual $peerWeight $gateway.BgpSettings.PeerWeight
205+
}
206+
finally
207+
{
208+
# Cleanup
209+
Clean-ResourceGroup $rgname
210+
}
211+
}
212+
145213
<#
146214
.SYNOPSIS
147215
Virtual network gateway tests

src/ResourceManager/Network/Commands.Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.LocalNetworkGatewayTests/TestLocalNetworkGatewayCRUD.json

Lines changed: 845 additions & 372 deletions
Large diffs are not rendered by default.

src/ResourceManager/Network/Commands.Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayTests/TestSetVirtualNetworkGatewayCRUD.json

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

src/ResourceManager/Network/Commands.Network/Commands.Network.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@
324324
<Compile Include="RouteTable\SetAzureRouteTableCommand.cs" />
325325
<Compile Include="VirtualNetworkGateway\AzureVirtualNetworkGatewayIpConfigBase.cs" />
326326
<Compile Include="VirtualNetworkGateway\ChildResourceHelp.cs" />
327+
<Compile Include="VirtualNetworkGateway\UpdateAzureVirtualNetworkGatewayCommand.cs" />
327328
<Compile Include="VirtualNetworkGateway\VirtualNetworkGatewayBaseCmdlet.cs" />
328329
<Compile Include="VirtualNetworkGateway\GetAzureVirtualNetworkGatewayCommand.cs" />
329330
<Compile Include="VirtualNetworkGateway\NewAzureVirtualNetworkGatewayCommand.cs" />

src/ResourceManager/Network/Commands.Network/LocalNetworkGateway/UpdateAzureLocalNetworkGatewayCommand.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,30 @@ public class SetAzureLocalNetworkGatewayCommand : LocalNetworkGatewayBaseCmdlet
3333
public PSLocalNetworkGateway LocalNetworkGateway { get; set; }
3434

3535
[Parameter(
36-
Mandatory = true,
36+
Mandatory = false,
3737
ValueFromPipelineByPropertyName = true,
3838
HelpMessage = "The address prefixes of the local network to be changed.")]
3939
[ValidateNotNullOrEmpty]
4040
public List<string> AddressPrefix { get; set; }
4141

42+
[Parameter(
43+
Mandatory = false,
44+
ValueFromPipelineByPropertyName = true,
45+
HelpMessage = "The local network gateway's ASN")]
46+
public uint Asn { get; set; }
47+
48+
[Parameter(
49+
Mandatory = false,
50+
ValueFromPipelineByPropertyName = true,
51+
HelpMessage = "The IP address of the local network gateway's BGP speaker")]
52+
public string BgpPeeringAddress { get; set; }
53+
54+
[Parameter(
55+
Mandatory = false,
56+
ValueFromPipelineByPropertyName = true,
57+
HelpMessage = "Weight added to BGP routes learned from this local network gateway")]
58+
public int PeerWeight { get; set; }
59+
4260
public override void ExecuteCmdlet()
4361
{
4462
base.ExecuteCmdlet();
@@ -48,7 +66,34 @@ public override void ExecuteCmdlet()
4866
throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound);
4967
}
5068

51-
this.LocalNetworkGateway.LocalNetworkAddressSpace.AddressPrefixes = this.AddressPrefix;
69+
if (this.AddressPrefix != null && this.AddressPrefix.Count > 0)
70+
{
71+
this.LocalNetworkGateway.LocalNetworkAddressSpace.AddressPrefixes = this.AddressPrefix;
72+
}
73+
74+
if ((this.Asn > 0 || !string.IsNullOrEmpty(this.BgpPeeringAddress) || this.PeerWeight > 0) && this.LocalNetworkGateway.BgpSettings == null)
75+
{
76+
this.LocalNetworkGateway.BgpSettings = new PSBgpSettings();
77+
}
78+
79+
if (this.Asn > 0)
80+
{
81+
this.LocalNetworkGateway.BgpSettings.Asn = this.Asn;
82+
}
83+
84+
if (!string.IsNullOrEmpty(this.BgpPeeringAddress))
85+
{
86+
this.LocalNetworkGateway.BgpSettings.BgpPeeringAddress = this.BgpPeeringAddress;
87+
}
88+
89+
if (this.PeerWeight > 0)
90+
{
91+
this.LocalNetworkGateway.BgpSettings.PeerWeight = this.PeerWeight;
92+
}
93+
else if (this.PeerWeight < 0)
94+
{
95+
throw new PSArgumentException("PeerWeight cannot be negative");
96+
}
5297

5398
// Map to the sdk object
5499
var localnetGatewayModel = Mapper.Map<MNM.LocalNetworkGateway>(this.LocalNetworkGateway);

0 commit comments

Comments
 (0)