Skip to content

Commit 6db0ffc

Browse files
committed
Changes for Health API
Draft of changes for Health API.
1 parent 493d3df commit 6db0ffc

12 files changed

+5797
-0
lines changed
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 LoadBalancerHealthPerRuleTests : NetworkTestRunner
22+
{
23+
public LoadBalancerHealthPerRuleTests(Xunit.Abstractions.ITestOutputHelper output)
24+
: base(output)
25+
{
26+
}
27+
28+
[Fact]
29+
[Trait(Category.AcceptanceType, Category.CheckIn)]
30+
[Trait(Category.Owner, NrpTeamAlias.slbdev)]
31+
public void TestLoadBalancerHealthPerRule()
32+
{
33+
TestRunner.RunTestScript("Test-LoadBalancerHealthPerRule");
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
<#
16+
.SYNOPSIS
17+
Tests to query load balancer health per rule..
18+
#>
19+
function Test-LoadBalancerHealthPerRule
20+
{
21+
# Setup
22+
$rgname = Get-ResourceGroupName
23+
$vnetName = Get-ResourceName
24+
$subnetName = Get-ResourceName
25+
$publicIpName = Get-ResourceName
26+
$lbName = Get-ResourceName
27+
$lbRuleName = Get-ResourceName
28+
$probeName = Get-ResourceName
29+
$frontendName = Get-ResourceName
30+
$backendAddressPoolName = Get-ResourceName
31+
$rglocation = Get-ProviderLocation ResourceManagement
32+
$resourceTypeParent = "Microsoft.Network/loadBalancers"
33+
$location = Get-ProviderLocation $resourceTypeParent
34+
$vmUsername = "azureuser"
35+
$vmPassword = ConvertTo-SecureString "$vmUsername@123" -AsPlainText -Force
36+
$ipConfigName = Get-ResourceName
37+
$vmsize = "Standard_A2"
38+
$ImagePublisher = "MicrosoftWindowsServer"
39+
$imageOffer = "WindowsServer"
40+
$imageSKU = "2019-Datacenter-GS"
41+
42+
try
43+
{
44+
# Create the resource group
45+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval"}
46+
47+
# Create the Virtual Network
48+
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24
49+
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
50+
51+
# Create the publicip
52+
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Static -sku Standard
53+
54+
# Create LoadBalancer
55+
$frontend = New-AzLoadBalancerFrontendIpConfig -Name $frontendName -PublicIpAddress $publicip
56+
57+
$bepool = New-AzLoadBalancerBackendAddressPoolConfig -Name $backendAddressPoolName
58+
59+
$probe = @{
60+
Name = $probeName
61+
Protocol = 'tcp'
62+
Port = '80'
63+
IntervalInSeconds = '360'
64+
ProbeCount = '5'
65+
}
66+
$healthprobe = New-AzLoadBalancerProbeConfig @probe
67+
68+
$lbrule = @{
69+
Name = $lbRuleName
70+
Protocol = 'tcp'
71+
FrontendPort = '80'
72+
BackendPort = '80'
73+
IdleTimeoutInMinutes = '15'
74+
FrontendIpConfiguration = $frontend
75+
BackendAddressPool = $bePool
76+
Probe = $healthprobe
77+
}
78+
$rule = New-AzLoadBalancerRuleConfig @lbrule -EnableTcpReset -DisableOutboundSNAT
79+
80+
$loadbalancer = @{
81+
ResourceGroupName = $rgName
82+
Name = $lbName
83+
Location = $rglocation
84+
Sku = 'Standard'
85+
FrontendIpConfiguration = $frontend
86+
BackendAddressPool = $bePool
87+
LoadBalancingRule = $rule
88+
Probe = $healthprobe
89+
}
90+
$lb = New-AzLoadBalancer @loadbalancer
91+
92+
$cred = New-Object System.Management.Automation.PSCredential ($vmUsername, $vmPassword);
93+
94+
$RdpPublicIP = New-AzPublicIpAddress -Name "RdpPublicIP" -ResourceGroupName $resourceGroup.ResourceGroupName -Location $resourceGroup.Location -AllocationMethod Static -Sku Standard -IpAddressVersion IPv4
95+
96+
# both LB pool and Instance Level public ip for RPD
97+
$Ip4Config = New-AzNetworkInterfaceIpConfig -Name $ipConfigName -Subnet $vnet.subnets[0] -PrivateIpAddressVersion IPv4 -LoadBalancerBackendAddressPool $bepool -PublicIpAddress $RdpPublicIP
98+
99+
$NIC = New-AzNetworkInterface -Name "NIC" -ResourceGroupName $resourceGroup.ResourceGroupName -Location $resourceGroup.Location -NetworkSecurityGroupId $nsg.Id -IpConfiguration $Ip4Config
100+
101+
$vmName = "myVM"
102+
$VMconfig = New-AzVMConfig -VMName $vmName -VMSize $vmsize
103+
| Set-AzVMOperatingSystem -Windows -ComputerName $vmName -Credential $cred -ProvisionVMAgent 3> $null
104+
| Set-AzVMSourceImage -PublisherName $ImagePublisher -Offer $imageOffer -Skus $imageSKU -Version "latest" 3> $null
105+
| Set-AzVMOSDisk -Name "$vmName.vhd" -CreateOption fromImage 3> $null | Add-AzVMNetworkInterface -Id $NIC.Id 3> $null
106+
107+
$VM = New-AzVM -ResourceGroupName $resourceGroup.ResourceGroupName -Location $resourceGroup.Location -VM $VMconfig
108+
109+
# install IIS (port 80)
110+
$ext = @{
111+
Publisher = 'Microsoft.Compute'
112+
ExtensionType = 'CustomScriptExtension'
113+
ExtensionName = 'IIS'
114+
ResourceGroupName = $rgName
115+
VMName = "myVM"
116+
Location = $region
117+
TypeHandlerVersion = '1.8'
118+
SettingString = '{"commandToExecute":"powershell Add-WindowsFeature Web-Server; powershell Add-Content -Path \"C:\\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"}'
119+
}
120+
Set-AzVMExtension @ext -AsJob
121+
122+
# List
123+
$list = Get-AzLoadBalancerRuleHealth -ResourceGroupName $rgname -LoadBalancerName $lbName -Name $lbruleName
124+
125+
Assert-True { @($list.LoadBalancerBackendAddresses).Count -eq 1}
126+
Assert-AreEqual $list.LoadBalancerBackendAddresses[0].IpAddress "10.0.1.4"
127+
Assert-True { $list.Down.Count -eq 1}
128+
}
129+
finally
130+
{
131+
# Cleanup
132+
Clean-ResourceGroup $rgname
133+
}
134+
}

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.LoadBalancerHealthPerRuleTests/TestLoadBalancerHealthPerRule.json

+5,322
Large diffs are not rendered by default.

src/Network/Network/Az.Network.psd1

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
200200
'Get-AzLoadBalancerInboundNatRuleConfig',
201201
'Get-AzLoadBalancerOutboundRuleConfig',
202202
'Get-AzLoadBalancerProbeConfig', 'Get-AzLoadBalancerRuleConfig',
203+
'Get-AzLoadBalancerRuleHealth',
203204
'Get-AzLocalNetworkGateway', 'Get-AzNatGateway',
204205
'Get-AzNetworkInterface', 'Get-AzNetworkInterfaceIpConfig',
205206
'Get-AzNetworkInterfaceTapConfig', 'Get-AzNetworkManager',

src/Network/Network/ChangeLog.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
* Added `DefaultOutboundConnectivityEnabled` property in PSNetworkInterface
5050
* Added support for `AutoscaleConfiguration` property in `AzureFirewall` model for `New-AzFirewall` and `Set-AzFirewall` commands
5151
* Added support for `ResiliencyModel` property in `New-AzVirtualNetworkGateway` and `Set-AzVirtualNetworkGateway` command for ExpressRoute
52+
* Added cmdlet `Get-AzLoadBalancerRuleHealth` for Load Balancer Rule Health.
5253

5354
## Version 7.11.0
5455
* Updated Device Update Private Link provider configuration

src/Network/Network/Common/NetworkResourceManagerProfile.cs

+16
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,22 @@ private static void Initialize()
863863
// MNM to CNM
864864
cfg.CreateMap<MNM.InboundNatRulePortMapping, CNM.PSInboundNatRulePortMapping>();
865865

866+
// LoadBalancerHealthPerRule
867+
// CNM to MNM
868+
cfg.CreateMap<CNM.PSLoadBalancerHealthPerRule, MNM.LoadBalancerHealthPerRule>();
869+
870+
// LoadBalancerHealthPerRule
871+
// MNM to CNM
872+
cfg.CreateMap<MNM.LoadBalancerHealthPerRule, CNM.PSLoadBalancerHealthPerRule>();
873+
874+
// LoadBalancerHealthPerRulePerBackendAddress
875+
// CNM to MNM
876+
cfg.CreateMap<CNM.PSLoadBalancerHealthPerRulePerBackendAddress, MNM.LoadBalancerHealthPerRulePerBackendAddress>();
877+
878+
// LoadBalancerHealthPerRulePerBackendAddress
879+
// MNM to CNM
880+
cfg.CreateMap<MNM.LoadBalancerHealthPerRulePerBackendAddress, CNM.PSLoadBalancerHealthPerRulePerBackendAddress>();
881+
866882
// NatRulePortMapping
867883
// CNM to MNM
868884
cfg.CreateMap<CNM.PSNatRulePortMapping, MNM.NatRulePortMapping>();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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.Tags;
16+
using Microsoft.Rest.Azure;
17+
using Microsoft.Azure.Commands.Network.Models;
18+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
19+
using Microsoft.Azure.Management.Network;
20+
using Microsoft.Azure.Management.Network.Models;
21+
using System;
22+
using System.Collections.Generic;
23+
using System.Management.Automation;
24+
using CNM = Microsoft.Azure.Commands.Network.Models;
25+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
26+
using System.Linq;
27+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
28+
29+
namespace Microsoft.Azure.Commands.Network
30+
{
31+
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "LoadBalancerRuleHealth", DefaultParameterSetName = "GetByNameParameterSet"), OutputType(typeof(PSLoadBalancerHealthPerRule))]
32+
public partial class GetAzureLoadBalancerRuleHealth : NetworkBaseCmdlet
33+
{
34+
private const string GetByNameParameterSet = "GetByNameParameterSet";
35+
36+
[Parameter(
37+
Mandatory = true,
38+
HelpMessage = "The resource group name of the load balancer.",
39+
ParameterSetName = GetByNameParameterSet)]
40+
[ResourceGroupCompleter]
41+
public string ResourceGroupName { get; set; }
42+
43+
[Parameter(Mandatory = true,
44+
HelpMessage = "The name of the load balancer.",
45+
ParameterSetName = GetByNameParameterSet)]
46+
[ValidateNotNullOrEmpty]
47+
public string LoadBalancerName { get; set; }
48+
49+
[Parameter(Mandatory = true,
50+
HelpMessage = "The name of the load balancing rule.",
51+
ParameterSetName = GetByNameParameterSet)]
52+
[ValidateNotNullOrEmpty]
53+
public string Name { get; set; }
54+
55+
public override void Execute()
56+
{
57+
base.Execute();
58+
var getHealth = this.NetworkClient.NetworkManagementClient.LoadBalancerLoadBalancingRules.Health(this.ResourceGroupName, this.LoadBalancerName, this.Name);
59+
var psHealth = NetworkResourceManagerProfile.Mapper.Map<PSLoadBalancerHealthPerRule>(getHealth);
60+
WriteObject(psHealth, true);
61+
}
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
using Microsoft.WindowsAzure.Commands.Common.Attributes;
15+
using Newtonsoft.Json;
16+
using System.Collections.Generic;
17+
18+
namespace Microsoft.Azure.Commands.Network.Models
19+
{
20+
public partial class PSLoadBalancerHealthPerRule : PSTopLevelResource
21+
{
22+
[JsonProperty(Order = 1)]
23+
[Ps1Xml(Target = ViewControl.Table)]
24+
public int Up { get; set; }
25+
26+
[JsonProperty(Order = 1)]
27+
[Ps1Xml(Target = ViewControl.Table)]
28+
public int Down { get; set; }
29+
30+
public List<PSLoadBalancerHealthPerRulePerBackendAddress> LoadBalancerBackendAddresses { get; set; }
31+
32+
[JsonIgnore]
33+
public string LoadBalancerBackendAddressesText
34+
{
35+
get { return JsonConvert.SerializeObject(LoadBalancerBackendAddresses, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
namespace Microsoft.Azure.Commands.Network.Models
16+
{
17+
public partial class PSLoadBalancerHealthPerRulePerBackendAddress : PSChildResource
18+
{
19+
public string IpAddress { get; set; }
20+
21+
public string NetworkInterfaceIPConfigurationId { get; set; }
22+
23+
public string State { get; set; }
24+
25+
public string Reason { get; set; }
26+
}
27+
}

src/Network/Network/Network.format.ps1xml

+26
Original file line numberDiff line numberDiff line change
@@ -3164,6 +3164,32 @@
31643164
</ListEntry>
31653165
</ListEntries>
31663166
</ListControl>
3167+
</View>
3168+
<View>
3169+
<Name>Microsoft.Azure.Commands.Network.Models.PSLoadBalancerHealthPerRule</Name>
3170+
<ViewSelectedBy>
3171+
<TypeName>Microsoft.Azure.Commands.Network.Models.PSLoadBalancerHealthPerRule</TypeName>
3172+
</ViewSelectedBy>
3173+
<ListControl>
3174+
<ListEntries>
3175+
<ListEntry>
3176+
<ListItems>
3177+
<ListItem>
3178+
<Label>Up</Label>
3179+
<PropertyName>Up</PropertyName>
3180+
</ListItem>
3181+
<ListItem>
3182+
<Label>Down</Label>
3183+
<PropertyName>Down</PropertyName>
3184+
</ListItem>
3185+
<ListItem>
3186+
<Label>LoadBalancerBackendAddresses</Label>
3187+
<PropertyName>LoadBalancerBackendAddressesText</PropertyName>
3188+
</ListItem>
3189+
</ListItems>
3190+
</ListEntry>
3191+
</ListEntries>
3192+
</ListControl>
31673193
</View>
31683194
<View>
31693195
<Name>Microsoft.Azure.Commands.Network.Models.PSRouteTable</Name>

0 commit comments

Comments
 (0)