示例#1
0
        public override void Execute()
        {
            base.Execute();

            var peering =
                this.ExpressRouteCircuit.Peerings.SingleOrDefault(
                    resource =>
                    string.Equals(resource.Name, "AzurePrivatePeering", System.StringComparison.CurrentCultureIgnoreCase));

            if (peering == null)
            {
                throw new ArgumentException("Private Peering does not exist on the Express Route Circuit");
            }

            var connection = peering.Connections.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (connection != null)
            {
                if ((string.IsNullOrWhiteSpace(this.AddressPrefixType) || AddressTypeUtils.IsIpv4(this.AddressPrefixType)) &&
                    connection.IPv6CircuitConnectionConfig != null)
                {
                    // call is to remove ipv4 and ipv6 exists
                    connection.AddressPrefix = null;
                }
                else if (AddressTypeUtils.IsIpv6(this.AddressPrefixType) && connection.AddressPrefix != null)
                {
                    // call is to remove ipv6 and ipv4 exists
                    connection.IPv6CircuitConnectionConfig = null;
                }
                else
                {
                    // remove ipv4 call and ipv6 gr is already null OR remove ipv6 call and ipv4 gr is already null OR remove all
                    peering.Connections.Remove(connection);
                }
            }

            WriteObject(this.ExpressRouteCircuit);
        }
示例#2
0
        public override void Execute()
        {
            base.Execute();
            var peering = this.ExpressRouteCircuit.Peerings.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (peering != null)
            {
                // When a PeerAddressType is specified, we need to check if the corresponding address family peering is present, else ignore
                // For example if the peering has only IPv4 properties set and the user tries to remove IPv6 address family peering, we can ignore the remove operation
                bool validateAddressFamilyPresent = true;

                if (peering.PeeringType == MNM.ExpressRoutePeeringType.MicrosoftPeering)
                {
                    if ((AddressTypeUtils.IsIpv4(this.PeerAddressType) && peering.MicrosoftPeeringConfig == null) ||
                        (AddressTypeUtils.IsIpv6(this.PeerAddressType) && (peering.Ipv6PeeringConfig == null || peering.Ipv6PeeringConfig.MicrosoftPeeringConfig == null)))
                    {
                        validateAddressFamilyPresent = false;
                    }

                    if (!validateAddressFamilyPresent)
                    {
                        // Peering config for specified address family is not present. No action
                        return;
                    }

                    if (peering.MicrosoftPeeringConfig != null && peering.Ipv6PeeringConfig != null)
                    {
                        // Both IPv4 and IPv6 peering configs are present. Only nullify the config corresponding to the address family specified
                        if (string.IsNullOrWhiteSpace(this.PeerAddressType) || AddressTypeUtils.IsIpv4(this.PeerAddressType))
                        {
                            peering.PrimaryPeerAddressPrefix   = null;
                            peering.SecondaryPeerAddressPrefix = null;
                            peering.RouteFilter            = null;
                            peering.MicrosoftPeeringConfig = null;
                        }
                        else if (AddressTypeUtils.IsIpv6(this.PeerAddressType))
                        {
                            peering.Ipv6PeeringConfig = null;
                        }
                        else if (AddressTypeUtils.IsAll(this.PeerAddressType))
                        {
                            this.ExpressRouteCircuit.Peerings.Remove(peering);
                        }
                    }
                    else
                    {
                        // Only one peering config exists. Removing that should result in the entire peering being removed
                        this.ExpressRouteCircuit.Peerings.Remove(peering);
                    }
                }

                else if (peering.PeeringType == MNM.ExpressRoutePeeringType.AzurePrivatePeering)
                {
                    if ((string.IsNullOrWhiteSpace(this.PeerAddressType) || AddressTypeUtils.IsIpv4(this.PeerAddressType)) &&
                        peering.Ipv6PeeringConfig != null)
                    {
                        // call is to remove ipv4 and ipv6 exists
                        peering.PrimaryPeerAddressPrefix   = null;
                        peering.SecondaryPeerAddressPrefix = null;
                    }
                    else if (AddressTypeUtils.IsIpv6(this.PeerAddressType) &&
                             !PeeringUtils.IsIpv4PrivatePeeringNull(peering))
                    {
                        // call is to remove ipv6 and ipv4 exists
                        peering.Ipv6PeeringConfig = null;
                    }
                    else
                    {
                        // remove ipv4 and ipv6 is null OR remove ipv6 and ipv4 is null OR remove all
                        this.ExpressRouteCircuit.Peerings.Remove(peering);
                    }
                }
                else
                {
                    // In case of Azure Public Peering
                    this.ExpressRouteCircuit.Peerings.Remove(peering);
                }
            }

            WriteObject(this.ExpressRouteCircuit);
        }