Skip to content

Commit f333fc8

Browse files
authored
Merge pull request #359 from DeepakRajendranMsft/NicHotFix
Nic, Nsg - ASG reference hot fix
2 parents 087cd3a + d00bb8f commit f333fc8

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,28 @@ public PSNetworkSecurityGroup GetNetworkSecurityGroup(string resourceGroupName,
6464
return psNetworkSecurityGroup;
6565
}
6666

67+
// Temporary - to be removed
68+
public void NullifyApplicationSecurityGroupsIfAbsent(NetworkSecurityGroup nsg)
69+
{
70+
if (nsg ==null || nsg.SecurityRules == null)
71+
{
72+
return;
73+
}
74+
75+
foreach (var rule in nsg.SecurityRules)
76+
{
77+
if (rule.SourceApplicationSecurityGroups != null && rule.SourceApplicationSecurityGroups.Count == 0)
78+
{
79+
rule.SourceApplicationSecurityGroups = null;
80+
}
81+
82+
if (rule.DestinationApplicationSecurityGroups != null && rule.DestinationApplicationSecurityGroups.Count == 0)
83+
{
84+
rule.DestinationApplicationSecurityGroups = null;
85+
}
86+
}
87+
}
88+
6789
public PSNetworkSecurityGroup ToPsNetworkSecurityGroup(NetworkSecurityGroup nsg)
6890
{
6991
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)