Skip to content

Commit 80944f2

Browse files
Fix lb scenarios, avoid clearning child resource ids during error
1 parent 2908b5b commit 80944f2

11 files changed

+33
-61
lines changed

src/ResourceManager/Network/Commands.Network/LoadBalancer/ChildResourceHelper.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
using System;
1616
using Microsoft.Azure.Commands.Network.Models;
17-
using MNM = Microsoft.Azure.Management.Network.Models;
1817

1918
namespace Microsoft.Azure.Commands.Network
2019
{
@@ -67,14 +66,14 @@ private static string NormalizeId(string id, string resourceName, string resourc
6766
return id.Replace(orignalString, string.Format("/{0}/", resourceValue));
6867
}
6968

70-
public static void NormalizeChildResourcesId(PSLoadBalancer loadBalancer)
69+
public static void NormalizeChildResourcesId(PSLoadBalancer loadBalancer, string subscriptionId)
7170
{
7271
// Normalize LoadBalancingRules
7372
if (loadBalancer.LoadBalancingRules != null)
7473
{
7574
foreach (var loadBalancingRule in loadBalancer.LoadBalancingRules)
7675
{
77-
loadBalancingRule.Id = string.Empty;
76+
loadBalancingRule.Id = GetResourceId(subscriptionId, loadBalancer.ResourceGroupName, loadBalancer.Name, Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerRuleName, loadBalancingRule.Name);
7877

7978
if (loadBalancingRule.FrontendIPConfiguration != null)
8079
{
@@ -110,7 +109,7 @@ public static void NormalizeChildResourcesId(PSLoadBalancer loadBalancer)
110109
{
111110
foreach (var inboundNatRule in loadBalancer.InboundNatRules)
112111
{
113-
inboundNatRule.Id = string.Empty;
112+
inboundNatRule.Id = GetResourceId(subscriptionId, loadBalancer.ResourceGroupName, loadBalancer.Name, Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerInBoundNatRuleName, inboundNatRule.Name);
114113

115114
if (inboundNatRule.FrontendIPConfiguration != null)
116115
{
@@ -128,7 +127,7 @@ public static void NormalizeChildResourcesId(PSLoadBalancer loadBalancer)
128127
{
129128
foreach (var inboundNatPool in loadBalancer.InboundNatPools)
130129
{
131-
inboundNatPool.Id = string.Empty;
130+
inboundNatPool.Id = GetResourceId(subscriptionId, loadBalancer.ResourceGroupName, loadBalancer.Name, Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerInboundNatPoolName, inboundNatPool.Name);
132131

133132
if (inboundNatPool.FrontendIPConfiguration != null)
134133
{
@@ -146,7 +145,7 @@ public static void NormalizeChildResourcesId(PSLoadBalancer loadBalancer)
146145
{
147146
foreach (var frontendIpConfig in loadBalancer.FrontendIpConfigurations)
148147
{
149-
frontendIpConfig.Id = string.Empty;
148+
frontendIpConfig.Id = GetResourceId(subscriptionId, loadBalancer.ResourceGroupName, loadBalancer.Name, Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerFrontendIpConfigName, frontendIpConfig.Name);
150149
}
151150
}
152151

@@ -155,7 +154,7 @@ public static void NormalizeChildResourcesId(PSLoadBalancer loadBalancer)
155154
{
156155
foreach (var probe in loadBalancer.Probes)
157156
{
158-
probe.Id = string.Empty;
157+
probe.Id = GetResourceId(subscriptionId, loadBalancer.ResourceGroupName, loadBalancer.Name, Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerProbeName, probe.Name);
159158
}
160159
}
161160

@@ -164,7 +163,7 @@ public static void NormalizeChildResourcesId(PSLoadBalancer loadBalancer)
164163
{
165164
foreach (var backendAddressPool in loadBalancer.BackendAddressPools)
166165
{
167-
backendAddressPool.Id = string.Empty;
166+
backendAddressPool.Id = GetResourceId(subscriptionId, loadBalancer.ResourceGroupName, loadBalancer.Name, Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerBackendAddressPoolName, backendAddressPool.Name);
168167
}
169168
}
170169
}

src/ResourceManager/Network/Commands.Network/LoadBalancer/FrontendIpConfiguration/AddAzureLoadBalancerFrontendIpConfigCommand.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,6 @@ public override void ExecuteCmdlet()
4545
throw new ArgumentException("FrontendIpConfiguration with the specified name already exists");
4646
}
4747

48-
// Get the subnetId and publicIpAddressId from the object if specified
49-
if (string.Equals(ParameterSetName, "SetByResource"))
50-
{
51-
this.SubnetId = this.Subnet.Id;
52-
53-
if (PublicIpAddress != null)
54-
{
55-
this.PublicIpAddressId = this.PublicIpAddress.Id;
56-
}
57-
}
58-
5948
var frontendIpConfig = new PSFrontendIPConfiguration();
6049
frontendIpConfig.Name = this.Name;
6150

src/ResourceManager/Network/Commands.Network/LoadBalancer/FrontendIpConfiguration/AzureLoadBalancerFrontendIpConfigBase.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,46 @@ public class AzureLoadBalancerFrontendIpConfigBase : NetworkBaseCmdlet
2727

2828
[Parameter(
2929
Mandatory = false,
30+
ParameterSetName = "SetByResourceSubnet",
31+
HelpMessage = "The private ip address of the frontendIpConfiguration " +
32+
"if static allocation is specified.")]
33+
[Parameter(
34+
Mandatory = false,
35+
ParameterSetName = "SetByResourceIdSubnet",
3036
HelpMessage = "The private ip address of the frontendIpConfiguration " +
3137
"if static allocation is specified.")]
3238
public string PrivateIpAddress { get; set; }
3339

3440
[Parameter(
35-
ParameterSetName = "SetByResourceId",
41+
Mandatory = true,
42+
ParameterSetName = "SetByResourceIdSubnet",
3643
HelpMessage = "SubnetId")]
3744
[ValidateNotNullOrEmpty]
3845
public string SubnetId { get; set; }
3946

4047
[Parameter(
41-
ParameterSetName = "SetByResource",
48+
Mandatory = true,
49+
ParameterSetName = "SetByResourceSubnet",
4250
HelpMessage = "Subnet")]
4351
public PSSubnet Subnet { get; set; }
4452

4553
[Parameter(
46-
ParameterSetName = "SetByResourceId",
54+
Mandatory = true,
55+
ParameterSetName = "SetByResourceIdPublicIpAddress",
4756
HelpMessage = "PublicIpAddressId")]
4857
public string PublicIpAddressId { get; set; }
4958

5059
[Parameter(
51-
ParameterSetName = "SetByResource",
60+
Mandatory = true,
61+
ParameterSetName = "SetByResourcePublicIpAddress",
5262
HelpMessage = "PublicIpAddress")]
5363
public PSPublicIpAddress PublicIpAddress { get; set; }
5464

5565
public override void ExecuteCmdlet()
5666
{
5767
base.ExecuteCmdlet();
5868

59-
if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource))
69+
if (!ParameterSetName.Contains(Microsoft.Azure.Commands.Network.Properties.Resources.SetByResourceId))
6070
{
6171
if (this.Subnet != null)
6272
{

src/ResourceManager/Network/Commands.Network/LoadBalancer/FrontendIpConfiguration/NewAzureLoadBalancerFrontendIpConfigCommand.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@ public override void ExecuteCmdlet()
3030
{
3131
base.ExecuteCmdlet();
3232

33-
// Get the subnetId and publicIpAddressId from the object if specified
34-
if (string.Equals(ParameterSetName, "SetByResource"))
35-
{
36-
this.SubnetId = this.Subnet.Id;
37-
38-
if (PublicIpAddress != null)
39-
{
40-
this.PublicIpAddressId = this.PublicIpAddress.Id;
41-
}
42-
}
43-
4433
var frontendIpConfig = new PSFrontendIPConfiguration();
4534
frontendIpConfig.Name = this.Name;
4635

src/ResourceManager/Network/Commands.Network/LoadBalancer/FrontendIpConfiguration/SetAzureLoadBalancerFrontendIpConfigCommand.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,9 @@ public override void ExecuteCmdlet()
4545
throw new ArgumentException("FrontendIpConfiguration with the specified name does not exist");
4646
}
4747

48-
49-
// Get the subnetId and publicIpAddressId from the object if specified
50-
if (string.Equals(ParameterSetName, "id"))
51-
{
52-
this.SubnetId = this.Subnet.Id;
53-
54-
if (PublicIpAddress != null)
55-
{
56-
this.PublicIpAddressId = this.PublicIpAddress.Id;
57-
}
58-
}
59-
6048
frontendIpConfig.Name = this.Name;
6149

50+
frontendIpConfig.Subnet = null;
6251
if (!string.IsNullOrEmpty(this.SubnetId))
6352
{
6453
frontendIpConfig.Subnet = new PSSubnet();
@@ -80,13 +69,6 @@ public override void ExecuteCmdlet()
8069
frontendIpConfig.PrivateIpAddress = this.PrivateIpAddress;
8170
}
8271

83-
frontendIpConfig.Subnet = null;
84-
if (!string.IsNullOrEmpty(this.SubnetId))
85-
{
86-
frontendIpConfig.Subnet = new PSSubnet();
87-
frontendIpConfig.Subnet.Id = this.SubnetId;
88-
}
89-
9072
frontendIpConfig.PublicIpAddress = null;
9173
if (!string.IsNullOrEmpty(this.PublicIpAddressId))
9274
{

src/ResourceManager/Network/Commands.Network/LoadBalancer/InboundNatPool/AddAzureLoadBalancerInboundNatPoolConfigCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public override void ExecuteCmdlet()
6363
this.NetworkClient.NetworkManagementClient.SubscriptionId,
6464
this.LoadBalancer.ResourceGroupName,
6565
this.LoadBalancer.Name,
66-
Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerInboundNatPoolsName,
66+
Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerInboundNatPoolName,
6767
this.Name);
6868

6969
this.LoadBalancer.InboundNatPools.Add(inboundNatPool);

src/ResourceManager/Network/Commands.Network/LoadBalancer/InboundNatPool/NewAzureLoadBalancerInboundNatPoolConfigCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public override void ExecuteCmdlet()
4747
inboundNatPool.Id =
4848
ChildResourceHelper.GetResourceNotSetId(
4949
this.NetworkClient.NetworkManagementClient.SubscriptionId,
50-
Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerInboundNatPoolsName,
50+
Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerInboundNatPoolName,
5151
this.Name);
5252

5353
WriteObject(inboundNatPool);

src/ResourceManager/Network/Commands.Network/LoadBalancer/NewAzureLoadBalancerCommand.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ private PSLoadBalancer CreateLoadBalancer()
163163
loadBalancer.InboundNatPools = this.InboundNatPool;
164164
}
165165

166+
loadBalancer.ResourceGroupName = this.ResourceGroupName;
167+
loadBalancer.Name = this.Name;
168+
166169
// Normalize the IDs
167-
ChildResourceHelper.NormalizeChildResourcesId(loadBalancer);
170+
ChildResourceHelper.NormalizeChildResourcesId(loadBalancer, this.NetworkClient.NetworkManagementClient.SubscriptionId);
168171

169172
// Map to the sdk object
170173
var lbModel = Mapper.Map<MNM.LoadBalancer>(loadBalancer);

src/ResourceManager/Network/Commands.Network/LoadBalancer/SetAzureLoadBalancerCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public override void ExecuteCmdlet()
4242
}
4343

4444
// Normalize the IDs
45-
ChildResourceHelper.NormalizeChildResourcesId(this.LoadBalancer);
45+
ChildResourceHelper.NormalizeChildResourcesId(this.LoadBalancer, this.NetworkClient.NetworkManagementClient.SubscriptionId);
4646

4747
// Map to the sdk object
4848
var lbModel = Mapper.Map<MNM.LoadBalancer>(this.LoadBalancer);

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

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

src/ResourceManager/Network/Commands.Network/Properties/Resources.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
<data name="SetByIP" xml:space="preserve">
217217
<value>SetByIP</value>
218218
</data>
219-
<data name="LoadBalancerInboundNatPoolsName" xml:space="preserve">
219+
<data name="LoadBalancerInboundNatPoolName" xml:space="preserve">
220220
<value>inboundNatPools</value>
221221
</data>
222222
<data name="ApplicationGatewayProbeName" xml:space="preserve">

0 commit comments

Comments
 (0)