/// <summary> /// Get all Networks /// </summary> private void GetAllNetworks() { NetworksListResponse networkListResponse = RecoveryServicesClient.GetAzureSiteRecoveryNetworks(); this.WriteNetworks(networkListResponse.NetworksList); }
/// <summary> /// Queries all Networks under Server /// </summary> private void GetByServer() { NetworksListResponse networkListResponse = RecoveryServicesClient.GetAzureSiteRecoveryNetworks( Utilities.GetValueFromArmId(this.Server.ID, ARMResourceTypeConstants.ReplicationFabrics)); this.WriteNetworks(networkListResponse.NetworksList); }
/// <summary> /// Queries all Networks under Fabric /// </summary> private void GetByFabric() { NetworksListResponse networkListResponse = RecoveryServicesClient.GetAzureSiteRecoveryNetworks( this.Fabric.Name); this.WriteNetworks(networkListResponse.NetworksList); }
/// <summary> /// Queries a particular Network /// </summary> private void GetByFriendlyName() { NetworksListResponse networkListResponse = RecoveryServicesClient.GetAzureSiteRecoveryNetworks( Utilities.GetValueFromArmId(this.Server.ID, ARMResourceTypeConstants.ReplicationFabrics)); foreach (Network network in networkListResponse.NetworksList) { if (0 == string.Compare(this.FriendlyName, network.Properties.FriendlyName, true)) { WriteNetwork(network); } } }
/// <summary> /// Queries a particular Network /// </summary> private void GetByFriendlyName() { NetworksListResponse networkListResponse = RecoveryServicesClient.GetAzureSiteRecoveryNetworks( this.Fabric.Name); foreach (Network network in networkListResponse.NetworksList) { if (0 == string.Compare(this.FriendlyName, network.Properties.FriendlyName, true)) { WriteNetwork(network); } } }
/// <summary> /// Get list of Networks. /// </summary> /// <param name='fabricName'> /// Required. Fabric unique name. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The response model for the list of Networks. /// </returns> public async Task <NetworksListResponse> ListAsync(string fabricName, CustomRequestHeaders customRequestHeaders, CancellationToken cancellationToken) { // Validate if (fabricName == null) { throw new ArgumentNullException("fabricName"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("fabricName", fabricName); tracingParameters.Add("customRequestHeaders", customRequestHeaders); TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/Subscriptions/"; if (this.Client.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId); } url = url + "/resourceGroups/"; url = url + Uri.EscapeDataString(this.Client.ResourceGroupName); url = url + "/providers/"; url = url + Uri.EscapeDataString(this.Client.ResourceNamespace); url = url + "/"; url = url + Uri.EscapeDataString(this.Client.ResourceType); url = url + "/"; url = url + Uri.EscapeDataString(this.Client.ResourceName); url = url + "/replicationFabrics/"; url = url + Uri.EscapeDataString(fabricName); url = url + "/replicationNetworks"; List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2015-11-10"); 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.Get; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("x-ms-client-request-id", customRequestHeaders.ClientRequestId); httpRequest.Headers.Add("x-ms-version", "2015-01-01"); // 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.OK) { 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 NetworksListResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new NetworksListResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { JToken valueArray = responseDoc["value"]; if (valueArray != null && valueArray.Type != JTokenType.Null) { foreach (JToken valueValue in ((JArray)valueArray)) { Network networkInstance = new Network(); result.NetworksList.Add(networkInstance); JToken propertiesValue = valueValue["properties"]; if (propertiesValue != null && propertiesValue.Type != JTokenType.Null) { NetworkProperties propertiesInstance = new NetworkProperties(); networkInstance.Properties = propertiesInstance; JToken fabricTypeValue = propertiesValue["fabricType"]; if (fabricTypeValue != null && fabricTypeValue.Type != JTokenType.Null) { string fabricTypeInstance = ((string)fabricTypeValue); propertiesInstance.FabricType = fabricTypeInstance; } JToken subnetsArray = propertiesValue["subnets"]; if (subnetsArray != null && subnetsArray.Type != JTokenType.Null) { foreach (JToken subnetsValue in ((JArray)subnetsArray)) { Subnet subnetInstance = new Subnet(); propertiesInstance.Subnets.Add(subnetInstance); JToken nameValue = subnetsValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); subnetInstance.Name = nameInstance; } JToken friendlyNameValue = subnetsValue["friendlyName"]; if (friendlyNameValue != null && friendlyNameValue.Type != JTokenType.Null) { string friendlyNameInstance = ((string)friendlyNameValue); subnetInstance.FriendlyName = friendlyNameInstance; } JToken addressListArray = subnetsValue["addressList"]; if (addressListArray != null && addressListArray.Type != JTokenType.Null) { foreach (JToken addressListValue in ((JArray)addressListArray)) { subnetInstance.AddressList.Add(((string)addressListValue)); } } } } JToken friendlyNameValue2 = propertiesValue["friendlyName"]; if (friendlyNameValue2 != null && friendlyNameValue2.Type != JTokenType.Null) { string friendlyNameInstance2 = ((string)friendlyNameValue2); propertiesInstance.FriendlyName = friendlyNameInstance2; } JToken networkTypeValue = propertiesValue["networkType"]; if (networkTypeValue != null && networkTypeValue.Type != JTokenType.Null) { string networkTypeInstance = ((string)networkTypeValue); propertiesInstance.NetworkType = networkTypeInstance; } } JToken idValue = valueValue["id"]; if (idValue != null && idValue.Type != JTokenType.Null) { string idInstance = ((string)idValue); networkInstance.Id = idInstance; } JToken nameValue2 = valueValue["name"]; if (nameValue2 != null && nameValue2.Type != JTokenType.Null) { string nameInstance2 = ((string)nameValue2); networkInstance.Name = nameInstance2; } JToken typeValue = valueValue["type"]; if (typeValue != null && typeValue.Type != JTokenType.Null) { string typeInstance = ((string)typeValue); networkInstance.Type = typeInstance; } JToken locationValue = valueValue["location"]; if (locationValue != null && locationValue.Type != JTokenType.Null) { string locationInstance = ((string)locationValue); networkInstance.Location = locationInstance; } JToken tagsSequenceElement = ((JToken)valueValue["tags"]); if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null) { foreach (JProperty property in tagsSequenceElement) { string tagsKey = ((string)property.Name); string tagsValue = ((string)property.Value); networkInstance.Tags.Add(tagsKey, tagsValue); } } } } JToken nextLinkValue = responseDoc["nextLink"]; if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null) { string nextLinkInstance = ((string)nextLinkValue); result.NextLink = nextLinkInstance; } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }