Esempio n. 1
0
        private bool TryHandleBeginNewAsync(IServiceOperations <ExpressRouteManagementClient> client,
                                            IDictionary <string, object> parameters, out Action undoFunction)
        {
            undoFunction = null;
            string serviceKey;
            CrossConnectionUpdateParameters updateParameters = new CrossConnectionUpdateParameters()
            {
                Operation = UpdateCrossConnectionOperation.NotifyCrossConnectionNotProvisioned
            };

            if (TryAssignParameter <string>("serviceKey", parameters, out serviceKey) &&
                !string.IsNullOrEmpty(serviceKey))
            {
                undoFunction = () =>
                {
                    using (ExpressRouteManagementClient expressRouteClient = GetClientFromOperations(client))
                    {
                        expressRouteClient.CrossConnections.Update(serviceKey, updateParameters);
                    }
                };
                return(true);
            }

            TraceParameterError(this, "BeginNewAsync", parameters);
            return(false);
        }
        public void CanCreateGetListAndUpdateCrossConnnections()
        {
            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();
                var customerExpressRouteClient = GetCustomerExpressRouteManagementClient();
                var providerExpressRouteClient = GetProviderExpressRouteManagementClient();
                var provider =
                    customerExpressRouteClient.DedicatedCircuitServiceProviders.List()
                                              .Single(
                                                  p =>
                                                  p.Name.Equals(GetProviderName(),
                                                                StringComparison.CurrentCultureIgnoreCase));
                var location = provider.DedicatedCircuitLocations.Split(',').First();
                var bandwidth = provider.DedicatedCircuitBandwidths[4].Bandwidth;
                var circuitName = TestUtilities.GenerateName("circuit");
                var newCircuitParams = new DedicatedCircuitNewParameters()
                    {
                        Bandwidth = bandwidth,
                        CircuitName = circuitName,
                        Location = location,
                        ServiceProviderName = provider.Name
                    };
                var newResponse = customerExpressRouteClient.DedicatedCircuits.New(newCircuitParams);
                TestUtilities.ValidateOperationResponse(newResponse);
                Guid serviceKey;
                Assert.True(Guid.TryParse(newResponse.Data, out serviceKey));
                
                newResponse = providerExpressRouteClient.CrossConnections.New(serviceKey.ToString());
                TestUtilities.ValidateOperationResponse(newResponse);

                CrossConnectionGetResponse getResponse =
                    providerExpressRouteClient.CrossConnections.Get(serviceKey.ToString());
                
                TestUtilities.ValidateOperationResponse(getResponse);
                Assert.Equal((uint) getResponse.CrossConnection.Bandwidth, bandwidth);
                Assert.Equal(getResponse.CrossConnection.Status, DedicatedCircuitState.Enabled.ToString());
                Assert.Equal(getResponse.CrossConnection.ProvisioningState,
                             ProviderProvisioningState.Provisioning.ToString());
                CrossConnectionListResponse listResponse = providerExpressRouteClient.CrossConnections.List();
                Assert.NotEmpty(listResponse.CrossConnections[0].ServiceKey);

                var updateParams = new CrossConnectionUpdateParameters()
                    {
                        Operation = UpdateCrossConnectionOperation.NotifyCrossConnectionProvisioned,
                        ProvisioningError = ""
                    };
                var updateResponse = providerExpressRouteClient.CrossConnections.Update(serviceKey.ToString(),
                                                                                        updateParams);

              

            }
        }
        public void CanCreateAndGetDedicatedCircuitLink()
        {
            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();
                var customerExpressRouteClient = GetCustomerExpressRouteManagementClient();
                var provider =
                    customerExpressRouteClient.DedicatedCircuitServiceProviders.List()
                    .Single(
                        p =>
                        p.Name.Equals(GetProviderName(),
                                      StringComparison.CurrentCultureIgnoreCase));
                var location         = provider.DedicatedCircuitLocations.Split(',').First();
                var bandwidth        = provider.DedicatedCircuitBandwidths.First().Bandwidth;
                var circuitName      = TestUtilities.GenerateName("circuit");
                var newCircuitParams = new DedicatedCircuitNewParameters()
                {
                    Bandwidth           = bandwidth,
                    CircuitName         = circuitName,
                    Location            = location,
                    ServiceProviderName = provider.Name
                };
                var newResponse = customerExpressRouteClient.DedicatedCircuits.New(newCircuitParams);
                TestUtilities.ValidateOperationResponse(newResponse);
                Guid serviceKey;
                Assert.True(Guid.TryParse(newResponse.Data, out serviceKey));
                var providerExpressRouteClient = GetProviderExpressRouteManagementClient();
                newResponse = providerExpressRouteClient.CrossConnections.New(serviceKey.ToString());
                TestUtilities.ValidateOperationResponse(newResponse);

                CrossConnectionGetResponse getResponse =
                    providerExpressRouteClient.CrossConnections.Get(serviceKey.ToString());
                TestUtilities.ValidateOperationResponse(getResponse);
                Assert.Equal((uint)getResponse.CrossConnection.Bandwidth, bandwidth);
                Assert.Equal(getResponse.CrossConnection.Status, DedicatedCircuitState.Enabled.ToString());
                Assert.Equal(getResponse.CrossConnection.ProvisioningState,
                             ProviderProvisioningState.Provisioning.ToString());

                var updateParams = new CrossConnectionUpdateParameters()
                {
                    Operation         = UpdateCrossConnectionOperation.NotifyCrossConnectionProvisioned,
                    ProvisioningError = ""
                };
                var updateResponse = providerExpressRouteClient.CrossConnections.Update(serviceKey.ToString(),
                                                                                        updateParams);
                TestUtilities.ValidateOperationResponse(updateResponse);

                newResponse = customerExpressRouteClient.DedicatedCircuitLinks.New(serviceKey.ToString(), GetVNetName());
                TestUtilities.ValidateOperationResponse(newResponse);
            }
        }
Esempio n. 4
0
        public AzureCrossConnection SetAzureCrossConnection(Guid serviceKey,
                                                            CrossConnectionUpdateParameters parameters)
        {
            var result = Client.CrossConnections.Update(serviceKey.ToString(), parameters);

            if (result.HttpStatusCode.Equals(HttpStatusCode.OK))
            {
                return(GetAzureCrossConnection(serviceKey));
            }
            else
            {
                throw new Exception(result.Error.ToString());
            }
        }
Esempio n. 5
0
        /// <summary>
        /// The Update Cross Connection operation updates an existing cross
        /// connection.
        /// </summary>
        /// <param name='serviceKey'>
        /// Required. The service key representing the relationship between
        /// Azure and the customer.
        /// </param>
        /// <param name='parameters'>
        /// Required. Parameters supplied to the Update Bgp Peering operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The Get Cross Connection Operation Response.
        /// </returns>
        public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.ExpressRoute.Models.CrossConnectionGetResponse> UpdateAsync(string serviceKey, CrossConnectionUpdateParameters 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("parameters", parameters);
                Tracing.Enter(invocationId, this, "UpdateAsync", tracingParameters);
            }
            try
            {
                if (shouldTrace)
                {
                    client = this.Client.WithHandler(new ClientRequestTrackingHandler(invocationId));
                }

                cancellationToken.ThrowIfCancellationRequested();
                ExpressRouteOperationResponse originalResponse = await client.CrossConnection.BeginUpdateAsync(serviceKey, 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 cross connection could not be updated due to an internal server error.";
                    throw new ArgumentException(exStr);
                }
                cancellationToken.ThrowIfCancellationRequested();
                CrossConnectionGetResponse getResult = await client.CrossConnection.GetAsync(serviceKey, cancellationToken).ConfigureAwait(false);

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

                return(getResult);
            }
            finally
            {
                if (client != null && shouldTrace)
                {
                    client.Dispose();
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// The Update Cross Connection operation updates an existing cross
        /// connection.
        /// </summary>
        /// <param name='serviceKey'>
        /// Required. The service key representing the relationship between
        /// Azure and the customer.
        /// </param>
        /// <param name='parameters'>
        /// Required. Parameters supplied to the Update CrossConnection
        /// 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 System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.ExpressRoute.Models.ExpressRouteOperationResponse> BeginUpdateAsync(string serviceKey, CrossConnectionUpdateParameters 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");
            }

            // 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("parameters", parameters);
                Tracing.Enter(invocationId, this, "BeginUpdateAsync", tracingParameters);
            }

            // Construct URL
            string baseUrl = this.Client.BaseUri.AbsoluteUri;
            string url     = "/" + this.Client.Credentials.SubscriptionId.Trim() + "/services/networking/dedicatedcircuits/" + serviceKey.Trim() + "/crossconnection?api-version=1.0";

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;

            // 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 updateCrossConnectionElement = new XElement(XName.Get("UpdateCrossConnection", "http://schemas.microsoft.com/windowsazure"));
                requestDoc.Add(updateCrossConnectionElement);

                XElement operationElement = new XElement(XName.Get("Operation", "http://schemas.microsoft.com/windowsazure"));
                operationElement.Value = ExpressRouteManagementClient.UpdateCrossConnectionOperationToString(parameters.Operation);
                updateCrossConnectionElement.Add(operationElement);

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

                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 && gatewayOperationAsyncResponseElement.IsEmpty == false)
                    {
                        XElement idElement = gatewayOperationAsyncResponseElement.Element(XName.Get("ID", "http://schemas.microsoft.com/windowsazure"));
                        if (idElement != null && idElement.IsEmpty == false)
                        {
                            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();
                }
            }
        }
Esempio n. 7
0
 public AzureCrossConnection SetAzureCrossConnection(string serviceKey,
                                                     CrossConnectionUpdateParameters parameters)
 {
     return((Client.CrossConnections.Update(serviceKey, parameters)).CrossConnection);
 }
Esempio n. 8
0
 /// <summary>
 /// The Update Cross Connection operation updates an existing cross
 /// connection.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ExpressRoute.ICrossConnectionOperations.
 /// </param>
 /// <param name='serviceKey'>
 /// The service key representing the relationship between Azure and the
 /// customer.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Update Bgp Peering operation.
 /// </param>
 /// <returns>
 /// The Get Cross Connection Operation Response.
 /// </returns>
 public static Task <CrossConnectionGetResponse> UpdateAsync(this ICrossConnectionOperations operations, string serviceKey, CrossConnectionUpdateParameters parameters)
 {
     return(operations.UpdateAsync(serviceKey, parameters, CancellationToken.None));
 }
Esempio n. 9
0
 /// <summary>
 /// The Update Cross Connection operation updates an existing cross
 /// connection.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ExpressRoute.ICrossConnectionOperations.
 /// </param>
 /// <param name='serviceKey'>
 /// The service key representing the relationship between Azure and the
 /// customer.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Update Bgp Peering operation.
 /// </param>
 /// <returns>
 /// The Get Cross Connection Operation Response.
 /// </returns>
 public static CrossConnectionGetResponse Update(this ICrossConnectionOperations operations, string serviceKey, CrossConnectionUpdateParameters parameters)
 {
     try
     {
         return(operations.UpdateAsync(serviceKey, parameters).Result);
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }
Esempio n. 10
0
 /// <summary>
 /// The Update Cross Connection operation updates an existing cross
 /// connection.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ExpressRoute.ICrossConnectionOperations.
 /// </param>
 /// <param name='serviceKey'>
 /// The service key representing the relationship between Azure and the
 /// customer.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Update CrossConnection operation.
 /// </param>
 /// <returns>
 /// A standard express route gateway response including an HTTP status
 /// code and request ID.
 /// </returns>
 public static Task <ExpressRouteOperationResponse> BeginUpdateAsync(this ICrossConnectionOperations operations, string serviceKey, CrossConnectionUpdateParameters parameters)
 {
     return(operations.BeginUpdateAsync(serviceKey, parameters, CancellationToken.None));
 }
        /// <summary>
        /// The Update Cross Connection operation updates an existing cross
        /// connection.
        /// </summary>
        /// <param name='serviceKey'>
        /// Required. The service key representing the relationship between
        /// Azure and the customer.
        /// </param>
        /// <param name='parameters'>
        /// Required. Parameters supplied to the Update Bgp Peering operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The Get Cross Connection Operation Response.
        /// </returns>
        public async Task <CrossConnectionGetResponse> UpdateAsync(string serviceKey, CrossConnectionUpdateParameters parameters, CancellationToken cancellationToken)
        {
            // Validate
            if (serviceKey == null)
            {
                throw new ArgumentNullException("serviceKey");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

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

            // Construct URL
            string url = "";

            url = url + "/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/services/networking/dedicatedcircuits/";
            url = url + Uri.EscapeDataString(serviceKey);
            url = url + "/crossconnection";
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=1.0");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

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

                // Set Headers

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

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

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode >= HttpStatusCode.BadRequest)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    CrossConnectionGetResponse result = null;
                    // Deserialize Response
                    result            = new CrossConnectionGetResponse();
                    result.StatusCode = statusCode;

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
Esempio n. 12
0
 /// <summary>
 /// The Update Cross Connection operation updates an existing cross
 /// connection.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ExpressRoute.ICrossConnectionOperations.
 /// </param>
 /// <param name='serviceKey'>
 /// Required. The service key representing the relationship between
 /// Azure and the customer.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Update Bgp Peering operation.
 /// </param>
 /// <returns>
 /// The Get Cross Connection Operation Response.
 /// </returns>
 public static CrossConnectionGetResponse Update(this ICrossConnectionOperations operations, string serviceKey, CrossConnectionUpdateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((ICrossConnectionOperations)s).UpdateAsync(serviceKey, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }