Skip to content

Commit 0febfe2

Browse files
authored
Merge pull request Azure#360 from Azure/net440fix
Fixes for NIC and NSG
2 parents f4c7296 + 74805d9 commit 0febfe2

File tree

6 files changed

+67
-4
lines changed

6 files changed

+67
-4
lines changed

src/ResourceManager/Network/Commands.Network/NetworkInterface/NetworkInterfaceBaseCmdlet.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ public PSNetworkInterface GetScaleSetNetworkInterface(string resourceGroupName,
7777
return psNetworkInterface;
7878
}
7979

80+
public void NullifyApplicationSecurityGroupIfAbsent(NetworkInterface nic)
81+
{
82+
if (nic == null || nic.IpConfigurations == null)
83+
{
84+
return;
85+
}
86+
87+
// Temporary - to be removed
88+
foreach (var ipconfigModel in nic.IpConfigurations)
89+
{
90+
if (ipconfigModel.ApplicationSecurityGroups != null && ipconfigModel.ApplicationSecurityGroups.Count == 0)
91+
{
92+
ipconfigModel.ApplicationSecurityGroups = null;
93+
}
94+
}
95+
}
96+
8097
public PSNetworkInterface ToPsNetworkInterface(NetworkInterface nic)
8198
{
8299
var psNic = Mapper.Map<PSNetworkInterface>(nic);

src/ResourceManager/Network/Commands.Network/NetworkInterface/NewAzureNetworkInterfaceCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,9 @@ private PSNetworkInterface CreateNetworkInterface()
419419

420420
var networkInterfaceModel = Mapper.Map<MNM.NetworkInterface>(networkInterface);
421421

422-
networkInterfaceModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
422+
this.NullifyApplicationSecurityGroupIfAbsent(networkInterfaceModel);
423+
424+
networkInterfaceModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
423425

424426
this.NetworkInterfaceClient.CreateOrUpdate(this.ResourceGroupName, this.Name, networkInterfaceModel);
425427

src/ResourceManager/Network/Commands.Network/NetworkInterface/SetAzureNetworkInterfaceCommand.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public override void Execute()
5252

5353
// Map to the sdk object
5454
var networkInterfaceModel = Mapper.Map<MNM.NetworkInterface>(this.NetworkInterface);
55-
networkInterfaceModel.Tags = TagsConversionHelper.CreateTagDictionary(this.NetworkInterface.Tag, validate: true);
55+
56+
this.NullifyApplicationSecurityGroupIfAbsent(networkInterfaceModel);
57+
58+
networkInterfaceModel.Tags = TagsConversionHelper.CreateTagDictionary(this.NetworkInterface.Tag, validate: true);
5659

5760
this.NetworkInterfaceClient.CreateOrUpdate(this.NetworkInterface.ResourceGroupName, this.NetworkInterface.Name, networkInterfaceModel);
5861

src/ResourceManager/Network/Commands.Network/NetworkSecurityGroup/NetworkSecurityGroupBaseCmdlet.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
1919
using Microsoft.Azure.Management.Network;
2020
using System.Net;
21+
using System.Collections;
22+
using System.Collections.Generic;
2123
using Microsoft.Azure.Management.Network.Models;
2224

2325
namespace Microsoft.Azure.Commands.Network
@@ -64,6 +66,39 @@ public PSNetworkSecurityGroup GetNetworkSecurityGroup(string resourceGroupName,
6466
return psNetworkSecurityGroup;
6567
}
6668

69+
// Temporary - to be removed
70+
public void NullifyApplicationSecurityGroupsIfAbsent(NetworkSecurityGroup nsg)
71+
{
72+
if (nsg == null)
73+
{
74+
return;
75+
}
76+
77+
this.NullifyApplicationSecurityRulesIfAbsent(nsg.DefaultSecurityRules);
78+
this.NullifyApplicationSecurityRulesIfAbsent(nsg.SecurityRules);
79+
}
80+
81+
public void NullifyApplicationSecurityRulesIfAbsent(IList<SecurityRule> rules)
82+
{
83+
if (rules == null)
84+
{
85+
return;
86+
}
87+
88+
foreach (var rule in rules)
89+
{
90+
if (rule.SourceApplicationSecurityGroups != null && rule.SourceApplicationSecurityGroups.Count == 0)
91+
{
92+
rule.SourceApplicationSecurityGroups = null;
93+
}
94+
95+
if (rule.DestinationApplicationSecurityGroups != null && rule.DestinationApplicationSecurityGroups.Count == 0)
96+
{
97+
rule.DestinationApplicationSecurityGroups = null;
98+
}
99+
}
100+
}
101+
67102
public PSNetworkSecurityGroup ToPsNetworkSecurityGroup(NetworkSecurityGroup nsg)
68103
{
69104
var psNsg = Mapper.Map<PSNetworkSecurityGroup>(nsg);

src/ResourceManager/Network/Commands.Network/NetworkSecurityGroup/NewAzureNetworkSecurityGroupCommand.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ private PSNetworkSecurityGroup CreateNetworkSecurityGroup()
9494

9595
// Map to the sdk object
9696
var nsgModel = Mapper.Map<MNM.NetworkSecurityGroup>(nsg);
97-
nsgModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
97+
98+
this.NullifyApplicationSecurityGroupsIfAbsent(nsgModel);
99+
100+
nsgModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
98101

99102
// Execute the Create NetworkSecurityGroup call
100103
this.NetworkSecurityGroupClient.CreateOrUpdate(this.ResourceGroupName, this.Name, nsgModel);

src/ResourceManager/Network/Commands.Network/NetworkSecurityGroup/SetAzureNetworkSecurityGroupCommand.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ public override void Execute()
4242

4343
// Map to the sdk object
4444
var nsgModel = Mapper.Map<MNM.NetworkSecurityGroup>(this.NetworkSecurityGroup);
45-
nsgModel.Tags = TagsConversionHelper.CreateTagDictionary(this.NetworkSecurityGroup.Tag, validate: true);
45+
46+
this.NullifyApplicationSecurityGroupsIfAbsent(nsgModel);
47+
48+
nsgModel.Tags = TagsConversionHelper.CreateTagDictionary(this.NetworkSecurityGroup.Tag, validate: true);
4649

4750
// Execute the PUT NetworkSecurityGroup call
4851
this.NetworkSecurityGroupClient.CreateOrUpdate(this.NetworkSecurityGroup.ResourceGroupName, this.NetworkSecurityGroup.Name, nsgModel);

0 commit comments

Comments
 (0)