Skip to content

Commit debf8f5

Browse files
author
Khushboo Baheti
committed
workingCode
1 parent 62a4325 commit debf8f5

14 files changed

+680
-4
lines changed

src/Network/Network/Az.Network.psd1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,11 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
534534
'New-AzVirtualApplianceSkuProperty', 'New-AzCustomIpPrefix',
535535
'Update-AzCustomIpPrefix', 'Get-AzCustomIpPrefix',
536536
'Remove-AzCustomIpPrefix', 'New-AzExpressRoutePortLOA',
537-
'New-AzO365PolicyProperty'
537+
'New-AzO365PolicyProperty',
538+
'Get-AzVirtualNetworkGatewayNatRule',
539+
'New-AzVirtualNetworkGatewayNatRule',
540+
'Update-AzVirtualNetworkGatewayNatRule',
541+
'Remove-AzVirtualNetworkGatewayNatRule'
538542

539543
# Variables to export from this module
540544
# VariablesToExport = @()

src/Network/Network/Common/NetworkResourceManagerProfile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,7 @@ private static void Initialize()
871871
cfg.CreateMap<CNM.PSGatewayRoute, MNM.GatewayRoute>();
872872
cfg.CreateMap<CNM.PSVpnClientConnectionHealthDetail, MNM.VpnClientConnectionHealthDetail>();
873873
cfg.CreateMap<CNM.PSIpConfigurationBgpPeeringAddress, MNM.IPConfigurationBgpPeeringAddress>();
874+
cfg.CreateMap<CNM.PSVirtualNetworkGatewayNatRule, MNM.VirtualNetworkGatewayNatRule>();
874875

875876
// MNM to CNM
876877
cfg.CreateMap<MNM.VirtualNetworkGateway, CNM.PSVirtualNetworkGateway>();
@@ -892,6 +893,7 @@ private static void Initialize()
892893
cfg.CreateMap<MNM.GatewayRoute, CNM.PSGatewayRoute>();
893894
cfg.CreateMap<MNM.VpnClientConnectionHealthDetail, CNM.PSVpnClientConnectionHealthDetail>();
894895
cfg.CreateMap<MNM.IPConfigurationBgpPeeringAddress, CNM.PSIpConfigurationBgpPeeringAddress>();
896+
cfg.CreateMap<MNM.VirtualNetworkGatewayNatRule, CNM.PSVirtualNetworkGatewayNatRule>();
895897

896898
// Application Gateways
897899
// CNM to MNM

src/Network/Network/Models/PSVirtualNetworkGateway.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class PSVirtualNetworkGateway : PSTopLevelResource
5252

5353
public string VpnGatewayGeneration { get; set; }
5454

55+
public List<PSVirtualNetworkGatewayNatRule> NatRules { get; set; }
56+
5557
[JsonIgnore]
5658
public string IpConfigurationsText
5759
{
@@ -82,6 +84,12 @@ public string BgpSettingsText
8284
get { return JsonConvert.SerializeObject(BgpSettings, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
8385
}
8486

87+
[JsonIgnore]
88+
public string NatRulesText
89+
{
90+
get { return JsonConvert.SerializeObject(NatRules, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
91+
}
92+
8593
[JsonIgnore]
8694
public string CustomRoutesText
8795
{
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
namespace Microsoft.Azure.Commands.Network.Models
16+
{
17+
using System.Collections.Generic;
18+
using Microsoft.WindowsAzure.Commands.Common.Attributes;
19+
using Newtonsoft.Json;
20+
21+
public class PSVirtualNetworkGatewayNatRule : PSChildResource
22+
{
23+
[Ps1Xml(Label = "VirtualNetworkGatewayNatRuleType", Target = ViewControl.Table)]
24+
public string VirtualNetworkGatewayNatRulePropertiesType { get; set; }
25+
26+
[Ps1Xml(Label = "Mode", Target = ViewControl.Table)]
27+
public string Mode { get; set; }
28+
29+
public List<PSVpnNatRuleMapping> InternalMappings { get; set; }
30+
31+
public List<PSVpnNatRuleMapping> ExternalMappings { get; set; }
32+
33+
[Ps1Xml(Label = "IpConfigurationId", Target = ViewControl.Table)]
34+
public string IpConfigurationId { get; set; }
35+
36+
[Ps1Xml(Label = "Provisioning State", Target = ViewControl.Table)]
37+
public string ProvisioningState { get; set; }
38+
39+
[JsonIgnore]
40+
public string InternalMappingsText
41+
{
42+
get { return JsonConvert.SerializeObject(InternalMappings, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
43+
}
44+
45+
[JsonIgnore]
46+
public string ExternalMappingsText
47+
{
48+
get { return JsonConvert.SerializeObject(ExternalMappings, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
49+
}
50+
}
51+
}

src/Network/Network/Network.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="AutoMapper" Version="6.2.2" />
17-
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.4.0" />
17+
<PackageReference Include="Microsoft.Azure.Management.Network" Version="330.2247.36274" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

src/Network/Network/Properties/Resources.Designer.cs

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Network/Network/VirtualNetwork/Peering/AddAzureVirtualNetworkPeeringCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private PSVirtualNetworkPeering AddVirtualNetworkPeering()
112112
var vnetPeeringModel = NetworkResourceManagerProfile.Mapper.Map<MNM.VirtualNetworkPeering>(vnetPeering);
113113

114114
// Execute the Create VirtualNetwork call
115-
this.VirtualNetworkPeeringClient.CreateOrUpdateWithHttpMessagesAsync(this.VirtualNetwork.ResourceGroupName, this.VirtualNetwork.Name, this.Name, vnetPeeringModel, auxAuthHeader).GetAwaiter().GetResult();
115+
this.VirtualNetworkPeeringClient.CreateOrUpdateWithHttpMessagesAsync(this.VirtualNetwork.ResourceGroupName, this.VirtualNetwork.Name, this.Name, vnetPeeringModel, null, auxAuthHeader).GetAwaiter().GetResult();
116116
var getVirtualNetworkPeering = this.GetVirtualNetworkPeering(this.VirtualNetwork.ResourceGroupName, this.VirtualNetwork.Name, this.Name);
117117

118118
return getVirtualNetworkPeering;

src/Network/Network/VirtualNetwork/Peering/SetAzureVirtualNetworkPeeringCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public override void Execute()
6161
}
6262

6363
// Execute the Create VirtualNetwork call
64-
this.VirtualNetworkPeeringClient.CreateOrUpdateWithHttpMessagesAsync(this.VirtualNetworkPeering.ResourceGroupName, this.VirtualNetworkPeering.VirtualNetworkName, this.VirtualNetworkPeering.Name, vnetPeeringModel, auxAuthHeader).GetAwaiter().GetResult();
64+
this.VirtualNetworkPeeringClient.CreateOrUpdateWithHttpMessagesAsync(this.VirtualNetworkPeering.ResourceGroupName, this.VirtualNetworkPeering.VirtualNetworkName, this.VirtualNetworkPeering.Name, vnetPeeringModel, null, auxAuthHeader).GetAwaiter().GetResult();
6565

6666
var getVirtualNetworkPeering = this.GetVirtualNetworkPeering(this.VirtualNetworkPeering.ResourceGroupName, this.VirtualNetworkPeering.VirtualNetworkName, this.VirtualNetworkPeering.Name);
6767

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
// http://www.apache.org/licenses/LICENSE-2.0
5+
// Unless required by applicable law or agreed to in writing, software
6+
// distributed under the License is distributed on an "AS IS" BASIS,
7+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8+
// See the License for the specific language governing permissions and
9+
// limitations under the License.
10+
// ----------------------------------------------------------------------------------
11+
namespace Microsoft.Azure.Commands.Network.VirtualNetworkGateway
12+
{
13+
using System;
14+
using System.Management.Automation;
15+
using Microsoft.Azure.Commands.Network.Models;
16+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
17+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
18+
19+
[Cmdlet(VerbsCommon.Get,
20+
ResourceManager.Common.AzureRMConstants.AzurePrefix + "VirtualNetworkGatewayNatRule",
21+
DefaultParameterSetName = VirtualNetworkGatewayParameterSets.ByVirtualNetworkGatewayName),
22+
OutputType(typeof(PSVirtualNetworkGatewayNatRule))]
23+
public class GetAzureVirtualNetworkGatewayNatRule : VirtualNetworkGatewayNatRuleBaseCmdlet
24+
{
25+
[Parameter(
26+
Mandatory = true,
27+
ParameterSetName = VirtualNetworkGatewayParameterSets.ByVirtualNetworkGatewayName,
28+
HelpMessage = "The resource group name.")]
29+
[ResourceGroupCompleter]
30+
[ValidateNotNullOrEmpty]
31+
public string ResourceGroupName { get; set; }
32+
33+
[Alias("ParentVirtualNetworkGatewayName", "VirtualNetworkGatewayName")]
34+
[Parameter(
35+
Mandatory = true,
36+
ParameterSetName = VirtualNetworkGatewayParameterSets.ByVirtualNetworkGatewayName,
37+
HelpMessage = "The parent resource name.")]
38+
[ResourceNameCompleter("Microsoft.Network/virtualNetworkGateways", "ResourceGroupName")]
39+
[ValidateNotNullOrEmpty]
40+
public string ParentResourceName { get; set; }
41+
42+
[Alias("ParentVirtualNetworkGateway", "VirtualNetworkGateway")]
43+
[Parameter(
44+
Mandatory = true,
45+
ValueFromPipeline = true,
46+
ParameterSetName = VirtualNetworkGatewayParameterSets.ByVirtualNetworkGatewayObject,
47+
HelpMessage = "The parent VirtualNetworkGateway for this VirtualNetworkGatewayNatRule.")]
48+
[ValidateNotNullOrEmpty]
49+
public PSVirtualNetworkGateway ParentObject { get; set; }
50+
51+
[Alias("ParentVirtualNetworkGatewayId", "VirtualNetworkGatewayId")]
52+
[Parameter(
53+
Mandatory = true,
54+
ValueFromPipelineByPropertyName = true,
55+
ParameterSetName = VirtualNetworkGatewayParameterSets.ByVirtualNetworkGatewayResourceId,
56+
HelpMessage = "The resource id of the parent VirtualNetworkGateway for this VirtualNetworkGatewayNatRule.")]
57+
[ValidateNotNullOrEmpty]
58+
[ResourceIdCompleter("Microsoft.Network/virtualNetworkGateways")]
59+
public string ParentResourceId { get; set; }
60+
61+
[Alias("ResourceName", "VirtualNetworkGatewayNatRuleName")]
62+
[Parameter(
63+
Mandatory = false,
64+
HelpMessage = "The resource name.")]
65+
[ResourceNameCompleter("Microsoft.Network/virtualNetworkGateways/natRules", "ResourceGroupName", "ParentResourceName")]
66+
[ValidateNotNullOrEmpty]
67+
[SupportsWildcards]
68+
public string Name { get; set; }
69+
70+
public override void Execute()
71+
{
72+
base.Execute();
73+
74+
if (ParameterSetName.Equals(VirtualNetworkGatewayParameterSets.ByVirtualNetworkGatewayObject, StringComparison.OrdinalIgnoreCase))
75+
{
76+
this.ResourceGroupName = this.ParentObject.ResourceGroupName;
77+
this.ParentResourceName = this.ParentObject.Name;
78+
}
79+
else if (ParameterSetName.Equals(VirtualNetworkGatewayParameterSets.ByVirtualNetworkGatewayResourceId, StringComparison.OrdinalIgnoreCase))
80+
{
81+
var parsedResourceId = new ResourceIdentifier(this.ParentResourceId);
82+
this.ResourceGroupName = parsedResourceId.ResourceGroupName;
83+
this.ParentResourceName = parsedResourceId.ResourceName;
84+
}
85+
86+
if (ShouldGetByName(ResourceGroupName, Name))
87+
{
88+
WriteObject(this.GetVirtualNetworkGatewayNatRule(this.ResourceGroupName, this.ParentResourceName, this.Name));
89+
}
90+
else
91+
{
92+
WriteObject(SubResourceWildcardFilter(Name, this.ListVirtualNetworkGatewayNatRules(this.ResourceGroupName, this.ParentResourceName)), true);
93+
}
94+
}
95+
}
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
// http://www.apache.org/licenses/LICENSE-2.0
5+
// Unless required by applicable law or agreed to in writing, software
6+
// distributed under the License is distributed on an "AS IS" BASIS,
7+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8+
// See the License for the specific language governing permissions and
9+
// limitations under the License.
10+
// ----------------------------------------------------------------------------------
11+
12+
namespace Microsoft.Azure.Commands.Network.VirtualNetworkGateway
13+
{
14+
using System;
15+
using System.Collections.Generic;
16+
using System.Management.Automation;
17+
using Microsoft.Azure.Commands.Network.Models;
18+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
19+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
20+
using MNM = Microsoft.Azure.Management.Network.Models;
21+
22+
[Cmdlet(VerbsCommon.New,
23+
ResourceManager.Common.AzureRMConstants.AzurePrefix + "VirtualNetworkGatewayNatRule",
24+
DefaultParameterSetName = VirtualNetworkGatewayParameterSets.ByVirtualNetworkGatewayNatRuleName),
25+
OutputType(typeof(PSVirtualNetworkGatewayNatRule))]
26+
public class NewAzureVirtualNetworkGatewayNatRule : VirtualNetworkGatewayNatRuleBaseCmdlet
27+
{
28+
[Alias("ResourceName", "VirtualNetworkGatewayNatRuleName")]
29+
[Parameter(
30+
Mandatory = true,
31+
ParameterSetName = VirtualNetworkGatewayParameterSets.ByVirtualNetworkGatewayNatRuleName,
32+
HelpMessage = "The resource name.")]
33+
[ValidateNotNullOrEmpty]
34+
public string Name { get; set; }
35+
36+
[Parameter(
37+
Mandatory = true,
38+
HelpMessage = "The type of NAT rule for VPN NAT")]
39+
[ValidateSet(
40+
MNM.VpnNatRuleType.Static,
41+
MNM.VpnNatRuleType.Dynamic,
42+
IgnoreCase = true)]
43+
public string Type { get; set; }
44+
45+
[Parameter(
46+
Mandatory = true,
47+
HelpMessage = "The Source NAT direction of a VPN NAT")]
48+
[ValidateSet(
49+
MNM.VpnNatRuleMode.EgressSnat,
50+
MNM.VpnNatRuleMode.IngressSnat,
51+
IgnoreCase = true)]
52+
public string Mode { get; set; }
53+
54+
[Parameter(
55+
Mandatory = true,
56+
HelpMessage = "The list of private IP address subnet internal mappings for NAT")]
57+
public string[] InternalMapping { get; set; }
58+
59+
[Parameter(
60+
Mandatory = true,
61+
HelpMessage = "The list of private IP address subnet external mappings for NAT")]
62+
public string[] ExternalMapping { get; set; }
63+
64+
[Parameter(
65+
Mandatory = false,
66+
HelpMessage = "The IP Configuration ID this NAT rule applies to")]
67+
public string IpConfigurationId { get; set; }
68+
69+
[Parameter(
70+
Mandatory = false,
71+
HelpMessage = "Run cmdlet in the background")]
72+
public SwitchParameter AsJob { get; set; }
73+
74+
public override void Execute()
75+
{
76+
base.Execute();
77+
78+
WriteObject(this.CreateVpnGatewayNatRule());
79+
}
80+
81+
private PSVirtualNetworkGatewayNatRule CreateVpnGatewayNatRule()
82+
{
83+
PSVirtualNetworkGatewayNatRule gatewayNatRule = new PSVirtualNetworkGatewayNatRule
84+
{
85+
Name = this.Name,
86+
Mode = this.Mode,
87+
VirtualNetworkGatewayNatRulePropertiesType = this.Type,
88+
InternalMappings = new List<PSVpnNatRuleMapping>(),
89+
ExternalMappings = new List<PSVpnNatRuleMapping>(),
90+
IpConfigurationId = this.IpConfigurationId,
91+
};
92+
93+
if (this.InternalMapping != null)
94+
{
95+
foreach (string internalMappingSubnet in this.InternalMapping)
96+
{
97+
var internalMapping = new PSVpnNatRuleMapping();
98+
internalMapping.AddressSpace = internalMappingSubnet;
99+
gatewayNatRule.InternalMappings.Add(internalMapping);
100+
}
101+
}
102+
103+
if (this.ExternalMapping != null)
104+
{
105+
foreach (string externalMappingSubnet in this.ExternalMapping)
106+
{
107+
var externalMapping = new PSVpnNatRuleMapping();
108+
externalMapping.AddressSpace = externalMappingSubnet;
109+
gatewayNatRule.ExternalMappings.Add(externalMapping);
110+
}
111+
}
112+
113+
return gatewayNatRule;
114+
}
115+
}
116+
}

0 commit comments

Comments
 (0)