Skip to content

Added subnet property to new-AzLoadBalancerBackendAddressConfig cmdlet. Fixed piping in Set/Remove-AzLoadBalancerBackendAddressPool #15503

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
Jul 23, 2021
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 @@ -71,7 +71,7 @@ function Test-LoadBalancerBackendPoolCRUD

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

Assert-NotNull $backendPoolSet2

Expand Down Expand Up @@ -104,7 +104,7 @@ function Test-LoadBalancerBackendPoolCreate
$location = Get-ProviderLocation $resourceTypeParent
$backendAddressConfigName = "TestVNetRef"
$testIpAddress1 = "10.0.0.5"
$testIpAddress2 = "10.0.0.6"
$testIpAddress2 = "10.0.1.6"
$testIpAddress3 = "10.0.0.7"

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

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

$ips = @($ip1, $ip2)
Expand Down Expand Up @@ -274,7 +274,7 @@ function Test-LoadBalancerBackendPoolDelete
$lb | Remove-AzLoadBalancerBackendAddressPool -Name $backendPoolName1

##test passing input object
Remove-AzLoadBalancerBackendAddressPool -InputObject $b2
$b2 | Remove-AzLoadBalancerBackendAddressPool

##test passing resourceId
Remove-AzLoadBalancerBackendAddressPool -ResourceId $b3.Id
Expand Down Expand Up @@ -470,6 +470,12 @@ function Test-LoadBalancerBackendAddressConfig
Assert-AreEqual $ipconfig1.IpAddress $validIpAddress
Assert-AreEqual $ipconfig1.VirtualNetwork.Id $virtualNetwork.Id

$ipconfig2 = New-AzLoadBalancerBackendAddressConfig -IpAddress $validIpAddress -Name $backendAddressConfigName1 -SubnetId virtualNetwork.Subnets[0].Id

Assert-AreEqual $ipconfig2.Name $backendAddressConfigName1
Assert-AreEqual $ipconfig2.IpAddress $validIpAddress
Assert-AreEqual $ipconfig2.Subnet.Id virtualNetwork.Subnets[0].Id

Assert-ThrowsLike { New-AzLoadBalancerBackendAddressConfig -IpAddress $invalidIpAddress2 -Name $backendAddressConfigName1 -VirtualNetworkId $virtualNetwork.Id} "*Invalid IPAddress*"

}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
* Added support for viewing extended location of public IP address in the console
- `New-AzPublicIpAddress`
- `Get-AzPublicIpAddress`
- `New-AzCustomIpPrefix`
- `Update-AzCustomIpPrefix`
* Updated cmdlet to add 'Subnet' property for IP based load balancer backend address pool.
- `New-AzLoadBalancerBackendAddressConfig`

## Version 4.9.0
* Updated cmdlets for route server for a more stable way to add IP configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@

namespace Microsoft.Azure.Commands.Network
{
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "LoadBalancerBackendAddressConfig", DefaultParameterSetName = "SetByResourcePublicIpAddress", SupportsShouldProcess = true), OutputType(typeof(PSLoadBalancerBackendAddress))]
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "LoadBalancerBackendAddressConfig", DefaultParameterSetName = "SetByIpAndSubnet", SupportsShouldProcess = true), OutputType(typeof(PSLoadBalancerBackendAddress))]
public partial class NewAzureLoadBalancerBackendAddress : NetworkBaseCmdlet
{
[Parameter(
Mandatory = true,
ParameterSetName = "SetByResourcePublicIpAddress",
ParameterSetName = "SetByIpAndVnet",
HelpMessage = "The IPAddress to add to the Backend pool",
ValueFromPipelineByPropertyName = true)]
[Parameter(
Mandatory = true,
ParameterSetName = "SetByIpAndSubnet",
HelpMessage = "The IPAddress to add to the Backend pool",
ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
Expand All @@ -47,12 +52,20 @@ public partial class NewAzureLoadBalancerBackendAddress : NetworkBaseCmdlet

[Parameter(
Mandatory = true,
ParameterSetName = "SetByResourcePublicIpAddress",
ParameterSetName = "SetByIpAndVnet",
HelpMessage = "The virtual network associated with the Backend Address config",
ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public string VirtualNetworkId { get; set; }

[Parameter(
Mandatory = true,
ParameterSetName = "SetByIpAndSubnet",
HelpMessage = "The subnet associated with the Backend Address config",
ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public string SubnetId { get; set; }

[Parameter(
Mandatory = true,
ParameterSetName = "SetByResourceFrontendIPConfiguration",
Expand All @@ -65,36 +78,43 @@ public override void Execute()
{
base.Execute();

var loadBalancerBackendAddress = new PSLoadBalancerBackendAddress();
loadBalancerBackendAddress.Name = this.Name;
var loadBalancerBackendAddress = new PSLoadBalancerBackendAddress
{
Name = this.Name
};

if (string.Equals(ParameterSetName, "SetByResourcePublicIpAddress"))
if (string.Equals(ParameterSetName, "SetByIpAndVnet"))
{
if (!ValidateIpAddress(this.IpAddress))
{
throw new PSArgumentException($"Invalid IPAddress : {Properties.Resources.InvalidIPAddress}");
}
this.ValidateAndSetIpAddress(loadBalancerBackendAddress);

loadBalancerBackendAddress.VirtualNetwork = new PSResourceId
{
Id = VirtualNetworkId
};
}

loadBalancerBackendAddress.IpAddress = this.IpAddress;
if (string.Equals(ParameterSetName, "SetByIpAndSubnet"))
{
this.ValidateAndSetIpAddress(loadBalancerBackendAddress);

loadBalancerBackendAddress.Subnet = new PSResourceId
{
Id = SubnetId
};
}
if(string.Equals(ParameterSetName, "SetByResourceFrontendIPConfiguration"))

if (string.Equals(ParameterSetName, "SetByResourceFrontendIPConfiguration"))
{
loadBalancerBackendAddress.LoadBalancerFrontendIPConfiguration = new PSResourceId
{
Id = LoadBalancerFrontendIPConfigurationId
};
}
}

WriteObject(loadBalancerBackendAddress);
}

public bool ValidateIpAddress(string ipAddress)
private bool ValidateIpAddress(string ipAddress)
{
IPAddress result = null;

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

return IPAddress.TryParse(ipAddress, out result);
}

private void ValidateAndSetIpAddress(PSLoadBalancerBackendAddress backendAddress)
{
if (!ValidateIpAddress(this.IpAddress))
{
throw new PSArgumentException($"Invalid IPAddress : {Properties.Resources.InvalidIPAddress}");
}

backendAddress.IpAddress = this.IpAddress;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public partial class RemoveAzureLoadBalancerBackendPool : NetworkBaseCmdlet
public PSLoadBalancer LoadBalancer { get; set; }

[Parameter(
Mandatory = false,
Mandatory = true,
HelpMessage = "The backend address pool to remove",
ValueFromPipeline = true,
ParameterSetName = DeleteByInputObjectParameterSet)]
[ValidateNotNullOrEmpty]
public PSBackendAddressPool InputObject { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public partial class SetAzureLoadBalancerBackendPool : NetworkBaseCmdlet
[Parameter(
Mandatory = true,
HelpMessage = "The backend address pool to set",
ValueFromPipeline = true,
ParameterSetName = SetByInputObjectParameterSet)]
[ValidateNotNullOrEmpty]
public PSBackendAddressPool InputObject { get; set; }
Expand Down
14 changes: 13 additions & 1 deletion src/Network/Network/Models/PSLoadBalancerBackendAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ public partial class PSLoadBalancerBackendAddress : PSChildResource
public PSResourceId VirtualNetwork { get; set; }

[JsonProperty(Order = 3)]
public string IpAddress { get; set; }
public PSResourceId Subnet { get; set; }

[JsonProperty(Order = 4)]
public string IpAddress { get; set; }

[JsonProperty(Order = 5)]
public PSResourceId LoadBalancerFrontendIPConfiguration { get; set; }

[JsonIgnore]
Expand All @@ -54,5 +57,14 @@ public string VirtualNetworkIdText
return JsonConvert.SerializeObject(VirtualNetwork, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
}
}

[JsonIgnore]
public string SubnetIdText
{
get
{
return JsonConvert.SerializeObject(Subnet, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
}
}
}
}
4 changes: 4 additions & 0 deletions src/Network/Network/Network.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -2710,6 +2710,10 @@
<Label>VirtualNetwork</Label>
<PropertyName>VirtualNetworkIdText</PropertyName>
</ListItem>
<ListItem>
<Label>Subnet</Label>
<PropertyName>SubnetIdText</PropertyName>
</ListItem>
<ListItem>
<Label>LoadBalancerFrontendIPConfiguration</Label>
<PropertyName>LoadBalancerFrontendIPConfigurationIdText</PropertyName>
Expand Down
35 changes: 31 additions & 4 deletions src/Network/Network/help/New-AzLoadBalancerBackendAddressConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ Returns a load balancer backend address config.

## SYNTAX

### SetByResourcePublicIpAddress (Default)
### SetByIpAndSubnet (Default)
```
New-AzLoadBalancerBackendAddressConfig -IpAddress <String> -Name <String> -SubnetId <String>
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### SetByIpAndVnet
```
New-AzLoadBalancerBackendAddressConfig -IpAddress <String> -Name <String> -VirtualNetworkId <String>
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
Expand All @@ -34,8 +40,14 @@ Returns a load balancer backend address config.
PS C:\> $virtualNetwork = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $resourceGroup
New-AzLoadBalancerBackendAddressConfig -IpAddress "10.0.0.5" -Name "TestVNetRef" -VirtualNetworkId $virtualNetwork.Id
```
### Example 2: New loadbalancer address config with subnet reference
```powershell
PS C:\> $virtualNetwork = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $resourceGroup
$subnet = Get-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $virtualNetwork
New-AzLoadBalancerBackendAddressConfig -IpAddress "10.0.0.5" -Name "TestVNetRef" -SubnetId $subnet.Id
```

### Example 2: New loadbalancer address config with loadbalancer frontend ip configuration reference
### Example 3: New loadbalancer address config with loadbalancer frontend ip configuration reference
```powershell
PS C:\> $frontend = New-AzLoadBalancerFrontendIpConfig -Name $frontendName -PublicIpAddress $publicip
New-AzLoadBalancerBackendAddressConfig -LoadBalancerFrontendIPConfigurationId $frontend.Id -Name "TestLBFERef"
Expand Down Expand Up @@ -63,7 +75,7 @@ The IPAddress to add to the backend pool

```yaml
Type: System.String
Parameter Sets: SetByResourcePublicIpAddress
Parameter Sets: SetByIpAndSubnet, SetByIpAndVnet
Aliases:

Required: True
Expand Down Expand Up @@ -103,12 +115,27 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -SubnetId
The subnet associated with the Backend Address config

```yaml
Type: System.String
Parameter Sets: SetByIpAndSubnet
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -VirtualNetworkId
The virtual network associated with Backend Address config

```yaml
Type: System.String
Parameter Sets: SetByResourcePublicIpAddress
Parameter Sets: SetByIpAndVnet
Aliases:

Required: True
Expand Down
Loading