Skip to content

Update Set-AzureRmLocalNetworkGateway and add Set-AzureRmVirtualNetworkGateway #2383

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 12 commits into from
Jun 7, 2016
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 @@ -348,6 +348,9 @@
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayConnectionTests\TestVirtualNetworkGatewayConnectionWithBgpCRUD.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayTests\TestSetVirtualNetworkGatewayCRUD.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayTests\TestVirtualNetworkExpressRouteGatewayCRUD.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ function Test-LocalNetworkGatewayCRUD
$expected = Get-AzureRmLocalNetworkGateway -ResourceGroupName $rgname -name $rname
Assert-AreEqual "200.168.0.0/16" $expected.LocalNetworkAddressSpace.AddressPrefixes[0]

# Add BGP settings using Set-AzureRmLocalNetworkGateway
$asn = 1234
$bgpPeeringAddress = "1.2.3.4"
$peerWeight = 15
$actual = Set-AzureRmLocalNetworkGateway -LocalNetworkGateway $expected -Asn $asn -BgpPeeringAddress $bgpPeeringAddress -PeerWeight $peerWeight
$expected = Get-AzureRmLocalNetworkGateway -ResourceGroupName $rgname -name $rname
Assert-AreEqual $asn $expected.BgpSettings.Asn
Assert-AreEqual $bgpPeeringAddress $expected.BgpSettings.BgpPeeringAddress
Assert-AreEqual $peerWeight $expected.BgpSettings.PeerWeight

# Update BGP settings
$asn = 1337
$actual = Set-AzureRmLocalNetworkGateway -LocalNetworkGateway $expected -Asn $asn
$expected = Get-AzureRmLocalNetworkGateway -ResourceGroupName $rgname -name $rname
Assert-AreEqual $asn $expected.BgpSettings.Asn

# Delete LocalNetworkGateway
$delete = Remove-AzureRmLocalNetworkGateway -ResourceGroupName $actual.ResourceGroupName -name $rname -PassThru -Force
Assert-AreEqual true $delete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public void TestVirtualNetworkExpressRouteGatewayCRUD()
NetworkResourcesController.NewInstance.RunPsTest("Test-VirtualNetworkExpressRouteGatewayCRUD");
}


[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVirtualNetworkGatewayCRUD()
Expand All @@ -40,5 +39,11 @@ public void TestVirtualNetworkGatewayP2SAndSKU()
{
NetworkResourcesController.NewInstance.RunPsTest("Test-VirtualNetworkGatewayP2SAndSKU");
}

[Fact]
public void TestSetVirtualNetworkGatewayCRUD()
{
NetworkResourcesController.NewInstance.RunPsTest("Test-SetVirtualNetworkGatewayCRUD");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,74 @@ function Test-VirtualNetworkGatewayCRUD
}
}

<#
.SYNOPSIS
Virtual network gateway tests
#>
function Test-SetVirtualNetworkGatewayCRUD
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$domainNameLabel = Get-ResourceName
$lngName = Get-ResourceName
$connName = Get-ResourceName
$vnetName = Get-ResourceName
$publicIpName = Get-ResourceName
$vnetGatewayConfigName = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$resourceTypeParent = "Microsoft.Network/virtualNetworkGateways"
$location = Get-ProviderLocation $resourceTypeParent

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

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

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

# Create & Get virtualnetworkgateway
$vnetIpConfig = New-AzureRmVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet
New-AzureRmVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -EnableBgp $false -GatewaySku Standard
$gateway = Get-AzureRmVirtualNetworkGateway -ResourceGroupName $rgname -name $rname

# test Set-AzureRmVirtualNetworkGateway
# resize
# $sku = "HighPerformance"
# $gateway = Set-AzureRmVirtualNetworkGateway -VirtualNetworkGateway $gateway -GatewaySku $sku
# Assert-AreEqual $sku $gateway.Sku.Name

# default site - put a local network gateway and set it as the default site
$lng = New-AzureRmLocalNetworkGateway -ResourceGroupName $rgname -Name $lngName -Location $location -GatewayIpAddress "1.2.3.4" -AddressPrefix "172.16.1.0/24"
$gateway = Set-AzureRmVirtualNetworkGateway -VirtualNetworkGateway $gateway -GatewayDefaultSite $lng
Assert-AreEqual $lng.Id $gateway.GatewayDefaultSite.Id

# VPN client things
$vpnClientAddressSpace = "192.168.1.0/24"
$gateway = Set-AzureRmVirtualNetworkGateway -VirtualNetworkGateway $gateway -VpnClientAddressPool $vpnClientAddressSpace
Assert-AreEqual $vpnClientAddressSpace $gateway.VpnClientConfiguration.VpnClientAddressPool.AddressPrefixes

# BGP settings
$asn = 1337
$peerweight = 5
$gateway = Set-AzureRmVirtualNetworkGateway -VirtualNetworkGateway $gateway -Asn $asn -PeerWeight $peerweight
Assert-AreEqual $asn $gateway.BgpSettings.Asn
Assert-AreEqual $peerWeight $gateway.BgpSettings.PeerWeight
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Virtual network gateway tests
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@
<Compile Include="RouteTable\SetAzureRouteTableCommand.cs" />
<Compile Include="VirtualNetworkGateway\AzureVirtualNetworkGatewayIpConfigBase.cs" />
<Compile Include="VirtualNetworkGateway\ChildResourceHelp.cs" />
<Compile Include="VirtualNetworkGateway\UpdateAzureVirtualNetworkGatewayCommand.cs" />
<Compile Include="VirtualNetworkGateway\VirtualNetworkGatewayBaseCmdlet.cs" />
<Compile Include="VirtualNetworkGateway\GetAzureVirtualNetworkGatewayCommand.cs" />
<Compile Include="VirtualNetworkGateway\NewAzureVirtualNetworkGatewayCommand.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,30 @@ public class SetAzureLocalNetworkGatewayCommand : LocalNetworkGatewayBaseCmdlet
public PSLocalNetworkGateway LocalNetworkGateway { get; set; }

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

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The local network gateway's ASN")]
public uint Asn { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The IP address of the local network gateway's BGP speaker")]
public string BgpPeeringAddress { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Weight added to BGP routes learned from this local network gateway")]
public int PeerWeight { get; set; }

public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();
Expand All @@ -48,7 +66,34 @@ public override void ExecuteCmdlet()
throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound);
}

this.LocalNetworkGateway.LocalNetworkAddressSpace.AddressPrefixes = this.AddressPrefix;
if (this.AddressPrefix != null && this.AddressPrefix.Count > 0)
{
this.LocalNetworkGateway.LocalNetworkAddressSpace.AddressPrefixes = this.AddressPrefix;
}

if ((this.Asn > 0 || !string.IsNullOrEmpty(this.BgpPeeringAddress) || this.PeerWeight > 0) && this.LocalNetworkGateway.BgpSettings == null)
{
this.LocalNetworkGateway.BgpSettings = new PSBgpSettings();
}

if (this.Asn > 0)
{
this.LocalNetworkGateway.BgpSettings.Asn = this.Asn;
}

if (!string.IsNullOrEmpty(this.BgpPeeringAddress))
{
this.LocalNetworkGateway.BgpSettings.BgpPeeringAddress = this.BgpPeeringAddress;
}

if (this.PeerWeight > 0)
{
this.LocalNetworkGateway.BgpSettings.PeerWeight = this.PeerWeight;
}
else if (this.PeerWeight < 0)
{
throw new PSArgumentException("PeerWeight cannot be negative");
}

// Map to the sdk object
var localnetGatewayModel = Mapper.Map<MNM.LocalNetworkGateway>(this.LocalNetworkGateway);
Expand Down
Loading