コード例 #1
0
        /// <summary>
        /// The Update Bgp Peering operation updates an existing bgp peering or
        /// creates a new one if one doesn't exist.
        /// </summary>
        /// <param name='serviceKey'>
        /// The service key representing the relationship between Azure and the
        /// customer.
        /// </param>
        /// <param name='accessType'>
        /// Whether the peering is private or public.
        /// </param>
        /// <param name='parameters'>
        /// Parameters supplied to the Update Bgp Peering operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The Get Bgp Peering Operation Response.
        /// </returns>
        public async Task <BgpPeeringGetResponse> UpdateAsync(string serviceKey, BgpPeeringAccessType accessType, BgpPeeringUpdateParameters parameters, CancellationToken cancellationToken)
        {
            ExpressRouteManagementClient client = this.Client;
            bool   shouldTrace  = CloudContext.Configuration.Tracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = Tracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("serviceKey", serviceKey);
                tracingParameters.Add("accessType", accessType);
                tracingParameters.Add("parameters", parameters);
                Tracing.Enter(invocationId, this, "UpdateAsync", tracingParameters);
            }
            try
            {
                if (shouldTrace)
                {
                    client = this.Client.WithHandler(new ClientRequestTrackingHandler(invocationId));
                }

                cancellationToken.ThrowIfCancellationRequested();
                ExpressRouteOperationResponse originalResponse = await client.BgpPeering.BeginUpdateAsync(serviceKey, accessType, parameters, cancellationToken).ConfigureAwait(false);

                cancellationToken.ThrowIfCancellationRequested();
                ExpressRouteOperationStatusResponse result = await client.GetOperationStatusAsync(originalResponse.OperationId, cancellationToken).ConfigureAwait(false);

                int delayInSeconds = 30;
                while (result.Status == ExpressRouteOperationStatus.InProgress)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    await TaskEx.Delay(delayInSeconds * 1000, cancellationToken).ConfigureAwait(false);

                    cancellationToken.ThrowIfCancellationRequested();
                    result = await client.GetOperationStatusAsync(originalResponse.OperationId, cancellationToken).ConfigureAwait(false);

                    delayInSeconds = 10;
                }

                if (result.Status == ExpressRouteOperationStatus.Failed)
                {
                    string exStr = "The BGP peering could not be updated due to an internal server error.";
                    throw new ArgumentException(exStr);
                }
                cancellationToken.ThrowIfCancellationRequested();
                BgpPeeringGetResponse getResult = await client.BgpPeering.GetAsync(serviceKey, accessType, cancellationToken).ConfigureAwait(false);

                if (shouldTrace)
                {
                    Tracing.Exit(invocationId, result);
                }

                return(getResult);
            }
            finally
            {
                if (client != null && shouldTrace)
                {
                    client.Dispose();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// The Update Bgp Peering operation updates an existing bgp peering.
        /// </summary>
        /// <param name='serviceKey'>
        /// The service key representing the relationship between Azure and the
        /// customer.
        /// </param>
        /// <param name='accessType'>
        /// Whether the peering is private or public.
        /// </param>
        /// <param name='parameters'>
        /// Parameters supplied to the Update Bgp Peering operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// A standard express route gateway response including an HTTP status
        /// code and request ID.
        /// </returns>
        public async Task <ExpressRouteOperationResponse> BeginUpdateAsync(string serviceKey, BgpPeeringAccessType accessType, BgpPeeringUpdateParameters parameters, CancellationToken cancellationToken)
        {
            // Validate
            if (serviceKey == null)
            {
                throw new ArgumentNullException("serviceKey");
            }
            if (serviceKey.Length > 36)
            {
                throw new ArgumentOutOfRangeException("serviceKey");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            if (parameters.PrimaryPeerSubnet != null && parameters.PrimaryPeerSubnet.Length > 18)
            {
                throw new ArgumentOutOfRangeException("parameters.PrimaryPeerSubnet");
            }
            if (parameters.SecondaryPeerSubnet != null && parameters.SecondaryPeerSubnet.Length > 18)
            {
                throw new ArgumentOutOfRangeException("parameters.SecondaryPeerSubnet");
            }
            if (parameters.SharedKey != null && parameters.SharedKey.Length < 6)
            {
                throw new ArgumentOutOfRangeException("parameters.SharedKey");
            }
            if (parameters.SharedKey != null && parameters.SharedKey.Length > 24)
            {
                throw new ArgumentOutOfRangeException("parameters.SharedKey");
            }

            // Tracing
            bool   shouldTrace  = CloudContext.Configuration.Tracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = Tracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("serviceKey", serviceKey);
                tracingParameters.Add("accessType", accessType);
                tracingParameters.Add("parameters", parameters);
                Tracing.Enter(invocationId, this, "BeginUpdateAsync", tracingParameters);
            }

            // Construct URL
            string url = new Uri(this.Client.BaseUri, "/").ToString() + this.Client.Credentials.SubscriptionId + "/services/networking/dedicatedcircuits/" + serviceKey + "/bgppeerings/" + accessType + "?api-version=1.0";

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Put;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("x-ms-version", "2011-10-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Serialize Request
                string    requestContent = null;
                XDocument requestDoc     = new XDocument();

                XElement updateBgpPeeringElement = new XElement(XName.Get("UpdateBgpPeering", "http://schemas.microsoft.com/windowsazure"));
                requestDoc.Add(updateBgpPeeringElement);

                XElement peerAsnElement = new XElement(XName.Get("PeerAsn", "http://schemas.microsoft.com/windowsazure"));
                peerAsnElement.Value = parameters.PeerAsn.ToString();
                updateBgpPeeringElement.Add(peerAsnElement);

                if (parameters.PrimaryPeerSubnet != null)
                {
                    XElement primaryPeerSubnetElement = new XElement(XName.Get("PrimaryPeerSubnet", "http://schemas.microsoft.com/windowsazure"));
                    primaryPeerSubnetElement.Value = parameters.PrimaryPeerSubnet;
                    updateBgpPeeringElement.Add(primaryPeerSubnetElement);
                }

                if (parameters.SecondaryPeerSubnet != null)
                {
                    XElement secondaryPeerSubnetElement = new XElement(XName.Get("SecondaryPeerSubnet", "http://schemas.microsoft.com/windowsazure"));
                    secondaryPeerSubnetElement.Value = parameters.SecondaryPeerSubnet;
                    updateBgpPeeringElement.Add(secondaryPeerSubnetElement);
                }

                if (parameters.SharedKey != null)
                {
                    XElement sharedKeyElement = new XElement(XName.Get("SharedKey", "http://schemas.microsoft.com/windowsazure"));
                    sharedKeyElement.Value = parameters.SharedKey;
                    updateBgpPeeringElement.Add(sharedKeyElement);
                }

                XElement vlanIdElement = new XElement(XName.Get("VlanId", "http://schemas.microsoft.com/windowsazure"));
                vlanIdElement.Value = parameters.VlanId.ToString();
                updateBgpPeeringElement.Add(vlanIdElement);

                requestContent      = requestDoc.ToString();
                httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
                httpRequest.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xml");

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        Tracing.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        Tracing.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.Accepted)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false), CloudExceptionType.Xml);
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    ExpressRouteOperationResponse result = null;
                    // Deserialize Response
                    cancellationToken.ThrowIfCancellationRequested();
                    string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    result = new ExpressRouteOperationResponse();
                    XDocument responseDoc = XDocument.Parse(responseContent);

                    XElement gatewayOperationAsyncResponseElement = responseDoc.Element(XName.Get("GatewayOperationAsyncResponse", "http://schemas.microsoft.com/windowsazure"));
                    if (gatewayOperationAsyncResponseElement != null)
                    {
                        XElement idElement = gatewayOperationAsyncResponseElement.Element(XName.Get("ID", "http://schemas.microsoft.com/windowsazure"));
                        if (idElement != null)
                        {
                            string idInstance = idElement.Value;
                            result.OperationId = idInstance;
                        }
                    }

                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        Tracing.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// The Update Bgp Peering operation updates an existing bgp peering or
 /// creates a new one if one doesn't exist.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ExpressRoute.IBgpPeeringOperations.
 /// </param>
 /// <param name='serviceKey'>
 /// Required. The service key representing the relationship between
 /// Azure and the customer.
 /// </param>
 /// <param name='accessType'>
 /// Required. Whether the peering is private or public.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Update Bgp Peering operation.
 /// </param>
 /// <returns>
 /// The Get Bgp Peering Operation Response.
 /// </returns>
 public static BgpPeeringGetResponse Update(this IBgpPeeringOperations operations, string serviceKey, BgpPeeringAccessType accessType, BgpPeeringUpdateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IBgpPeeringOperations)s).UpdateAsync(serviceKey, accessType, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
コード例 #4
0
 /// <summary>
 /// The Update Bgp Peering operation updates an existing bgp peering or
 /// creates a new one if one doesn't exist.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ExpressRoute.IBgpPeeringOperations.
 /// </param>
 /// <param name='serviceKey'>
 /// Required. The service key representing the relationship between
 /// Azure and the customer.
 /// </param>
 /// <param name='accessType'>
 /// Required. Whether the peering is private or public.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Update Bgp Peering operation.
 /// </param>
 /// <returns>
 /// The Get Bgp Peering Operation Response.
 /// </returns>
 public static Task <BgpPeeringGetResponse> UpdateAsync(this IBgpPeeringOperations operations, string serviceKey, BgpPeeringAccessType accessType, BgpPeeringUpdateParameters parameters)
 {
     return(operations.UpdateAsync(serviceKey, accessType, parameters, CancellationToken.None));
 }
コード例 #5
0
 /// <summary>
 /// The Update Bgp Peering operation updates an existing bgp peering or
 /// creates a new one if one doesn't exist.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ExpressRoute.IBgpPeeringOperations.
 /// </param>
 /// <param name='serviceKey'>
 /// The service key representing the relationship between Azure and the
 /// customer.
 /// </param>
 /// <param name='accessType'>
 /// Whether the peering is private or public.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Update Bgp Peering operation.
 /// </param>
 /// <returns>
 /// The Get Bgp Peering Operation Response.
 /// </returns>
 public static BgpPeeringGetResponse Update(this IBgpPeeringOperations operations, string serviceKey, BgpPeeringAccessType accessType, BgpPeeringUpdateParameters parameters)
 {
     try
     {
         return(operations.UpdateAsync(serviceKey, accessType, parameters).Result);
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }