Skip to content

Commit 4951b85

Browse files
Add support saas nva cmdlet (#22836)
* add saas nva cmdlet * add help file * update changelog file * correct formatting * Update ChangeLog.md --------- Co-authored-by: Yabo Hu <[email protected]>
1 parent 879c842 commit 4951b85

File tree

7 files changed

+418
-0
lines changed

7 files changed

+418
-0
lines changed

src/Network/Network/Az.Network.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
568568
'New-AzOffice365PolicyProperty', 'Get-AzNetworkVirtualApplianceSku',
569569
'New-AzVirtualApplianceAdditionalNicProperty',
570570
'New-AzVirtualApplianceSkuProperty', 'New-AzCustomIpPrefix',
571+
'New-AzSaaSNetworkVirtualAppliance',
571572
'Update-AzCustomIpPrefix', 'Get-AzCustomIpPrefix',
572573
'Remove-AzCustomIpPrefix', 'New-AzExpressRoutePortLOA',
573574
'New-AzO365PolicyProperty', 'Get-AzVirtualNetworkGatewayNatRule',

src/Network/Network/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Onboarded `Microsoft.EventGrid/namespaces` to private link cmdlets
2727
* Fixed bug in `NewAzureApplicationGatewayFirewallCustomRuleGroupByVariable` to add "GeoLocation" as a valid input for VariableName
2828
* Added breaking change message for parameter `VariableName` in `NewAzureApplicationGatewayFirewallCustomRuleGroupByVariable` to remove "Geo" as a valid input.
29+
* Added cmdlet `New-AzSaaSNetworkVirtualAppliance` for creating a NetworkVirtualAppliance of SaaS type.
2930

3031
## Version 6.1.1
3132
* Onboarded `Microsoft.ElasticSan/elasticSans` to private link cmdlets

src/Network/Network/Common/NetworkResourceManagerProfile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,7 @@ private static void Initialize()
15701570
cfg.CreateMap<CNM.PSVirtualApplianceSite, MNM.VirtualApplianceSite>();
15711571
cfg.CreateMap<CNM.PSVirtualApplianceSkuProperties, MNM.VirtualApplianceSkuProperties>();
15721572
cfg.CreateMap<CNM.PSNetworkVirtualApplianceConnection, MNM.NetworkVirtualApplianceConnection>();
1573+
cfg.CreateMap<CNM.PSNetworkVirtualApplianceDelegationProperties, MNM.DelegationProperties>();
15731574

15741575
// MNM to CNM
15751576
// Where CNM - models from Powershell
@@ -1584,6 +1585,7 @@ private static void Initialize()
15841585
cfg.CreateMap<MNM.VirtualApplianceSkuProperties, CNM.PSVirtualApplianceSkuProperties>();
15851586
cfg.CreateMap<MNM.VirtualApplianceAdditionalNicProperties, CNM.PSVirtualApplianceAdditionalNicProperties>();
15861587
cfg.CreateMap<MNM.NetworkVirtualApplianceConnection,CNM.PSNetworkVirtualApplianceConnection>();
1588+
cfg.CreateMap<MNM.DelegationProperties, CNM.PSNetworkVirtualApplianceDelegationProperties>();
15871589

15881590
// NetworkManager
15891591
// CNM to MNMs

src/Network/Network/Models/PSNetworkVirtualAppliance.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@ public class PSNetworkVirtualAppliance : PSTopLevelResource
4646
public PSVirtualApplianceSkuProperties NvaSku { get; set; }
4747

4848
public IList<PSVirtualApplianceAdditionalNicProperties> AdditionalNics { get; set; }
49+
50+
public PSNetworkVirtualApplianceDelegationProperties Delegation { get; set; }
4951
}
5052
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
namespace Microsoft.Azure.Commands.Network.Models
17+
{
18+
public class PSNetworkVirtualApplianceDelegationProperties : PSTopLevelResource
19+
{
20+
21+
public string ServiceName { get; set; }
22+
public string ProvisioningState { get; set; }
23+
24+
public PSNetworkVirtualApplianceDelegationProperties() { }
25+
26+
public PSNetworkVirtualApplianceDelegationProperties(string serviceName)
27+
{
28+
this.ServiceName = serviceName;
29+
}
30+
}
31+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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 Microsoft.Azure.Commands.Network.Models;
17+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
18+
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
19+
using Microsoft.Azure.Management.Network;
20+
using System;
21+
using System.Collections;
22+
using System.Collections.Generic;
23+
using System.Management.Automation;
24+
using System.Management.Automation.Remoting;
25+
using System.Text;
26+
using MNM = Microsoft.Azure.Management.Network.Models;
27+
28+
namespace Microsoft.Azure.Commands.Network
29+
{
30+
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SaaSNetworkVirtualAppliance", SupportsShouldProcess = true, DefaultParameterSetName = ResourceNameParameterSet), OutputType(typeof(PSNetworkVirtualAppliance))]
31+
public class NewSaaSNetworkVirtualApplianceCommand : NetworkVirtualApplianceBaseCmdlet
32+
{
33+
private const string ResourceNameParameterSet = "ResourceNameParameterSet";
34+
private const string ResourceIdParameterSet = "ResourceIdParameterSet";
35+
36+
[Alias("ResourceName")]
37+
[Parameter(
38+
Mandatory = true,
39+
ValueFromPipelineByPropertyName = true,
40+
ParameterSetName = ResourceNameParameterSet,
41+
HelpMessage = "The resource name.")]
42+
[ValidateNotNullOrEmpty]
43+
public virtual string Name { get; set; }
44+
45+
[Parameter(
46+
Mandatory = true,
47+
ValueFromPipelineByPropertyName = true,
48+
ParameterSetName = ResourceNameParameterSet,
49+
HelpMessage = "The resource group name.")]
50+
[ResourceGroupCompleter]
51+
[ValidateNotNullOrEmpty]
52+
public virtual string ResourceGroupName { get; set; }
53+
54+
[Parameter(
55+
Mandatory = true,
56+
ValueFromPipelineByPropertyName = true,
57+
ParameterSetName = ResourceIdParameterSet,
58+
HelpMessage = "The resource Id.")]
59+
[ValidateNotNullOrEmpty]
60+
public virtual string ResourceId { get; set; }
61+
62+
[Parameter(
63+
Mandatory = true,
64+
ValueFromPipelineByPropertyName = true,
65+
HelpMessage = "The SaaS NVA location.")]
66+
[ValidateNotNullOrEmpty]
67+
public string Location { get; set; }
68+
69+
[Parameter(
70+
Mandatory = true,
71+
ValueFromPipelineByPropertyName = true,
72+
HelpMessage = "The Resource Id of the Virtual Hub.")]
73+
[ValidateNotNullOrEmpty]
74+
public string VirtualHubId { get; set; }
75+
76+
[Parameter(
77+
Mandatory = false,
78+
ValueFromPipelineByPropertyName = true,
79+
HelpMessage = "A hashtable which represents resource tags.")]
80+
public Hashtable Tag { get; set; }
81+
82+
[Parameter(
83+
Mandatory = false,
84+
HelpMessage = "Do not ask for confirmation if you want to overwrite a resource")]
85+
public SwitchParameter Force { get; set; }
86+
87+
[Parameter(
88+
Mandatory = false,
89+
HelpMessage = "Run cmdlet in the background")]
90+
public SwitchParameter AsJob { get; set; }
91+
92+
[Parameter(
93+
Mandatory = true,
94+
ValueFromPipelineByPropertyName = true,
95+
HelpMessage = "The delegated service name")]
96+
[ValidateNotNullOrEmpty]
97+
public string DelegatedServiceName { get; set; }
98+
99+
100+
public override void Execute()
101+
{
102+
base.Execute();
103+
if (ParameterSetName.Equals(ResourceIdParameterSet))
104+
{
105+
this.ResourceGroupName = GetResourceGroup(this.ResourceId);
106+
this.Name = GetResourceName(this.ResourceId, "Microsoft.Network/networkVirtualAppliances");
107+
}
108+
var present = this.IsNetworkVirtualAppliancePresent(this.ResourceGroupName, this.Name);
109+
ConfirmAction(
110+
Force.IsPresent,
111+
string.Format(Properties.Resources.OverwritingResource, Name),
112+
Properties.Resources.CreatingResourceMessage,
113+
Name,
114+
() =>
115+
{
116+
var nva = CreateNetworkVirtualAppliance();
117+
if (present)
118+
{
119+
nva = this.GetNetworkVirtualAppliance(this.ResourceGroupName, this.Name);
120+
}
121+
WriteObject(nva);
122+
},
123+
() => present);
124+
}
125+
126+
private PSNetworkVirtualAppliance CreateNetworkVirtualAppliance()
127+
{
128+
var networkVirtualAppliance = new PSNetworkVirtualAppliance();
129+
networkVirtualAppliance.Name = this.Name;
130+
networkVirtualAppliance.Location = this.Location;
131+
networkVirtualAppliance.VirtualHub = new PSResourceId();
132+
networkVirtualAppliance.VirtualHub.Id = this.VirtualHubId;
133+
networkVirtualAppliance.Delegation = new PSNetworkVirtualApplianceDelegationProperties(this.DelegatedServiceName);
134+
var networkVirtualApplianceModel = NetworkResourceManagerProfile.Mapper.Map<MNM.NetworkVirtualAppliance>(networkVirtualAppliance);
135+
networkVirtualApplianceModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
136+
this.NetworkVirtualAppliancesClient.CreateOrUpdate(this.ResourceGroupName, this.Name, networkVirtualApplianceModel);
137+
var getNetworkVirtualAppliance = this.GetNetworkVirtualAppliance(this.ResourceGroupName, this.Name);
138+
return getNetworkVirtualAppliance;
139+
}
140+
}
141+
}

0 commit comments

Comments
 (0)