Skip to content

Commit c76b8a6

Browse files
authored
[nva] New Cmdlet: New-AzVirtualApplianceAdditionalNicProperty (#21633)
* New Cmdlet: New-AzVirtualApplianceAdditionalNicProperties * SupportsShouldProcess Added * Mapp CNM and MNM * Adding default Address Family, adding validate function * New-AzVirtualApplianceAdditionalNicProperties => New-AzVirtualApplianceAdditionalNicProperty * Fixes for additional nic scenario * Review Comments incorportated * Updating help * Array from NewNetworkVirtualApplianceCommand
1 parent 582d3cb commit c76b8a6

10 files changed

+276
-5
lines changed

src/Accounts/Accounts/Utilities/CommandMappings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4261,6 +4261,7 @@
42614261
"New-AzOffice365PolicyProperty": {},
42624262
"Get-AzNetworkVirtualApplianceSku": {},
42634263
"New-AzVirtualApplianceSkuProperty": {},
4264+
"New-AzVirtualApplianceAdditionalNicProperty": {},
42644265
"New-AzCustomIpPrefix": {},
42654266
"Update-AzCustomIpPrefix": {},
42664267
"Get-AzCustomIpPrefix": {},

src/Network/Network/Az.Network.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
560560
'Update-AzNetworkVirtualAppliance', 'Get-AzVirtualApplianceSite',
561561
'New-AzVirtualApplianceSite', 'Remove-AzVirtualApplianceSite',
562562
'Update-AzVirtualApplianceSite', 'New-AzOffice365PolicyProperty',
563-
'Get-AzNetworkVirtualApplianceSku',
563+
'Get-AzNetworkVirtualApplianceSku', 'New-AzVirtualApplianceAdditionalNicProperty',
564564
'New-AzVirtualApplianceSkuProperty', 'New-AzCustomIpPrefix',
565565
'Update-AzCustomIpPrefix', 'Get-AzCustomIpPrefix',
566566
'Remove-AzCustomIpPrefix', 'New-AzExpressRoutePortLOA',

src/Network/Network/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
- Also updated cmdlet to add the property of RateLimitDuration, RateLimitThreshold and GroupByUserSession
3939
- `New-AzureApplicationGatewayFirewallCustomRule`
4040
* Added support of `AdditionalNic` Property in New-AzNetworkVirtualAppliance
41+
* Added the new cmdlet for supporting `AdditionalNic` Property
42+
- 'New-AzVirtualApplianceAdditionalNicProperty'
4143

4244
## Version 5.6.0
4345
* Updated `New-AzLoadBalancer` and `Set-AzLoadBalancer` to validate surface level parameters for global tier load balancers

src/Network/Network/Common/NetworkResourceManagerProfile.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,8 @@ private static void Initialize()
15511551
cfg.CreateMap<CNM.PSVirtualApplianceSkuProperties, MNM.VirtualApplianceSkuProperties>();
15521552

15531553
// MNM to CNM
1554+
// Where CNM - models from Powershell
1555+
// MNM - models from Sdk
15541556
cfg.CreateMap<MNM.NetworkVirtualAppliance, CNM.PSNetworkVirtualAppliance>();
15551557
cfg.CreateMap<MNM.NetworkVirtualApplianceSku, CNM.PSNetworkVirtualApplianceSku>();
15561558
cfg.CreateMap<MNM.NetworkVirtualApplianceSkuInstances, CNM.PSNetworkVirtualApplianceSkuInstances>();
@@ -1559,6 +1561,7 @@ private static void Initialize()
15591561
cfg.CreateMap<MNM.VirtualApplianceNicProperties, CNM.PSVirtualApplianceNicProperties>();
15601562
cfg.CreateMap<MNM.VirtualApplianceSite, CNM.PSVirtualApplianceSite>();
15611563
cfg.CreateMap<MNM.VirtualApplianceSkuProperties, CNM.PSVirtualApplianceSkuProperties>();
1564+
cfg.CreateMap<MNM.VirtualApplianceAdditionalNicProperties, CNM.PSVirtualApplianceAdditionalNicProperties>();
15621565

15631566
// NetworkManager
15641567
// CNM to MNMs

src/Network/Network/Models/PSNetworkVirtualAppliance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ public class PSNetworkVirtualAppliance : PSTopLevelResource
4343

4444
public PSVirtualApplianceSkuProperties NvaSku { get; set; }
4545

46-
public IList<PSVirtualApplianceAdditionalNicProperties> VirtualApplianceAdditionalNics { get; set; }
46+
public IList<PSVirtualApplianceAdditionalNicProperties> AdditionalNics { get; set; }
4747
}
4848
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 System;
16+
using System.Collections.Generic;
17+
using System.Management.Automation;
18+
using Microsoft.Azure.Commands.Network.Models;
19+
20+
namespace Microsoft.Azure.Commands.Network
21+
{
22+
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VirtualApplianceAdditionalNicProperty",
23+
SupportsShouldProcess = true),
24+
OutputType(typeof(PSVirtualApplianceAdditionalNicProperties))]
25+
public class NewVirtualApplianceAdditionaNicPropertyCommand : VirtualApplianceAdditionalNicPropertiesBaseCmdlet
26+
{
27+
private const int NicNameValueMaxLength = 24;
28+
29+
[Parameter(
30+
Mandatory = true,
31+
ValueFromPipelineByPropertyName = false,
32+
HelpMessage = "The Name of Interface.")]
33+
[ValidateNotNullOrEmpty]
34+
public string NicName { get; set; }
35+
36+
[Parameter(
37+
Mandatory = true,
38+
ValueFromPipelineByPropertyName = false,
39+
HelpMessage = "Additional Interface to have public IP or not.")]
40+
[ValidateNotNullOrEmpty]
41+
public bool HasPublicIP { get; set; }
42+
43+
[Parameter(
44+
Mandatory = false,
45+
ValueFromPipelineByPropertyName = false,
46+
HelpMessage = "The Address Family for IP for Interface.")]
47+
[ValidateSet(
48+
IPv4,
49+
IPv6,
50+
IgnoreCase = true)]
51+
public string AddressFamily { get; set; }
52+
53+
public override void Execute()
54+
{
55+
base.Execute();
56+
57+
Validate();
58+
59+
var additionalNicProperty = new PSVirtualApplianceAdditionalNicProperties();
60+
additionalNicProperty.Name = this.NicName;
61+
additionalNicProperty.HasPublicIP = this.HasPublicIP;
62+
additionalNicProperty.AddressFamily = "IPv4";
63+
64+
var additionalNicProperties = new List<PSVirtualApplianceAdditionalNicProperties>
65+
{
66+
additionalNicProperty
67+
};
68+
69+
WriteObject(additionalNicProperties, true);
70+
}
71+
72+
private void Validate()
73+
{
74+
// validate name length
75+
if (this.NicName.Length > NicNameValueMaxLength)
76+
{
77+
throw new ArgumentException($"Nic Name length is limited to {NicNameValueMaxLength} characters.");
78+
}
79+
}
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
using System;
17+
using System.Collections.Generic;
18+
using System.Text;
19+
20+
namespace Microsoft.Azure.Commands.Network
21+
{
22+
public class VirtualApplianceAdditionalNicPropertiesBaseCmdlet : NetworkBaseCmdlet
23+
{
24+
// Empty class for future development of Get/Set/Update commands.
25+
}
26+
}

src/Network/Network/NetworkVirtualAppliance/NewNetworkVirtualApplianceCommand.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public class NewNetworkVirtualApplianceCommand : NetworkVirtualApplianceBaseCmdl
135135
ValueFromPipelineByPropertyName = true,
136136
HelpMessage = "The Additional Nic Properties of the Virtual Appliance.")]
137137
[ValidateNotNullOrEmpty]
138-
public IList<PSVirtualApplianceAdditionalNicProperties> AdditionalNic { get; set; }
138+
public PSVirtualApplianceAdditionalNicProperties[] AdditionalNic { get; set; }
139139

140140
public override void Execute()
141141
{
@@ -177,12 +177,15 @@ private PSNetworkVirtualAppliance CreateNetworkVirtualAppliance()
177177
networkVirtualAppliance.BootStrapConfigurationBlobs = this.BootStrapConfigurationBlob;
178178
networkVirtualAppliance.CloudInitConfigurationBlobs = this.CloudInitConfigurationBlob;
179179
networkVirtualAppliance.CloudInitConfiguration = this.CloudInitConfiguration;
180-
networkVirtualAppliance.VirtualApplianceAdditionalNics = this.AdditionalNic;
180+
if (AdditionalNic != null)
181+
{
182+
networkVirtualAppliance.AdditionalNics = AdditionalNic;
183+
}
181184

182185
var networkVirtualApplianceModel = NetworkResourceManagerProfile.Mapper.Map<MNM.NetworkVirtualAppliance>(networkVirtualAppliance);
183186

184187
networkVirtualApplianceModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
185-
188+
186189
this.NetworkVirtualAppliancesClient.CreateOrUpdate(this.ResourceGroupName, this.Name, networkVirtualApplianceModel);
187190

188191
var getNetworkVirtualAppliance = this.GetNetworkVirtualAppliance(this.ResourceGroupName, this.Name);

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,29 @@ The **New-AzNetworkVirtualAppliance** command creates a Network Virtual Applianc
3838
### Example 1
3939
```powershell
4040
$sku=New-AzVirtualApplianceSkuProperty -VendorName "barracudasdwanrelease" -BundledScaleUnit 1 -MarketPlaceVersion 'latest'
41+
4142
$hub=Get-AzVirtualHub -ResourceGroupName testrg -Name hub
43+
4244
$nva=New-AzNetworkVirtualAppliance -ResourceGroupName testrg -Name nva -Location eastus2 -VirtualApplianceAsn 1270 -VirtualHubId $hub.Id -Sku $sku -CloudInitConfiguration "echo Hello World!"
45+
4346
```
4447

4548
Creates a new Network Virtual Appliance resource in resource group: testrg.
4649

50+
### Example 2
51+
```powershell
52+
$sku=New-AzVirtualApplianceSkuProperty -VendorName "ciscosdwantest" -BundledScaleUnit 4 -MarketPlaceVersion '17.6.03'
53+
54+
$hub=Get-AzVirtualHub -ResourceGroupName testrg -Name hub
55+
56+
$additionalNic=New-AzVirtualApplianceAdditionalNicProperty -NicName "sdwan" -HasPublicIp $true
57+
58+
$nva=New-AzNetworkVirtualAppliance -ResourceGroupName testrg -Name nva -Location eastus2 -VirtualApplianceAsn 65222 -VirtualHubId $hub.Id -Sku $sku -CloudInitConfiguration "echo Hello World!" -AdditionalNic $additionalNic
59+
60+
```
61+
62+
Creates a new Network Virtual Appliance resource in resource group: testrg with additional nic "sdwan" and a public IP attached to "sdwan" nic.
63+
4764
## PARAMETERS
4865

4966
### -AsJob
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---
2+
external help file: Microsoft.Azure.PowerShell.Cmdlets.Network.dll-Help.xml
3+
Module Name: Az.Network
4+
online version: https://learn.microsoft.com/powershell/module/az.network/new-azvirtualapplianceadditionalnicproperty
5+
schema: 2.0.0
6+
---
7+
8+
# New-AzVirtualApplianceAdditionalNicProperty
9+
10+
## SYNOPSIS
11+
Define a Network Virtual Appliance Additional Nic Property for the resource.
12+
13+
## SYNTAX
14+
15+
```
16+
New-AzVirtualApplianceAdditionalNicProperty -NicName <String> -HasPublicIP <Boolean> [-AddressFamily <String>]
17+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
The New-AzVirtualApplianceAdditionalNicProperty command defines an Additional Nic Property for Network Virtual Appliance resource.
22+
23+
## EXAMPLES
24+
25+
### Example 1
26+
```powershell
27+
$var=New-AzVirtualApplianceAdditionalNicProperty -NicName "sdwan" -HasPublicIp $true
28+
```
29+
30+
Create an Additional Nic Property object to be used with New-AzNetworkVirtualAppliance command.
31+
32+
## PARAMETERS
33+
34+
### -AddressFamily
35+
The Address Family for IP for Interface.
36+
37+
```yaml
38+
Type: String
39+
Parameter Sets: (All)
40+
Aliases:
41+
Accepted values: IPv4, IPv6
42+
43+
Required: False
44+
Position: Named
45+
Default value: None
46+
Accept pipeline input: False
47+
Accept wildcard characters: False
48+
```
49+
50+
### -Confirm
51+
Prompts you for confirmation before running the cmdlet.
52+
53+
```yaml
54+
Type: SwitchParameter
55+
Parameter Sets: (All)
56+
Aliases: cf
57+
58+
Required: False
59+
Position: Named
60+
Default value: None
61+
Accept pipeline input: False
62+
Accept wildcard characters: False
63+
```
64+
65+
### -DefaultProfile
66+
The credentials, account, tenant, and subscription used for communication with Azure.
67+
68+
```yaml
69+
Type: IAzureContextContainer
70+
Parameter Sets: (All)
71+
Aliases: AzContext, AzureRmContext, AzureCredential
72+
73+
Required: False
74+
Position: Named
75+
Default value: None
76+
Accept pipeline input: False
77+
Accept wildcard characters: False
78+
```
79+
80+
### -HasPublicIP
81+
Additional Interface to have public IP or not.
82+
83+
```yaml
84+
Type: Boolean
85+
Parameter Sets: (All)
86+
Aliases:
87+
88+
Required: True
89+
Position: Named
90+
Default value: None
91+
Accept pipeline input: False
92+
Accept wildcard characters: False
93+
```
94+
95+
### -NicName
96+
The Name of Interface.
97+
98+
```yaml
99+
Type: String
100+
Parameter Sets: (All)
101+
Aliases:
102+
103+
Required: True
104+
Position: Named
105+
Default value: None
106+
Accept pipeline input: False
107+
Accept wildcard characters: False
108+
```
109+
110+
### -WhatIf
111+
Shows what would happen if the cmdlet runs. The cmdlet is not run.
112+
113+
```yaml
114+
Type: SwitchParameter
115+
Parameter Sets: (All)
116+
Aliases: wi
117+
118+
Required: False
119+
Position: Named
120+
Default value: None
121+
Accept pipeline input: False
122+
Accept wildcard characters: False
123+
```
124+
125+
### CommonParameters
126+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
127+
128+
## INPUTS
129+
130+
### None
131+
132+
## OUTPUTS
133+
134+
### Microsoft.Azure.Commands.Network.Models.PSVirtualApplianceAdditionalNicProperties
135+
136+
## NOTES
137+
138+
## RELATED LINKS

0 commit comments

Comments
 (0)