Exemple #1
0
        /// <summary>
        /// The create InputObject.
        /// </summary>
        /// <returns>
        /// The <see cref="PSDirectConnection"/>.
        /// </returns>
        /// <exception cref="Exception">
        /// </exception>
        private PSDirectConnection CreateDirectPeering()
        {
            var peeringRequest = new PSDirectConnection
            {
                BandwidthInMbps        = this.BandwidthInMbps,
                PeeringDBFacilityId    = this.PeeringDBFacilityId,
                ConnectionIdentifier   = Guid.NewGuid().ToString(),
                SessionAddressProvider = this.MicrosoftProvidedIPAddress ? Constants.Microsoft : Constants.Peer,
                UseForPeeringService   = this.UseForPeeringService,
                BgpSession             = null
            };

            if (!this.MicrosoftProvidedIPAddress && !string.IsNullOrEmpty(this.SessionPrefixV4) || !string.IsNullOrEmpty(this.SessionPrefixV6))
            {
                peeringRequest.BgpSession = new PSBgpSession
                {
                    MaxPrefixesAdvertisedV4 = !string.IsNullOrEmpty(this.SessionPrefixV4) ? (this.MaxPrefixesAdvertisedIPv4 ?? 20000) : (int?)null,
                    MaxPrefixesAdvertisedV6 = !string.IsNullOrEmpty(this.SessionPrefixV6) ? (this.MaxPrefixesAdvertisedIPv6 ?? 2000) : (int?)null,
                    SessionPrefixV4         = this.ValidatePrefix(this.SessionPrefixV4?.Trim()),
                    SessionPrefixV6         = this.ValidatePrefix(this.SessionPrefixV6?.Trim()),
                    Md5AuthenticationKey    = this.MD5AuthenticationKey
                };
            }

            if (this.IsValidConnection(peeringRequest))
            {
                return(peeringRequest);
            }
            throw new PSArgumentException(string.Format(Resources.Error_InvalidConnection));
        }
Exemple #2
0
        /// <summary>
        /// The create InputObject.
        /// </summary>
        /// <returns>
        /// The <see cref="PSDirectConnection"/>.
        /// </returns>
        /// <exception cref="Exception">
        /// </exception>
        private PSDirectConnection CreateDirectPeering()
        {
            var peeringRequest = new PSDirectConnection
            {
                BandwidthInMbps      = this.BandwidthInMbps,
                PeeringDBFacilityId  = this.PeeringDBFacilityId,
                ConnectionIdentifier = Guid.NewGuid().ToString(),
                BgpSession           = new PSBgpSession
                {
                    MaxPrefixesAdvertisedV4 = !string.IsNullOrEmpty(this.SessionPrefixV4) ? (this.MaxPrefixesAdvertisedIPv4 ?? 20000) : (int?)null,
                    MaxPrefixesAdvertisedV6 = !string.IsNullOrEmpty(this.SessionPrefixV6) ? (this.MaxPrefixesAdvertisedIPv6 ?? 2000) : (int?)null,
                    SessionPrefixV4         =
                        this.ValidatePrefix(
                            this.SessionPrefixV4,
                            Constants.Direct),
                    SessionPrefixV6 =
                        this.ValidatePrefix(
                            this.SessionPrefixV6,
                            Constants.Direct),
                    Md5AuthenticationKey = this.MD5AuthenticationKey
                }
            };

            if (this.IsValidConnection(peeringRequest))
            {
                return(peeringRequest);
            }
            throw new PSArgumentException(string.Format(Resources.Error_InvalidConnection));
        }
        /// <inheritdoc />
        /// <summary>
        ///     The base execute operation.
        /// </summary>
        public override void Execute()
        {
            try
            {
                base.Execute();
                PSDirectConnection newRequest = null;
                if (this.ParameterSetName.Equals(
                        Constants.ParameterSetNameIPv4Prefix,
                        StringComparison.OrdinalIgnoreCase))
                {
                    newRequest = this.UpdateIpV4Prefix();
                }
                else if (this.ParameterSetName.Equals(
                             Constants.ParameterSetNameIPv6Prefix,
                             StringComparison.OrdinalIgnoreCase))
                {
                    newRequest = this.UpdateIpV6Prefix();
                }
                else if (this.ParameterSetName.Equals(
                             Constants.ParameterSetNameBandwidth,
                             StringComparison.OrdinalIgnoreCase))
                {
                    newRequest = this.UpdatePeeringOffer();
                }
                else if (this.ParameterSetName.Equals(
                             Constants.ParameterSetNameMd5Authentication,
                             StringComparison.OrdinalIgnoreCase))
                {
                    newRequest = this.UpdateMD5Authentication();
                }
                else if (this.ParameterSetName.Equals(Constants.ParameterSetNameUseForPeeringService, StringComparison.InvariantCultureIgnoreCase))
                {
                    newRequest = this.UpdateUseForPeeringService();
                }

                this.WriteObject(newRequest);
            }
            catch (InvalidOperationException mapException)
            {
                throw new InvalidOperationException(string.Format(Resources.Error_Mapping, mapException));
            }
            catch (ErrorResponseException ex)
            {
                var error = this.GetErrorCodeAndMessageFromArmOrErm(ex);
                throw new ErrorResponseException(string.Format(Resources.Error_CloudError, error.Code, error.Message));
            }
        }
Exemple #4
0
        /// <inheritdoc />
        /// <summary>
        ///     The base execute operation.
        /// </summary>
        public override void Execute()
        {
            try
            {
                base.Execute();
                PSDirectConnection newRequest = null;
                if (this.ParameterSetName.Equals(
                        Constants.ParameterSetNameIPv4Prefix,
                        StringComparison.OrdinalIgnoreCase))
                {
                    newRequest = this.UpdateIpV4Prefix();
                }
                else if (this.ParameterSetName.Equals(
                             Constants.ParameterSetNameIPv6Prefix,
                             StringComparison.OrdinalIgnoreCase))
                {
                    newRequest = this.UpdateIpV6Prefix();
                }
                else if (this.ParameterSetName.Equals(
                             Constants.ParameterSetNameBandwidth,
                             StringComparison.OrdinalIgnoreCase))
                {
                    newRequest = this.UpdatePeeringOffer();
                }
                else if (this.ParameterSetName.Equals(
                             Constants.ParameterSetNameMd5Authentication,
                             StringComparison.OrdinalIgnoreCase))
                {
                    newRequest = this.UpdateMD5Authentication();
                }

                this.WriteObject(newRequest);
            }
            catch (InvalidOperationException mapException)
            {
                throw new InvalidOperationException(string.Format(Resources.Error_Mapping, mapException));
            }
            catch (ErrorResponseException ex)
            {
                var error = ex.Response.Content.Contains("\"error\\\":") ? JsonConvert.DeserializeObject <Dictionary <string, ErrorResponse> >(JsonConvert.DeserializeObject(ex.Response.Content).ToString()).FirstOrDefault().Value : JsonConvert.DeserializeObject <ErrorResponse>(ex.Response.Content);
                throw new ErrorResponseException(string.Format(Resources.Error_CloudError, error.Code, error.Message));
            }
        }