Skip to content

Commit d3161b5

Browse files
gitlwhWeiheng Li
andauthored
[Network] Add PrivateIpAddressPrefixLength parameters for two AzNetworkInterfaceIpConfig cmd (Azure#27447)
Co-authored-by: Weiheng Li <[email protected]>
1 parent d50978b commit d3161b5

File tree

7 files changed

+86
-4
lines changed

7 files changed

+86
-4
lines changed

src/Network/Network/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
--->
2020

2121
## Upcoming Release
22+
* Updated Add-AzNetworkInterfaceIpConfig and New-AzNetworkInterfaceIpConfig cmdlets to add new parameter PrivateIpAddressPrefixLength.
23+
- `Add-AzNetworkInterfaceIpConfig`
24+
- `New-AzNetworkInterfaceIpConfig`
2225

2326
## Version 7.15.1
2427
* Updated VirtualNetworkGatewayConnection cmdlets to pass AuxilaryAuthHeader for referenced resourceIds i.e. LocalNetworkGateway2, VirtualNetworkGateway2. This is needed in case referenced resourceIds are in different AAD Tenant.

src/Network/Network/Models/PSNetworkInterfaceIpConfiguration.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public class PSNetworkInterfaceIPConfiguration : PSIPConfiguration
2424
[Ps1Xml(Target = ViewControl.Table)]
2525
public string PrivateIpAddressVersion { get; set; }
2626

27+
[JsonProperty(Order = 2)]
28+
[Ps1Xml(Target = ViewControl.Table)]
29+
public int? PrivateIpAddressPrefixLength { get; set; }
30+
2731
[JsonProperty(Order = 2)]
2832
public List<PSBackendAddressPool> LoadBalancerBackendAddressPools { get; set; }
2933

src/Network/Network/Network.format.ps1xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,10 @@
20102010
<Label>PrivateIpAddressVersion</Label>
20112011
<PropertyName>PrivateIpAddressVersion</PropertyName>
20122012
</ListItem>
2013+
<ListItem>
2014+
<Label>PrivateIPAddressPrefixLength</Label>
2015+
<PropertyName>PrivateIPAddressPrefixLength</PropertyName>
2016+
</ListItem>
20132017
<ListItem>
20142018
<Label>PrivateIpAllocationMethod</Label>
20152019
<PropertyName>PrivateIpAllocationMethod</PropertyName>

src/Network/Network/NetworkInterface/IpConfiguration/AddAzureNetworkInterfaceIpConfigCommand.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public class AddAzureNetworkInterfaceIpConfigCommand : AzureNetworkInterfaceIpCo
3535
HelpMessage = "The Network Interface")]
3636
public PSNetworkInterface NetworkInterface { get; set; }
3737

38+
[Parameter(
39+
Mandatory = false,
40+
HelpMessage = "The Private IPAddress Prefix Length")]
41+
public int? PrivateIPAddressPrefixLength { get; set; }
3842

3943
public override void Execute()
4044
{
@@ -185,6 +189,21 @@ public override void Execute()
185189

186190
ipconfig.PrivateIpAddressVersion = this.PrivateIpAddressVersion;
187191

192+
if (this.PrivateIPAddressPrefixLength != null)
193+
{
194+
if (ipconfig.Primary)
195+
{
196+
throw new ArgumentException("Primary property must be false when PrivateIPAddressPrefixLength is set.");
197+
}
198+
199+
if (!string.Equals(this.PrivateIpAddressVersion, "IPv4", StringComparison.OrdinalIgnoreCase))
200+
{
201+
throw new ArgumentException("PrivateIPAddressVersion must be IPv4 when PrivateIPAddressPrefixLength is set.");
202+
}
203+
204+
ipconfig.PrivateIpAddressPrefixLength = this.PrivateIPAddressPrefixLength;
205+
}
206+
188207
this.NetworkInterface.IpConfigurations.Add(ipconfig);
189208

190209
WriteObject(this.NetworkInterface);

src/Network/Network/NetworkInterface/IpConfiguration/NewAzureNetworkInterfaceIpConfigCommand.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.Network.Models;
16+
using System;
1617
using System.Collections.Generic;
1718
using System.Management.Automation;
1819

@@ -27,6 +28,12 @@ public class NewAzureNetworkInterfaceIpConfigCommand : AzureNetworkInterfaceIpCo
2728
[ValidateNotNullOrEmpty]
2829
public override string Name { get; set; }
2930

31+
[Parameter(
32+
Mandatory = false,
33+
HelpMessage = "The Private IPAddress Prefix Length")]
34+
[ValidateNotNullOrEmpty]
35+
public int? PrivateIPAddressPrefixLength { get; set; }
36+
3037
public override void Execute()
3138
{
3239
base.Execute();
@@ -158,6 +165,21 @@ public override void Execute()
158165
}
159166
}
160167

168+
if (this.PrivateIPAddressPrefixLength != null)
169+
{
170+
if (this.Primary.IsPresent)
171+
{
172+
throw new ArgumentException("Primary property must be false when PrivateIPAddressPrefixLength is set.");
173+
}
174+
175+
if (!string.Equals(this.PrivateIpAddressVersion, "IPv4", StringComparison.OrdinalIgnoreCase))
176+
{
177+
throw new ArgumentException("PrivateIPAddressVersion must be IPv4 when PrivateIPAddressPrefixLength is set.");
178+
}
179+
180+
ipconfig.PrivateIpAddressPrefixLength = this.PrivateIPAddressPrefixLength;
181+
}
182+
161183
ipconfig.PrivateIpAddressVersion = this.PrivateIpAddressVersion;
162184
ipconfig.Primary = this.Primary.IsPresent;
163185
WriteObject(ipconfig);

src/Network/Network/help/Add-AzNetworkInterfaceIpConfig.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Adds a network interface IP configuration to a network interface.
1616
### SetByResource (Default)
1717
```
1818
Add-AzNetworkInterfaceIpConfig -Name <String> -NetworkInterface <PSNetworkInterface>
19-
[-PrivateIpAddressVersion <String>] [-PrivateIpAddress <String>] [-Primary] [-Subnet <PSSubnet>]
19+
[-PrivateIpAddressVersion <String>] [-PrivateIpAddress <String>] [-PrivateIpAddressPrefixLength <UInt16>] [-Primary] [-Subnet <PSSubnet>]
2020
[-PublicIpAddress <PSPublicIpAddress>] [-LoadBalancerBackendAddressPool <PSBackendAddressPool[]>]
2121
[-LoadBalancerInboundNatRule <PSInboundNatRule[]>]
2222
[-ApplicationGatewayBackendAddressPool <PSApplicationGatewayBackendAddressPool[]>]
@@ -27,7 +27,7 @@ Add-AzNetworkInterfaceIpConfig -Name <String> -NetworkInterface <PSNetworkInterf
2727
### SetByResourceId
2828
```
2929
Add-AzNetworkInterfaceIpConfig -Name <String> -NetworkInterface <PSNetworkInterface>
30-
[-PrivateIpAddressVersion <String>] [-PrivateIpAddress <String>] [-Primary] [-SubnetId <String>]
30+
[-PrivateIpAddressVersion <String>] [-PrivateIpAddress <String>] [-PrivateIpAddressPrefixLength <UInt16>] [-Primary] [-SubnetId <String>]
3131
[-PublicIpAddressId <String>] [-LoadBalancerBackendAddressPoolId <String[]>]
3232
[-LoadBalancerInboundNatRuleId <String[]>] [-ApplicationGatewayBackendAddressPoolId <String[]>]
3333
[-ApplicationSecurityGroupId <String[]>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
@@ -265,6 +265,21 @@ Accept pipeline input: False
265265
Accept wildcard characters: False
266266
```
267267
268+
### -PrivateIPAddressPrefixLength
269+
Specifies the static IP address prefix length of the network interface IP configuration.
270+
271+
```yaml
272+
Type: Type: System.UInt16
273+
Parameter Sets: (All)
274+
Aliases:
275+
276+
Required: False
277+
Position: Named
278+
Default value: None
279+
Accept pipeline input: False
280+
Accept wildcard characters: False
281+
```
282+
268283
### -PrivateIpAddressVersion
269284
Specifies the IP address version of a network interface IP configuration.
270285
The acceptable values for this parameter are:

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Creates a network interface IP configuration.
1616
### SetByResource (Default)
1717
```
1818
New-AzNetworkInterfaceIpConfig -Name <String> [-PrivateIpAddressVersion <String>] [-PrivateIpAddress <String>]
19-
[-Primary] [-Subnet <PSSubnet>] [-PublicIpAddress <PSPublicIpAddress>]
19+
[-Primary] [-Subnet <PSSubnet>] [-PublicIpAddress <PSPublicIpAddress>] [-PrivateIpAddressPrefixLength <UInt16>]
2020
[-LoadBalancerBackendAddressPool <PSBackendAddressPool[]>] [-LoadBalancerInboundNatRule <PSInboundNatRule[]>]
2121
[-ApplicationGatewayBackendAddressPool <PSApplicationGatewayBackendAddressPool[]>]
2222
[-ApplicationSecurityGroup <PSApplicationSecurityGroup[]>] [-GatewayLoadBalancerId <String>]
@@ -25,7 +25,7 @@ New-AzNetworkInterfaceIpConfig -Name <String> [-PrivateIpAddressVersion <String>
2525

2626
### SetByResourceId
2727
```
28-
New-AzNetworkInterfaceIpConfig -Name <String> [-PrivateIpAddressVersion <String>] [-PrivateIpAddress <String>]
28+
New-AzNetworkInterfaceIpConfig -Name <String> [-PrivateIpAddressVersion <String>] [-PrivateIpAddress <String>] [-PrivateIpAddressPrefixLength <UInt16>]
2929
[-Primary] [-SubnetId <String>] [-PublicIpAddressId <String>] [-LoadBalancerBackendAddressPoolId <String[]>]
3030
[-LoadBalancerInboundNatRuleId <String[]>] [-ApplicationGatewayBackendAddressPoolId <String[]>]
3131
[-ApplicationSecurityGroupId <String[]>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
@@ -274,6 +274,21 @@ Accept pipeline input: False
274274
Accept wildcard characters: False
275275
```
276276
277+
### -PrivateIPAddressPrefixLength
278+
Specifies the static IP address prefix length of the network interface IP configuration.
279+
280+
```yaml
281+
Type: Type: System.UInt16
282+
Parameter Sets: (All)
283+
Aliases:
284+
285+
Required: False
286+
Position: Named
287+
Default value: None
288+
Accept pipeline input: False
289+
Accept wildcard characters: False
290+
```
291+
277292
### -PrivateIpAddressVersion
278293
Specifies the IP address version of a network interface IP configuration.
279294
The acceptable values for this parameter are:

0 commit comments

Comments
 (0)