/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { try { StorageListResponse storageListResponse = RecoveryServicesClient.GetAzureSiteRecoveryStorages(this.Server.ID); this.WriteStorages(storageListResponse.Storages); } catch (Exception exception) { this.HandleException(exception); } }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { try { this.WriteWarningWithTimestamp( string.Format( Properties.Resources.CmdletWillBeDeprecatedSoon, this.MyInvocation.MyCommand.Name)); StorageListResponse storageListResponse = RecoveryServicesClient.GetAzureSiteRecoveryStorages(this.Server.ID); this.WriteStorages(storageListResponse.Storages); } catch (Exception exception) { this.HandleException(exception); } }
/// <summary> /// Get the list of all storages under the vault. /// </summary> /// <param name='serverId'> /// Required. Server Id. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The response model for the list storage operation. /// </returns> public async Task <StorageListResponse> ListAsync(string serverId, CustomRequestHeaders customRequestHeaders, CancellationToken cancellationToken) { // Validate if (serverId == null) { throw new ArgumentNullException("serverId"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("serverId", serverId); tracingParameters.Add("customRequestHeaders", customRequestHeaders); TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters); } // Construct URL string url = ""; if (this.Client.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId); } url = url + "/cloudservices/"; url = url + Uri.EscapeDataString(this.Client.CloudServiceName); url = url + "/resources/"; url = url + "WAHyperVRecoveryManager"; url = url + "/~/"; url = url + "HyperVRecoveryManagerVault"; url = url + "/"; url = url + Uri.EscapeDataString(this.Client.ResourceName); url = url + "/Storages"; List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2015-02-10"); queryParameters.Add("ServerId=" + Uri.EscapeDataString(serverId)); 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("Accept", "application/xml"); httpRequest.Headers.Add("x-ms-client-request-id", customRequestHeaders.ClientRequestId); httpRequest.Headers.Add("x-ms-version", "2013-03-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 StorageListResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new StorageListResponse(); XDocument responseDoc = XDocument.Parse(responseContent); XElement arrayOfStorageSequenceElement = responseDoc.Element(XName.Get("ArrayOfStorage", "http://schemas.microsoft.com/windowsazure")); if (arrayOfStorageSequenceElement != null) { foreach (XElement arrayOfStorageElement in arrayOfStorageSequenceElement.Elements(XName.Get("Storage", "http://schemas.microsoft.com/windowsazure"))) { AsrStorage storageInstance = new AsrStorage(); result.Storages.Add(storageInstance); XElement typeElement = arrayOfStorageElement.Element(XName.Get("Type", "http://schemas.microsoft.com/windowsazure")); if (typeElement != null) { string typeInstance = typeElement.Value; storageInstance.Type = typeInstance; } XElement fabricObjectIDElement = arrayOfStorageElement.Element(XName.Get("FabricObjectID", "http://schemas.microsoft.com/windowsazure")); if (fabricObjectIDElement != null) { string fabricObjectIDInstance = fabricObjectIDElement.Value; storageInstance.FabricObjectID = fabricObjectIDInstance; } XElement fabricTypeElement = arrayOfStorageElement.Element(XName.Get("FabricType", "http://schemas.microsoft.com/windowsazure")); if (fabricTypeElement != null) { string fabricTypeInstance = fabricTypeElement.Value; storageInstance.FabricType = fabricTypeInstance; } XElement serverIDElement = arrayOfStorageElement.Element(XName.Get("ServerID", "http://schemas.microsoft.com/windowsazure")); if (serverIDElement != null) { string serverIDInstance = serverIDElement.Value; storageInstance.ServerID = serverIDInstance; } XElement nameElement = arrayOfStorageElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")); if (nameElement != null) { string nameInstance = nameElement.Value; storageInstance.Name = nameInstance; } XElement idElement = arrayOfStorageElement.Element(XName.Get("ID", "http://schemas.microsoft.com/windowsazure")); if (idElement != null) { string idInstance = idElement.Value; storageInstance.ID = idInstance; } } } } 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(); } } }
/// <summary> /// Gets the replication storage objects under a fabric. /// </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 storage classification operation. /// </returns> public async Task <StorageListResponse> 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 + "/replicationStorageClassifications"; 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("Accept-Language", customRequestHeaders.Culture); 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 StorageListResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new StorageListResponse(); 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)) { StorageClassification storageClassificationInstance = new StorageClassification(); result.StorageClassifications.Add(storageClassificationInstance); JToken propertiesValue = valueValue["properties"]; if (propertiesValue != null && propertiesValue.Type != JTokenType.Null) { StorageClassificationProperties propertiesInstance = new StorageClassificationProperties(); storageClassificationInstance.Properties = propertiesInstance; JToken friendlyNameValue = propertiesValue["friendlyName"]; if (friendlyNameValue != null && friendlyNameValue.Type != JTokenType.Null) { string friendlyNameInstance = ((string)friendlyNameValue); propertiesInstance.FriendlyName = friendlyNameInstance; } } JToken idValue = valueValue["id"]; if (idValue != null && idValue.Type != JTokenType.Null) { string idInstance = ((string)idValue); storageClassificationInstance.Id = idInstance; } JToken nameValue = valueValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); storageClassificationInstance.Name = nameInstance; } JToken typeValue = valueValue["type"]; if (typeValue != null && typeValue.Type != JTokenType.Null) { string typeInstance = ((string)typeValue); storageClassificationInstance.Type = typeInstance; } JToken locationValue = valueValue["location"]; if (locationValue != null && locationValue.Type != JTokenType.Null) { string locationInstance = ((string)locationValue); storageClassificationInstance.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); storageClassificationInstance.Tags.Add(tagsKey, tagsValue); } } } } JToken nextLinkValue = responseDoc["nextLink"]; if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null) { string nextLinkInstance = ((string)nextLinkValue); result.NextLink = nextLinkInstance; } JToken clientRequestIdValue = responseDoc["ClientRequestId"]; if (clientRequestIdValue != null && clientRequestIdValue.Type != JTokenType.Null) { string clientRequestIdInstance = ((string)clientRequestIdValue); result.ClientRequestId = clientRequestIdInstance; } JToken correlationRequestIdValue = responseDoc["CorrelationRequestId"]; if (correlationRequestIdValue != null && correlationRequestIdValue.Type != JTokenType.Null) { string correlationRequestIdInstance = ((string)correlationRequestIdValue); result.CorrelationRequestId = correlationRequestIdInstance; } JToken dateValue = responseDoc["Date"]; if (dateValue != null && dateValue.Type != JTokenType.Null) { string dateInstance = ((string)dateValue); result.Date = dateInstance; } JToken contentTypeValue = responseDoc["ContentType"]; if (contentTypeValue != null && contentTypeValue.Type != JTokenType.Null) { string contentTypeInstance = ((string)contentTypeValue); result.ContentType = contentTypeInstance; } } } result.StatusCode = statusCode; if (httpResponse.Content != null && httpResponse.Content.Headers.Contains("Content-Type")) { result.ContentType = httpResponse.Content.Headers.GetValues("Content-Type").FirstOrDefault(); } if (httpResponse.Headers.Contains("Date")) { result.Date = httpResponse.Headers.GetValues("Date").FirstOrDefault(); } if (httpResponse.Headers.Contains("x-ms-client-request-id")) { result.ClientRequestId = httpResponse.Headers.GetValues("x-ms-client-request-id").FirstOrDefault(); } if (httpResponse.Headers.Contains("x-ms-correlation-request-id")) { result.CorrelationRequestId = httpResponse.Headers.GetValues("x-ms-correlation-request-id").FirstOrDefault(); } 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(); } } }