Skip to content

Commit 0aaead3

Browse files
authored
Added Subnet' property to new-AzLoadBalancerBackendAddressConfig cmdlet. Fixed piping in Set/Remove loadBalancerBackendPool cmdlets (#15496)
* it1 * Fixed piping in Remove/set lbBackendPool cmdlets * Updated help files * Added tests, session records. Updated BreakingChangesIssues and ChangeLog
1 parent 2547f2a commit 0aaead3

15 files changed

+1915
-1657
lines changed

src/Network/Network.Test/ScenarioTests/LoadBalancerBackendPoolTests.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function Test-LoadBalancerBackendPoolCRUD
7171

7272
#remove IpAddress from list
7373
$backendPoolSet1.LoadBalancerBackendAddresses.Remove($backendPoolSet1.LoadBalancerBackendAddresses[0])
74-
$backendPoolSet2 = Set-AzLoadBalancerBackendAddressPool -InputObject $backendPoolSet1
74+
$backendPoolSet2 = $backendPoolSet1 | Set-AzLoadBalancerBackendAddressPool
7575

7676
Assert-NotNull $backendPoolSet2
7777

@@ -104,7 +104,7 @@ function Test-LoadBalancerBackendPoolCreate
104104
$location = Get-ProviderLocation $resourceTypeParent
105105
$backendAddressConfigName = "TestVNetRef"
106106
$testIpAddress1 = "10.0.0.5"
107-
$testIpAddress2 = "10.0.0.6"
107+
$testIpAddress2 = "10.0.1.6"
108108
$testIpAddress3 = "10.0.0.7"
109109

110110
$backendAddressConfigName1 = Get-ResourceName
@@ -129,7 +129,7 @@ function Test-LoadBalancerBackendPoolCreate
129129
$lb = New-AzLoadBalancer -Name $lbName -ResourceGroupName $rgname -Location $location -SKU Standard
130130

131131
$ip1 = New-AzLoadBalancerBackendAddressConfig -IpAddress $testIpAddress1 -Name $backendAddressConfigName1 -VirtualNetworkId $vnet.Id
132-
$ip2 = New-AzLoadBalancerBackendAddressConfig -IpAddress $testIpAddress2 -Name $backendAddressConfigName2 -VirtualNetworkId $vnet.Id
132+
$ip2 = New-AzLoadBalancerBackendAddressConfig -IpAddress $testIpAddress2 -Name $backendAddressConfigName2 -SubnetId $vnet.Subnets[0].Id
133133
$ip3 = New-AzLoadBalancerBackendAddressConfig -IpAddress $testIpAddress3 -Name $backendAddressConfigName3 -VirtualNetworkId $vnet.Id
134134

135135
$ips = @($ip1, $ip2)
@@ -274,7 +274,7 @@ function Test-LoadBalancerBackendPoolDelete
274274
$lb | Remove-AzLoadBalancerBackendAddressPool -Name $backendPoolName1
275275

276276
##test passing input object
277-
Remove-AzLoadBalancerBackendAddressPool -InputObject $b2
277+
$b2 | Remove-AzLoadBalancerBackendAddressPool
278278

279279
##test passing resourceId
280280
Remove-AzLoadBalancerBackendAddressPool -ResourceId $b3.Id
@@ -470,6 +470,12 @@ function Test-LoadBalancerBackendAddressConfig
470470
Assert-AreEqual $ipconfig1.IpAddress $validIpAddress
471471
Assert-AreEqual $ipconfig1.VirtualNetwork.Id $virtualNetwork.Id
472472

473+
$ipconfig2 = New-AzLoadBalancerBackendAddressConfig -IpAddress $validIpAddress -Name $backendAddressConfigName1 -SubnetId virtualNetwork.Subnets[0].Id
474+
475+
Assert-AreEqual $ipconfig2.Name $backendAddressConfigName1
476+
Assert-AreEqual $ipconfig2.IpAddress $validIpAddress
477+
Assert-AreEqual $ipconfig2.Subnet.Id virtualNetwork.Subnets[0].Id
478+
473479
Assert-ThrowsLike { New-AzLoadBalancerBackendAddressConfig -IpAddress $invalidIpAddress2 -Name $backendAddressConfigName1 -VirtualNetworkId $virtualNetwork.Id} "*Invalid IPAddress*"
474480

475481
}

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.LoadBalancerBackendPoolTests/TestLoadBalancerBackendAddressConfig.json

Lines changed: 269 additions & 196 deletions
Large diffs are not rendered by default.

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.LoadBalancerBackendPoolTests/TestLoadBalancerBackendPoolCRUD.json

Lines changed: 435 additions & 408 deletions
Large diffs are not rendered by default.

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.LoadBalancerBackendPoolTests/TestLoadBalancerBackendPoolCreate.json

Lines changed: 500 additions & 467 deletions
Large diffs are not rendered by default.

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.LoadBalancerBackendPoolTests/TestLoadBalancerBackendPoolDelete.json

Lines changed: 568 additions & 529 deletions
Large diffs are not rendered by default.

src/Network/Network/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
- `New-AzPublicIpAddress`
2626
- `New-AzCustomIpPrefix`
2727
- `Update-AzCustomIpPrefix`
28+
* Updated cmdlet to add 'Subnet' property for IP based load balancer backend address pool.
29+
- `New-AzLoadBalancerBackendAddressConfig`
2830

2931
## Version 4.9.0
3032
* Updated cmdlets for route server for a more stable way to add IP configuration.

src/Network/Network/LoadBalancer/NewAzLoadBalancerBackendAddressConfig.cs

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@
2727

2828
namespace Microsoft.Azure.Commands.Network
2929
{
30-
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "LoadBalancerBackendAddressConfig", DefaultParameterSetName = "SetByResourcePublicIpAddress", SupportsShouldProcess = true), OutputType(typeof(PSLoadBalancerBackendAddress))]
30+
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "LoadBalancerBackendAddressConfig", DefaultParameterSetName = "SetByIpAndSubnet", SupportsShouldProcess = true), OutputType(typeof(PSLoadBalancerBackendAddress))]
3131
public partial class NewAzureLoadBalancerBackendAddress : NetworkBaseCmdlet
3232
{
3333
[Parameter(
3434
Mandatory = true,
35-
ParameterSetName = "SetByResourcePublicIpAddress",
35+
ParameterSetName = "SetByIpAndVnet",
36+
HelpMessage = "The IPAddress to add to the Backend pool",
37+
ValueFromPipelineByPropertyName = true)]
38+
[Parameter(
39+
Mandatory = true,
40+
ParameterSetName = "SetByIpAndSubnet",
3641
HelpMessage = "The IPAddress to add to the Backend pool",
3742
ValueFromPipelineByPropertyName = true)]
3843
[ValidateNotNullOrEmpty]
@@ -47,12 +52,20 @@ public partial class NewAzureLoadBalancerBackendAddress : NetworkBaseCmdlet
4752

4853
[Parameter(
4954
Mandatory = true,
50-
ParameterSetName = "SetByResourcePublicIpAddress",
55+
ParameterSetName = "SetByIpAndVnet",
5156
HelpMessage = "The virtual network associated with the Backend Address config",
5257
ValueFromPipelineByPropertyName = true)]
5358
[ValidateNotNullOrEmpty]
5459
public string VirtualNetworkId { get; set; }
5560

61+
[Parameter(
62+
Mandatory = true,
63+
ParameterSetName = "SetByIpAndSubnet",
64+
HelpMessage = "The subnet associated with the Backend Address config",
65+
ValueFromPipelineByPropertyName = true)]
66+
[ValidateNotNullOrEmpty]
67+
public string SubnetId { get; set; }
68+
5669
[Parameter(
5770
Mandatory = true,
5871
ParameterSetName = "SetByResourceFrontendIPConfiguration",
@@ -65,36 +78,43 @@ public override void Execute()
6578
{
6679
base.Execute();
6780

68-
var loadBalancerBackendAddress = new PSLoadBalancerBackendAddress();
69-
loadBalancerBackendAddress.Name = this.Name;
81+
var loadBalancerBackendAddress = new PSLoadBalancerBackendAddress
82+
{
83+
Name = this.Name
84+
};
7085

71-
if (string.Equals(ParameterSetName, "SetByResourcePublicIpAddress"))
86+
if (string.Equals(ParameterSetName, "SetByIpAndVnet"))
7287
{
73-
if (!ValidateIpAddress(this.IpAddress))
74-
{
75-
throw new PSArgumentException($"Invalid IPAddress : {Properties.Resources.InvalidIPAddress}");
76-
}
88+
this.ValidateAndSetIpAddress(loadBalancerBackendAddress);
7789

7890
loadBalancerBackendAddress.VirtualNetwork = new PSResourceId
7991
{
8092
Id = VirtualNetworkId
8193
};
94+
}
8295

83-
loadBalancerBackendAddress.IpAddress = this.IpAddress;
96+
if (string.Equals(ParameterSetName, "SetByIpAndSubnet"))
97+
{
98+
this.ValidateAndSetIpAddress(loadBalancerBackendAddress);
99+
100+
loadBalancerBackendAddress.Subnet = new PSResourceId
101+
{
102+
Id = SubnetId
103+
};
84104
}
85-
86-
if(string.Equals(ParameterSetName, "SetByResourceFrontendIPConfiguration"))
105+
106+
if (string.Equals(ParameterSetName, "SetByResourceFrontendIPConfiguration"))
87107
{
88108
loadBalancerBackendAddress.LoadBalancerFrontendIPConfiguration = new PSResourceId
89109
{
90110
Id = LoadBalancerFrontendIPConfigurationId
91111
};
92-
}
112+
}
93113

94114
WriteObject(loadBalancerBackendAddress);
95115
}
96116

97-
public bool ValidateIpAddress(string ipAddress)
117+
private bool ValidateIpAddress(string ipAddress)
98118
{
99119
IPAddress result = null;
100120

@@ -105,5 +125,15 @@ public bool ValidateIpAddress(string ipAddress)
105125

106126
return IPAddress.TryParse(ipAddress, out result);
107127
}
128+
129+
private void ValidateAndSetIpAddress(PSLoadBalancerBackendAddress backendAddress)
130+
{
131+
if (!ValidateIpAddress(this.IpAddress))
132+
{
133+
throw new PSArgumentException($"Invalid IPAddress : {Properties.Resources.InvalidIPAddress}");
134+
}
135+
136+
backendAddress.IpAddress = this.IpAddress;
137+
}
108138
}
109139
}

src/Network/Network/LoadBalancer/RemoveAzureLoadBalancerBackendPool.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ public partial class RemoveAzureLoadBalancerBackendPool : NetworkBaseCmdlet
6969
public PSLoadBalancer LoadBalancer { get; set; }
7070

7171
[Parameter(
72-
Mandatory = false,
72+
Mandatory = true,
7373
HelpMessage = "The backend address pool to remove",
74+
ValueFromPipeline = true,
7475
ParameterSetName = DeleteByInputObjectParameterSet)]
7576
[ValidateNotNullOrEmpty]
7677
public PSBackendAddressPool InputObject { get; set; }

src/Network/Network/LoadBalancer/SetAzureLoadBalancerBackendPool.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public partial class SetAzureLoadBalancerBackendPool : NetworkBaseCmdlet
7373
[Parameter(
7474
Mandatory = true,
7575
HelpMessage = "The backend address pool to set",
76+
ValueFromPipeline = true,
7677
ParameterSetName = SetByInputObjectParameterSet)]
7778
[ValidateNotNullOrEmpty]
7879
public PSBackendAddressPool InputObject { get; set; }

src/Network/Network/Models/PSLoadBalancerBackendAddress.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ public partial class PSLoadBalancerBackendAddress : PSChildResource
2929
public PSResourceId VirtualNetwork { get; set; }
3030

3131
[JsonProperty(Order = 3)]
32-
public string IpAddress { get; set; }
32+
public PSResourceId Subnet { get; set; }
3333

3434
[JsonProperty(Order = 4)]
35+
public string IpAddress { get; set; }
36+
37+
[JsonProperty(Order = 5)]
3538
public PSResourceId LoadBalancerFrontendIPConfiguration { get; set; }
3639

3740
[JsonIgnore]
@@ -54,5 +57,14 @@ public string VirtualNetworkIdText
5457
return JsonConvert.SerializeObject(VirtualNetwork, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
5558
}
5659
}
60+
61+
[JsonIgnore]
62+
public string SubnetIdText
63+
{
64+
get
65+
{
66+
return JsonConvert.SerializeObject(Subnet, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
67+
}
68+
}
5769
}
5870
}

src/Network/Network/Network.format.ps1xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,10 @@
27142714
<Label>VirtualNetwork</Label>
27152715
<PropertyName>VirtualNetworkIdText</PropertyName>
27162716
</ListItem>
2717+
<ListItem>
2718+
<Label>Subnet</Label>
2719+
<PropertyName>SubnetIdText</PropertyName>
2720+
</ListItem>
27172721
<ListItem>
27182722
<Label>LoadBalancerFrontendIPConfiguration</Label>
27192723
<PropertyName>LoadBalancerFrontendIPConfigurationIdText</PropertyName>

src/Network/Network/help/New-AzLoadBalancerBackendAddressConfig.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ Returns a load balancer backend address config.
1212

1313
## SYNTAX
1414

15-
### SetByResourcePublicIpAddress (Default)
15+
### SetByIpAndSubnet (Default)
16+
```
17+
New-AzLoadBalancerBackendAddressConfig -IpAddress <String> -Name <String> -SubnetId <String>
18+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
19+
```
20+
21+
### SetByIpAndVnet
1622
```
1723
New-AzLoadBalancerBackendAddressConfig -IpAddress <String> -Name <String> -VirtualNetworkId <String>
1824
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
@@ -34,8 +40,14 @@ Returns a load balancer backend address config.
3440
PS C:\> $virtualNetwork = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $resourceGroup
3541
New-AzLoadBalancerBackendAddressConfig -IpAddress "10.0.0.5" -Name "TestVNetRef" -VirtualNetworkId $virtualNetwork.Id
3642
```
43+
### Example 2: New loadbalancer address config with subnet reference
44+
```powershell
45+
PS C:\> $virtualNetwork = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $resourceGroup
46+
$subnet = Get-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $virtualNetwork
47+
New-AzLoadBalancerBackendAddressConfig -IpAddress "10.0.0.5" -Name "TestVNetRef" -SubnetId $subnet.Id
48+
```
3749

38-
### Example 2: New loadbalancer address config with loadbalancer frontend ip configuration reference
50+
### Example 3: New loadbalancer address config with loadbalancer frontend ip configuration reference
3951
```powershell
4052
PS C:\> $frontend = New-AzLoadBalancerFrontendIpConfig -Name $frontendName -PublicIpAddress $publicip
4153
New-AzLoadBalancerBackendAddressConfig -LoadBalancerFrontendIPConfigurationId $frontend.Id -Name "TestLBFERef"
@@ -63,7 +75,7 @@ The IPAddress to add to the backend pool
6375
6476
```yaml
6577
Type: System.String
66-
Parameter Sets: SetByResourcePublicIpAddress
78+
Parameter Sets: SetByIpAndSubnet, SetByIpAndVnet
6779
Aliases:
6880

6981
Required: True
@@ -103,12 +115,27 @@ Accept pipeline input: True (ByPropertyName)
103115
Accept wildcard characters: False
104116
```
105117
118+
### -SubnetId
119+
The subnet associated with the Backend Address config
120+
121+
```yaml
122+
Type: System.String
123+
Parameter Sets: SetByIpAndSubnet
124+
Aliases:
125+
126+
Required: True
127+
Position: Named
128+
Default value: None
129+
Accept pipeline input: True (ByPropertyName)
130+
Accept wildcard characters: False
131+
```
132+
106133
### -VirtualNetworkId
107134
The virtual network associated with Backend Address config
108135
109136
```yaml
110137
Type: System.String
111-
Parameter Sets: SetByResourcePublicIpAddress
138+
Parameter Sets: SetByIpAndVnet
112139
Aliases:
113140

114141
Required: True

0 commit comments

Comments
 (0)