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); } }
/// <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(); } } }
/// <summary> /// The Get Cross Connection operation retrieves the Cross Connection /// information for the Dedicated Circuit with the specified service /// key. /// </summary> /// <param name='serviceKey'> /// Required. The servicee key representing the dedicated circuit. /// </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> GetAsync(string serviceKey, CancellationToken cancellationToken) { // Validate if (serviceKey == null) { throw new ArgumentNullException("serviceKey"); } // 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); Tracing.Enter(invocationId, this, "GetAsync", 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.Get; 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); // 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.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false), CloudExceptionType.Xml); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result CrossConnectionGetResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new CrossConnectionGetResponse(); XDocument responseDoc = XDocument.Parse(responseContent); XElement crossConnectionElement = responseDoc.Element(XName.Get("CrossConnection", "http://schemas.microsoft.com/windowsazure")); if (crossConnectionElement != null && crossConnectionElement.IsEmpty == false) { XElement bandwidthElement = crossConnectionElement.Element(XName.Get("Bandwidth", "http://schemas.microsoft.com/windowsazure")); if (bandwidthElement != null && bandwidthElement.IsEmpty == false) { int bandwidthInstance = int.Parse(bandwidthElement.Value, CultureInfo.InvariantCulture); result.Bandwidth = bandwidthInstance; } XElement provisioningStateElement = crossConnectionElement.Element(XName.Get("ProvisioningState", "http://schemas.microsoft.com/windowsazure")); if (provisioningStateElement != null && provisioningStateElement.IsEmpty == false) { string provisioningStateInstance = provisioningStateElement.Value; result.ProvisioningState = provisioningStateInstance; } XElement primaryAzurePortElement = crossConnectionElement.Element(XName.Get("PrimaryAzurePort", "http://schemas.microsoft.com/windowsazure")); if (primaryAzurePortElement != null && primaryAzurePortElement.IsEmpty == false) { string primaryAzurePortInstance = primaryAzurePortElement.Value; result.PrimaryAzurePort = primaryAzurePortInstance; } XElement secondaryAzurePortElement = crossConnectionElement.Element(XName.Get("SecondaryAzurePort", "http://schemas.microsoft.com/windowsazure")); if (secondaryAzurePortElement != null && secondaryAzurePortElement.IsEmpty == false) { string secondaryAzurePortInstance = secondaryAzurePortElement.Value; result.SecondaryAzurePort = secondaryAzurePortInstance; } XElement sTagElement = crossConnectionElement.Element(XName.Get("STag", "http://schemas.microsoft.com/windowsazure")); if (sTagElement != null && sTagElement.IsEmpty == false) { int sTagInstance = int.Parse(sTagElement.Value, CultureInfo.InvariantCulture); result.STag = sTagInstance; } XElement statusElement = crossConnectionElement.Element(XName.Get("Status", "http://schemas.microsoft.com/windowsazure")); if (statusElement != null && statusElement.IsEmpty == false) { string statusInstance = statusElement.Value; result.Status = statusInstance; } } 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(); } } }
/// <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(); } } }
/// <summary> /// The New Cross Connection operation provisions a cross connection /// for the given azure circuit. /// </summary> /// <param name='serviceKey'> /// Required. Service key of the dedicated circuit. /// </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> NewAsync(string serviceKey, CancellationToken cancellationToken) { // Validate if (serviceKey == null) { throw new ArgumentNullException("serviceKey"); } // 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); Tracing.Enter(invocationId, this, "NewAsync", tracingParameters); } // Construct URL string url = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/networking/dedicatedcircuits/" + serviceKey.Trim() + "/crossconnection?api-version=1.0"; 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.Post; 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) { 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.BadRequest) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result CrossConnectionGetResponse result = null; result = new CrossConnectionGetResponse(); result.StatusCode = statusCode; if (shouldTrace) { Tracing.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }