示例#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(Properties.Resources.ExpressRoutePrivatePeeringNotFound);
            }

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

            if (circuitconnection != null)
            {
                throw new ArgumentException(string.Format(Properties.Resources.ExpressRouteCircuitConnectionAlreadyAdded, Name));
            }

            circuitconnection = new PSExpressRouteCircuitConnection();

            circuitconnection.Name = this.Name;

            circuitconnection.ExpressRouteCircuitPeering    = new PSResourceId();
            circuitconnection.ExpressRouteCircuitPeering.Id = peering.Id;

            circuitconnection.PeerExpressRouteCircuitPeering    = new PSResourceId();
            circuitconnection.PeerExpressRouteCircuitPeering.Id = this.PeerExpressRouteCircuitPeering;

            if (!string.IsNullOrWhiteSpace(this.AuthorizationKey))
            {
                circuitconnection.AuthorizationKey = this.AuthorizationKey;
            }

            if (AddressTypeUtils.IsIpv6(this.AddressPrefixType))
            {
                // Create new PSExpressRouteIPv6AddressPrefix()
                var expressRouteIPv6AddressPrefix = new PSExpressRouteCircuitConnectionIPv6ConnectionConfig();
                expressRouteIPv6AddressPrefix.AddressPrefix   = AddressPrefix;
                circuitconnection.IPv6CircuitConnectionConfig = expressRouteIPv6AddressPrefix;
            }
            else
            {
                // For IPv4
                circuitconnection.AddressPrefix = this.AddressPrefix;
            }

            peering.Connections.Add(circuitconnection);

            WriteObject(this.ExpressRouteCircuit);
        }
        public override void Execute()
        {
            base.Execute();
            // Verify if the subnet exists in the VirtualNetwork
            var peering = this.ExpressRouteCircuit.Peerings.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (peering != null)
            {
                throw new ArgumentException("Peering with the specified name already exists");
            }


            if (string.Equals(ParameterSetName, ParamSetByRouteFilter))
            {
                if (this.RouteFilter != null)
                {
                    this.RouteFilterId = this.RouteFilter.Id;
                }
            }

            peering = new PSPeering();

            peering.Name        = this.Name;
            peering.PeeringType = this.PeeringType;
            peering.PeerASN     = this.PeerASN;
            peering.VlanId      = this.VlanId;


            if (!string.IsNullOrEmpty(this.SharedKey))
            {
                peering.SharedKey = this.SharedKey;
            }

            if (AddressTypeUtils.IsIpv6(this.PeerAddressType))
            {
                this.SetIpv6PeeringParameters(peering);
            }
            else
            {
                // Set IPv4 config even if no PeerAddresType has been specified for backward compatibility
                this.SetIpv4PeeringParameters(peering);
            }

            this.ConstructMicrosoftConfig(peering);

            this.ExpressRouteCircuit.Peerings.Add(peering);

            WriteObject(this.ExpressRouteCircuit);
        }
 public void ConstructMicrosoftConfig(PSPeering peering)
 {
     if (this.MicrosoftConfigAdvertisedPublicPrefixes != null && this.MicrosoftConfigAdvertisedPublicPrefixes.Any())
     {
         if (AddressTypeUtils.IsIpv6(this.PeerAddressType))
         {
             peering.Ipv6PeeringConfig.MicrosoftPeeringConfig = new PSPeeringConfig();
             peering.Ipv6PeeringConfig.MicrosoftPeeringConfig.AdvertisedPublicPrefixes = this.MicrosoftConfigAdvertisedPublicPrefixes?.ToList();
             peering.Ipv6PeeringConfig.MicrosoftPeeringConfig.CustomerASN         = this.MicrosoftConfigCustomerAsn;
             peering.Ipv6PeeringConfig.MicrosoftPeeringConfig.RoutingRegistryName = this.MicrosoftConfigRoutingRegistryName;
         }
         else
         {
             // Set IPv4 config even if no PeerAddresType has been specified for backward compatibility
             peering.MicrosoftPeeringConfig = new PSPeeringConfig();
             peering.MicrosoftPeeringConfig.AdvertisedPublicPrefixes = this.MicrosoftConfigAdvertisedPublicPrefixes?.ToList();
             peering.MicrosoftPeeringConfig.CustomerASN         = this.MicrosoftConfigCustomerAsn;
             peering.MicrosoftPeeringConfig.RoutingRegistryName = this.MicrosoftConfigRoutingRegistryName;
         }
     }
 }
示例#4
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);
        }
示例#5
0
        public override void Execute()
        {
            base.Execute();

            if (string.Equals(ParameterSetName, ParamSetByRouteFilter))
            {
                if (this.RouteFilter != null)
                {
                    this.RouteFilterId = this.RouteFilter.Id;
                }
            }

            var peering = new PSPeering();

            peering.Name        = this.Name;
            peering.PeeringType = this.PeeringType;
            peering.PeerASN     = this.PeerASN;
            peering.VlanId      = this.VlanId;

            if (!string.IsNullOrEmpty(this.SharedKey))
            {
                peering.SharedKey = this.SharedKey;
            }

            if (AddressTypeUtils.IsIpv6(this.PeerAddressType))
            {
                this.SetIpv6PeeringParameters(peering);
            }
            else
            {
                // Set IPv4 config even if no PeerAddresType has been specified for backward compatibility
                this.SetIpv4PeeringParameters(peering);
            }

            this.ConstructMicrosoftConfig(peering);

            WriteObject(peering);
        }
示例#6
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(Properties.Resources.ExpressRoutePrivatePeeringNotFound);
            }

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

            if (null == circuitconnection)
            {
                throw new ArgumentException(string.Format(Properties.Resources.ExpressRouteCircuitConnectionNotFound, Name));
            }

            circuitconnection.Name = this.Name;

            if (null != peering.Id)
            {
                circuitconnection.ExpressRouteCircuitPeering.Id = peering.Id;
            }

            if (null != this.PeerExpressRouteCircuitPeering)
            {
                circuitconnection.PeerExpressRouteCircuitPeering.Id = this.PeerExpressRouteCircuitPeering;
            }

            if (!string.IsNullOrWhiteSpace(this.AuthorizationKey))
            {
                circuitconnection.AuthorizationKey = this.AuthorizationKey;
            }

            if (this.AddressPrefix != null)
            {
                if (AddressTypeUtils.IsIpv6(this.AddressPrefixType))
                {
                    if (circuitconnection.IPv6CircuitConnectionConfig != null)
                    {
                        circuitconnection.IPv6CircuitConnectionConfig.AddressPrefix = this.AddressPrefix;
                    }
                    else
                    {
                        var ipv6AddressPrefix = new PSExpressRouteCircuitConnectionIPv6ConnectionConfig();
                        ipv6AddressPrefix.AddressPrefix = this.AddressPrefix;
                        circuitconnection.IPv6CircuitConnectionConfig = ipv6AddressPrefix;
                    }
                }
                else
                {
                    circuitconnection.AddressPrefix = this.AddressPrefix;
                }
            }

            WriteObject(this.ExpressRouteCircuit);
        } // end of Execute()
示例#7
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);
        }