Skip to content

Commit 00a194c

Browse files
erichoffmannmsWeiheng Liwyunchi-ms
authored
Add new IsParent parameter to New-AzCustomIpPrefix cmdlet (#19577)
* fix * add files * fix * Add new IsParent parameter to New-AzCustomIpPrefix cmdlet * Add usage examples Co-authored-by: Weiheng Li <[email protected]> Co-authored-by: Yunchi Wang <[email protected]>
1 parent ffdbfe7 commit 00a194c

File tree

4 files changed

+119
-52
lines changed

4 files changed

+119
-52
lines changed

src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace Microsoft.Azure.Commands.Network
2121
using System.Collections;
2222
using System.Linq;
2323
using System.Management.Automation;
24+
using System.Text.RegularExpressions;
2425
using MNM = Microsoft.Azure.Management.Network.Models;
2526

2627
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSCustomIpPrefix))]
@@ -99,10 +100,13 @@ public class NewAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet
99100

100101
[Parameter(
101102
Mandatory = false,
102-
HelpMessage = "Parent CustomIpPrefix for /64 IPv6 CustomIpPrefix",
103+
HelpMessage = "Parent CustomIpPrefix for Child CustomIpPrefix",
103104
ValueFromPipelineByPropertyName = true)]
104105
public PSCustomIpPrefix CustomIpPrefixParent { get; set; }
105106

107+
[Parameter(Mandatory = false, HelpMessage = "Denotes that resource is being created as a Parent CustomIpPrefix")]
108+
public SwitchParameter IsParent { get; set; }
109+
106110
[Parameter(
107111
Mandatory = false,
108112
HelpMessage = "A list of availability zones denoting the IP allocated for the resource needs to come from.",
@@ -152,6 +156,22 @@ private PSCustomIpPrefix CreateCustomIpPrefix()
152156
ExpressRouteAdvertise = this.ExpressRouteAdvertise
153157
};
154158

159+
if (IsIPv4CIDR())
160+
{
161+
if (this.IsParent)
162+
{
163+
psModel.PrefixType = "Parent";
164+
}
165+
else if (this.CustomIpPrefixParent != null)
166+
{
167+
psModel.PrefixType = "Child";
168+
}
169+
else
170+
{
171+
psModel.PrefixType = "Singular";
172+
}
173+
}
174+
155175
var sdkModel = NetworkResourceManagerProfile.Mapper.Map<MNM.CustomIpPrefix>(psModel);
156176

157177
sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
@@ -167,5 +187,17 @@ private PSCustomIpPrefix CreateCustomIpPrefix()
167187

168188
return null;
169189
}
190+
191+
private bool IsIPv4CIDR()
192+
{
193+
if (this.Cidr != null)
194+
{
195+
return Regex.IsMatch(this.Cidr, @"^\d+\.\d+\.\d+\.\d+/\d+$");
196+
}
197+
else
198+
{
199+
return false;
200+
}
201+
}
170202
}
171203
}

src/Network/Network/ChangeLog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
* Updated commandlet to support bypassing NVA for spoke vNet traffic.
3535
- `NewAzureRmRoutingConfigurationCommand.cs`
3636
* Updated commandlet to support new parameters: asn, geo, expressrouteadvertise.
37-
- `Update-AzCustomIpPrefix
37+
- `Update-AzCustomIpPrefix`
3838
* Updated cmdlets to enable verification on client certificate revocation by using a new property VerifyClientRevocation in ApplicationGatewayClientAuthConfiguration
3939
- `New-AzApplicationGatewayClientAuthConfiguration`
4040
- `Set-AzApplicationGatewayClientAuthConfiguration`
41+
* Updated commandlet to support IPv4 Parent/Child CustomIpPrefix creation.
42+
- `New-AzCustomIpPrefix`
4143
* Added Uppercase Transform in New-AzApplicationGatewayFirewallCondition
4244
* Added DdosProtectionMode parameter in New-AzPublicIpAddress
4345
* Added ProbeThreshold parameter to Load Balancer Probe

src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class PSCustomIpPrefix : PSTopLevelResource
4545

4646
public bool? ExpressRouteAdvertise { get; set; }
4747

48+
public string PrefixType { get; set; }
49+
4850
[JsonIgnore]
4951
public string PublicIpPrefixesText
5052
{

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

Lines changed: 81 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ Creates a CustomIpPrefix resource
1313
## SYNTAX
1414

1515
```
16-
New-AzCustomIpPrefix -Name <String> -ResourceGroupName <String> -Location <String> -Cidr <String> [-Geo <String>]
17-
[-Asn <String>] [-ExpressRouteAdvertise] [-Zone <String[]>] [-Tag <Hashtable>] [-SignedMessage <String>] [-AuthorizationMessage <String>]
18-
[-CustomIpPrefixParent <CustomIpPrefix>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
16+
New-AzCustomIpPrefix -Name <String> -ResourceGroupName <String> -Location <String> -Cidr <String>
17+
[-Asn <String>] [-Geo <String>] [-SignedMessage <String>] [-AuthorizationMessage <String>]
18+
[-ExpressRouteAdvertise] [-CustomIpPrefixParent <PSCustomIpPrefix>] [-IsParent] [-Zone <String[]>]
19+
[-Tag <Hashtable>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
1920
[<CommonParameters>]
2021
```
2122

@@ -31,13 +32,27 @@ $myCustomIpPrefix = New-AzCustomIpPrefix -Name $prefixName -ResourceGroupName $r
3132

3233
This command kicks off the provisioning process for a new zone-redundant IPv4 Custom IP Prefix resource with name $prefixName in resource group $rgName with a CIDR of 40.40.40.0/24 in West US 2 region. Note the AuthorizationMessage is a contactenated string (containing the subscription ID, CIDR, and Route Origin Authorization expiration date) and the SignedMessage is the same string signed by X509 certificate offline.
3334

35+
### Example 2
36+
```powershell
37+
$myV4ParentPrefix = New-AzCustomIpPrefix -Name $prefixName -ResourceGroupName $rgName -Cidr "40.40.40.0/24" -Location westus2 -IsParent -AuthorizationMessage $authorizationMessage -SignedMessage $signedMessage
38+
```
39+
40+
This command kicks off the provisioning process for a new Parent IPv4 Custom IP Prefix resource with name $prefixName in resource group $rgName with a CIDR of 40.40.40.0/24.
41+
42+
### Example 3
43+
```powershell
44+
$myV4ChildIpPrefix = New-AzCustomIpPrefix -Name $prefixName -ResourceGroupName $rgName -Cidr "40.40.40.0/25" -Location westus2 -CustomIpPrefixParent $myV4ParentPrefix
45+
```
46+
47+
This command kicks off the provisioning process for a new Child IPv4 Custom IP Prefix resource with name $prefixName in resource group $rgName with a CIDR of 40.40.40.0/25. Its parent prefix is $myV4ParentPrefix.
48+
3449
## PARAMETERS
3550

3651
### -AsJob
3752
Run cmdlet in the background
3853

3954
```yaml
40-
Type: SwitchParameter
55+
Type: System.Management.Automation.SwitchParameter
4156
Parameter Sets: (All)
4257
Aliases:
4358

@@ -48,26 +63,26 @@ Accept pipeline input: False
4863
Accept wildcard characters: False
4964
```
5065
51-
### -Cidr
52-
The CustomIpPrefix CIDR.
66+
### -Asn
67+
The customIpPrefix ASN code.
5368
5469
```yaml
55-
Type: String
70+
Type: System.String
5671
Parameter Sets: (All)
5772
Aliases:
5873

59-
Required: True
74+
Required: False
6075
Position: Named
6176
Default value: None
6277
Accept pipeline input: True (ByPropertyName)
6378
Accept wildcard characters: False
6479
```
6580
66-
### -Geo
67-
The CustomIpPrefix Geo code.
81+
### -AuthorizationMessage
82+
Authorization message for WAN validation.
6883
6984
```yaml
70-
Type: String
85+
Type: System.String
7186
Parameter Sets: (All)
7287
Aliases:
7388

@@ -78,41 +93,41 @@ Accept pipeline input: True (ByPropertyName)
7893
Accept wildcard characters: False
7994
```
8095
81-
### -Asn
82-
The CustomIpPrefix Geo code.
96+
### -Cidr
97+
The CustomIpPrefix CIDR.
8398
8499
```yaml
85-
Type: String
100+
Type: System.String
86101
Parameter Sets: (All)
87102
Aliases:
88103

89-
Required: False
104+
Required: True
90105
Position: Named
91106
Default value: None
92107
Accept pipeline input: True (ByPropertyName)
93108
Accept wildcard characters: False
94109
```
95110
96-
### -ExpressRouteAdvertise
97-
Need to use ExpressRoute to advertise the CustomIpPrefix
111+
### -CustomIpPrefixParent
112+
Parent CustomIpPrefix of resource.
98113
99114
```yaml
100-
Type: SwitchParameter
115+
Type: Microsoft.Azure.Commands.Network.Models.PSCustomIpPrefix
101116
Parameter Sets: (All)
102117
Aliases:
103118

104119
Required: False
105120
Position: Named
106121
Default value: None
107-
Accept pipeline input: False
122+
Accept pipeline input: True (ByPropertyName)
108123
Accept wildcard characters: False
109124
```
110125
111126
### -DefaultProfile
112127
The credentials, account, tenant, and subscription used for communication with Azure.
113128
114129
```yaml
115-
Type: IAzureContextContainer
130+
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
116131
Parameter Sets: (All)
117132
Aliases: AzContext, AzureRmContext, AzureCredential
118133

@@ -123,41 +138,57 @@ Accept pipeline input: False
123138
Accept wildcard characters: False
124139
```
125140
126-
### -Location
127-
The CustomIpPrefix location.
141+
### -ExpressRouteAdvertise
142+
Using expressRoute advertise.
128143
129144
```yaml
130-
Type: String
145+
Type: System.Management.Automation.SwitchParameter
131146
Parameter Sets: (All)
132147
Aliases:
133148

134-
Required: True
149+
Required: False
135150
Position: Named
136151
Default value: None
137152
Accept pipeline input: True (ByPropertyName)
138153
Accept wildcard characters: False
139154
```
140155
141-
### -Name
142-
The resource name.
156+
### -Geo
157+
The customIpPrefix GEO code.
143158
144159
```yaml
145-
Type: String
160+
Type: System.String
146161
Parameter Sets: (All)
147-
Aliases: ResourceName
162+
Aliases:
163+
Accepted values: AFRI, APAC, AQ, EURO, LATAM, ME, NAM, OCEANIA
148164

149-
Required: True
165+
Required: False
150166
Position: Named
151167
Default value: None
152168
Accept pipeline input: True (ByPropertyName)
153169
Accept wildcard characters: False
154170
```
155171
156-
### -ResourceGroupName
157-
The resource group name.
172+
### -IsParent
173+
Denotes that resource is being created as a Parent CustomIpPrefix
158174
159175
```yaml
160-
Type: String
176+
Type: System.Management.Automation.SwitchParameter
177+
Parameter Sets: (All)
178+
Aliases:
179+
180+
Required: False
181+
Position: Named
182+
Default value: None
183+
Accept pipeline input: False
184+
Accept wildcard characters: False
185+
```
186+
187+
### -Location
188+
The CustomIpPrefix location.
189+
190+
```yaml
191+
Type: System.String
161192
Parameter Sets: (All)
162193
Aliases:
163194

@@ -168,41 +199,41 @@ Accept pipeline input: True (ByPropertyName)
168199
Accept wildcard characters: False
169200
```
170201
171-
### -Tag
172-
A hashtable which represents resource tags.
202+
### -Name
203+
The resource name.
173204
174205
```yaml
175-
Type: Hashtable
206+
Type: System.String
176207
Parameter Sets: (All)
177-
Aliases:
208+
Aliases: ResourceName
178209

179-
Required: False
210+
Required: True
180211
Position: Named
181212
Default value: None
182213
Accept pipeline input: True (ByPropertyName)
183214
Accept wildcard characters: False
184215
```
185216
186-
### -SignedMessage
187-
Signed message for WAN validation.
217+
### -ResourceGroupName
218+
The resource group name.
188219
189220
```yaml
190-
Type: String
221+
Type: System.String
191222
Parameter Sets: (All)
192223
Aliases:
193224

194-
Required: False
225+
Required: True
195226
Position: Named
196227
Default value: None
197228
Accept pipeline input: True (ByPropertyName)
198229
Accept wildcard characters: False
199230
```
200231
201-
### -AuthorizationMessage
202-
Authorization message for WAN validation.
232+
### -SignedMessage
233+
Signed message for WAN validation.
203234
204235
```yaml
205-
Type: String
236+
Type: System.String
206237
Parameter Sets: (All)
207238
Aliases:
208239

@@ -213,11 +244,11 @@ Accept pipeline input: True (ByPropertyName)
213244
Accept wildcard characters: False
214245
```
215246
216-
### -CustomIpPrefixParent
217-
Parent CustomIpPrefix of resource.
247+
### -Tag
248+
A hashtable which represents resource tags.
218249
219250
```yaml
220-
Type: CustomIpPrefix
251+
Type: System.Collections.Hashtable
221252
Parameter Sets: (All)
222253
Aliases:
223254

@@ -232,7 +263,7 @@ Accept wildcard characters: False
232263
A list of availability zones denoting the IP allocated for the resource needs to come from.
233264
234265
```yaml
235-
Type: String[]
266+
Type: System.String[]
236267
Parameter Sets: (All)
237268
Aliases:
238269

@@ -247,7 +278,7 @@ Accept wildcard characters: False
247278
Prompts you for confirmation before running the cmdlet.
248279
249280
```yaml
250-
Type: SwitchParameter
281+
Type: System.Management.Automation.SwitchParameter
251282
Parameter Sets: (All)
252283
Aliases: cf
253284

@@ -263,7 +294,7 @@ Shows what would happen if the cmdlet runs.
263294
The cmdlet is not run.
264295
265296
```yaml
266-
Type: SwitchParameter
297+
Type: System.Management.Automation.SwitchParameter
267298
Parameter Sets: (All)
268299
Aliases: wi
269300

0 commit comments

Comments
 (0)