Skip to content

Commit b1a080a

Browse files
bugfix for remove cmdlet to delete config (#13655)
Co-authored-by: Abhinav Prakash <[email protected]>
1 parent ff33d07 commit b1a080a

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

src/Network/Network/ChangeLog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
--->
2020

2121
## Upcoming Release
22-
22+
* Bugfix in Remove peering and connection commandlet for ExpressrouteCircuit scenario
23+
- Remove-AzExpressRouteCircuitPeeringConfig and Remove-AzExpressRouteCircuitConnectionConfig
2324
## Version 4.3.0
2425
* Updated below cmdlet
2526
- `New-AzLoadBalancerFrontendIpConfigCommand`, `Set-AzLoadBalancerFrontendIpConfigCommand`, `Add-AzLoadBalancerFrontendIpConfigCommand`:

src/Network/Network/Common/Utils.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.Network.Models;
1516
using System;
1617

1718
namespace Microsoft.Azure.Commands.Network
@@ -45,4 +46,18 @@ public static bool IsAll(string addressType)
4546
return false;
4647
}
4748
}
49+
50+
public class PeeringUtils
51+
{
52+
public static bool IsIpv4PrivatePeeringNull(PSPeering privatePeering)
53+
{
54+
if (privatePeering == null ||
55+
(privatePeering.PrimaryPeerAddressPrefix == null &&
56+
privatePeering.SecondaryPeerAddressPrefix == null))
57+
{
58+
return true;
59+
}
60+
return false;
61+
}
62+
}
4863
}

src/Network/Network/ExpressRouteCircuit/Peering/Connection/RemoveAzureExpressRouteCircuitConnectionConfigCommand.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,20 @@ public override void Execute()
7070

7171
if (connection != null)
7272
{
73-
if (AddressTypeUtils.IsIpv4(this.AddressPrefixType) || string.IsNullOrWhiteSpace(this.AddressPrefixType))
73+
if ((string.IsNullOrWhiteSpace(this.AddressPrefixType) || AddressTypeUtils.IsIpv4(this.AddressPrefixType)) &&
74+
connection.IPv6CircuitConnectionConfig != null)
7475
{
76+
// call is to remove ipv4 and ipv6 exists
7577
connection.AddressPrefix = null;
7678
}
77-
78-
else if (AddressTypeUtils.IsIpv6(this.AddressPrefixType))
79+
else if (AddressTypeUtils.IsIpv6(this.AddressPrefixType) && connection.AddressPrefix != null)
7980
{
81+
// call is to remove ipv6 and ipv4 exists
8082
connection.IPv6CircuitConnectionConfig = null;
8183
}
82-
83-
else if (AddressTypeUtils.IsAll(this.AddressPrefixType))
84+
else
8485
{
86+
// remove ipv4 call and ipv6 gr is already null OR remove ipv6 call and ipv4 gr is already null OR remove all
8587
peering.Connections.Remove(connection);
8688
}
8789
}

src/Network/Network/ExpressRouteCircuit/Peering/RemoveAzureExpressRouteCircuitPeeringConfigCommand.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public override void Execute()
7575
if (peering.MicrosoftPeeringConfig != null && peering.Ipv6PeeringConfig != null)
7676
{
7777
// Both IPv4 and IPv6 peering configs are present. Only nullify the config corresponding to the address family specified
78-
if (AddressTypeUtils.IsIpv4(this.PeerAddressType) || string.IsNullOrWhiteSpace(this.PeerAddressType))
78+
if (string.IsNullOrWhiteSpace(this.PeerAddressType) || AddressTypeUtils.IsIpv4(this.PeerAddressType))
7979
{
8080
peering.PrimaryPeerAddressPrefix = null;
8181
peering.SecondaryPeerAddressPrefix = null;
@@ -100,21 +100,25 @@ public override void Execute()
100100

101101
else if (peering.PeeringType == MNM.ExpressRoutePeeringType.AzurePrivatePeering)
102102
{
103-
if (AddressTypeUtils.IsIpv4(this.PeerAddressType) || string.IsNullOrWhiteSpace(this.PeerAddressType))
103+
if ((string.IsNullOrWhiteSpace(this.PeerAddressType) || AddressTypeUtils.IsIpv4(this.PeerAddressType)) &&
104+
peering.Ipv6PeeringConfig != null)
104105
{
106+
// call is to remove ipv4 and ipv6 exists
105107
peering.PrimaryPeerAddressPrefix = null;
106108
peering.SecondaryPeerAddressPrefix = null;
107109
}
108-
else if (AddressTypeUtils.IsIpv6(this.PeerAddressType))
110+
else if (AddressTypeUtils.IsIpv6(this.PeerAddressType) &&
111+
!PeeringUtils.IsIpv4PrivatePeeringNull(peering))
109112
{
113+
// call is to remove ipv6 and ipv4 exists
110114
peering.Ipv6PeeringConfig = null;
111115
}
112-
else if (AddressTypeUtils.IsAll(this.PeerAddressType))
116+
else
113117
{
118+
// remove ipv4 and ipv6 is null OR remove ipv6 and ipv4 is null OR remove all
114119
this.ExpressRouteCircuit.Peerings.Remove(peering);
115120
}
116121
}
117-
118122
else
119123
{
120124
// In case of Azure Public Peering

0 commit comments

Comments
 (0)