/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { try { this.WriteWarningWithTimestamp( string.Format( Properties.Resources.CmdletWillBeDeprecatedSoon, this.MyInvocation.MyCommand.Name)); string cloudServiceName = Utilities.GenerateCloudServiceName(this.Location); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(cloudServiceName); string base64Label = Convert.ToBase64String(bytes); CloudServiceCreateArgs cloudServiceCreateArgs = new CloudServiceCreateArgs() { GeoRegion = this.Location, Label = base64Label, Description = base64Label }; RecoveryServicesClient.FindOrCreateCloudService(cloudServiceName, cloudServiceCreateArgs); VaultCreateArgs vaultCreateArgs = new VaultCreateArgs() { Name = this.Name, Plan = string.Empty, ResourceProviderNamespace = Constants.ResourceNamespace, Type = Constants.ASRVaultType, ETag = Guid.NewGuid().ToString(), SchemaVersion = Constants.RpSchemaVersion }; RecoveryServicesOperationStatusResponse response = RecoveryServicesClient.CreateVault(cloudServiceName, this.Name, vaultCreateArgs); VaultOperationOutput output = new VaultOperationOutput() { Response = response.StatusCode == HttpStatusCode.OK ? Resources.VaultCreationSuccessMessage : response.StatusCode.ToString() }; this.WriteObject(output, true); } catch (Exception exception) { this.HandleException(exception); } }
public void CreateVault() { using (UndoContext context = UndoContext.Current) { context.Start(); var rsmClient = GetRecoveryServicesClient(CustomHttpHandler); VaultCreateArgs vaultCreateArgs = new VaultCreateArgs(); vaultCreateArgs.Location = "westus"; vaultCreateArgs.Properties = new VaultProperties(); vaultCreateArgs.Sku = new VaultSku(); vaultCreateArgs.Sku.Name = "standard"; VaultCreateResponse response = rsmClient.Vaults.BeginCreating(resourceGroupName, resourceName, vaultCreateArgs); Assert.NotNull(response.Name); Assert.NotNull(response.Id); Assert.NotNull(response.Properties.ProvisioningState); Assert.Equal(HttpStatusCode.Created, response.StatusCode); } }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { try { VaultCreateArgs vaultCreateArgs = new VaultCreateArgs(); vaultCreateArgs.Location = this.Location; vaultCreateArgs.Properties = new VaultProperties(); vaultCreateArgs.Properties.Sku = new VaultSku(); vaultCreateArgs.Properties.Sku.Name = "standard"; VaultCreateResponse response = RecoveryServicesClient.CreateVault(this.ResouceGroupName, this.Name, vaultCreateArgs); this.WriteObject(new ASRVault(response)); } catch (Exception exception) { this.HandleException(exception); } }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteSiteRecoveryCmdlet() { base.ExecuteSiteRecoveryCmdlet(); this.WriteWarningWithTimestamp( string.Format( Properties.Resources.SiteRecoveryVaultTypeWillBeDeprecatedSoon)); VaultCreateArgs vaultCreateArgs = new VaultCreateArgs(); vaultCreateArgs.Location = this.Location; vaultCreateArgs.Properties = new VaultProperties(); vaultCreateArgs.Properties.Sku = new VaultSku(); vaultCreateArgs.Properties.Sku.Name = "standard"; VaultCreateResponse response = RecoveryServicesClient.CreateVault(this.ResourceGroupName, this.Name, vaultCreateArgs); this.WriteObject(new ASRVault(response)); }
public void CreateVault(string resourceGroupName, string resourceName, string location) { RecoveryServicesTestsBase testsBase = new RecoveryServicesTestsBase(); var rsClient = testsBase.GetRecoveryServicesClient(RsCustomHttpHandler); if (!IsVaultPresent(resourceGroupName, resourceName)) { VaultCreateArgs vaultCreateArgs = new VaultCreateArgs(); vaultCreateArgs.Location = location; vaultCreateArgs.Properties = new VaultProperties(); vaultCreateArgs.Sku = new VaultSku(); vaultCreateArgs.Sku.Name = "standard"; VaultCreateResponse response = rsClient.Vaults.BeginCreating(resourceGroupName, resourceName, vaultCreateArgs); Assert.NotNull(response.Name); Assert.NotNull(response.Id); Assert.NotNull(response.Properties.ProvisioningState); Assert.Equal(HttpStatusCode.Created, response.StatusCode); } }
/// <summary> /// ProcessRecord of the command. /// </summary> protected override void ProcessRecord() { try { this.WriteWarningWithTimestamp( string.Format( Properties.Resources.SiteRecoveryVaultTypeWillBeDeprecatedSoon)); VaultCreateArgs vaultCreateArgs = new VaultCreateArgs(); vaultCreateArgs.Location = this.Location; vaultCreateArgs.Properties = new VaultProperties(); vaultCreateArgs.Properties.Sku = new VaultSku(); vaultCreateArgs.Properties.Sku.Name = "standard"; VaultCreateResponse response = RecoveryServicesClient.CreateVault(this.ResouceGroupName, this.Name, vaultCreateArgs); this.WriteObject(new ASRVault(response)); } catch (Exception exception) { this.HandleException(exception); } }
/// <summary> /// Method to create Azure Site Recovery Vault /// </summary> /// <param name="resouceGroupName">name of the resouce group</param> /// <param name="vaultName">name of the vault</param> /// <param name="vaultCreateInput">vault creation input object</param> /// <returns>creation response object.</returns> public VaultCreateResponse CreateVault(string resouceGroupName, string vaultName, VaultCreateArgs vaultCreateInput) { return(this.recoveryServicesClient.Vaults.BeginCreating(resouceGroupName, vaultName, vaultCreateInput)); }
/// <summary> /// Creates a vault /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.RecoveryServices.IVaultOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the (resource group?) cloud service /// containing the job collection. /// </param> /// <param name='vaultName'> /// Required. The name of the vault to create. /// </param> /// <param name='vaultCreationInput'> /// Required. Vault object to be created /// </param> /// <returns> /// The response model for the Vm group object. /// </returns> public static Task <VaultCreateResponse> BeginCreatingAsync(this IVaultOperations operations, string resourceGroupName, string vaultName, VaultCreateArgs vaultCreationInput) { return(operations.BeginCreatingAsync(resourceGroupName, vaultName, vaultCreationInput, CancellationToken.None)); }
/// <summary> /// Creates a vault /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.RecoveryServices.IVaultOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the (resource group?) cloud service /// containing the job collection. /// </param> /// <param name='vaultName'> /// Required. The name of the vault to create. /// </param> /// <param name='vaultCreationInput'> /// Required. Vault object to be created /// </param> /// <returns> /// The response model for the Vm group object. /// </returns> public static VaultCreateResponse BeginCreating(this IVaultOperations operations, string resourceGroupName, string vaultName, VaultCreateArgs vaultCreationInput) { return(Task.Factory.StartNew((object s) => { return ((IVaultOperations)s).BeginCreatingAsync(resourceGroupName, vaultName, vaultCreationInput); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Creates a vault /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.RecoveryServices.IVaultOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the (resource group) cloud service containing /// the job collection. /// </param> /// <param name='vaultName'> /// Optional. The name of the vault to create. /// </param> /// <param name='vaultCreationInput'> /// Required. Vault object to be created /// </param> /// <returns> /// The response body contains the status of the specified asynchronous /// operation, indicating whether it has succeeded, is inprogress, or /// has failed. Note that this status is distinct from the HTTP status /// code returned for the Get Operation Status operation itself. If /// the asynchronous operation succeeded, the response body includes /// the HTTP status code for the successful request. If the /// asynchronous operation failed, the response body includes the HTTP /// status code for the failed request, and also includes error /// information regarding the failure. /// </returns> public static Task <RecoveryServicesOperationStatusResponse> CreateAsync(this IVaultOperations operations, string resourceGroupName, string vaultName, VaultCreateArgs vaultCreationInput) { return(operations.CreateAsync(resourceGroupName, vaultName, vaultCreationInput, CancellationToken.None)); }
/// <summary> /// Creates a vault /// </summary> /// <param name='resourceGroupName'> /// Required. The name of the (resource group?) cloud service /// containing the job collection. /// </param> /// <param name='vaultName'> /// Required. The name of the vault to create. /// </param> /// <param name='vaultCreationInput'> /// Required. Vault object to be created /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The response model for the Vm group object. /// </returns> public async Task <VaultCreateResponse> BeginCreatingAsync(string resourceGroupName, string vaultName, VaultCreateArgs vaultCreationInput, CancellationToken cancellationToken) { // Validate if (resourceGroupName == null) { throw new ArgumentNullException("resourceGroupName"); } if (vaultName == null) { throw new ArgumentNullException("vaultName"); } if (vaultCreationInput == null) { throw new ArgumentNullException("vaultCreationInput"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("vaultName", vaultName); tracingParameters.Add("vaultCreationInput", vaultCreationInput); TracingAdapter.Enter(invocationId, this, "BeginCreatingAsync", 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(resourceGroupName); url = url + "/providers/"; url = url + Uri.EscapeDataString(this.Client.ResourceNamespace); url = url + "/"; url = url + "vaults"; url = url + "/"; url = url + Uri.EscapeDataString(vaultName); List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2015-08-15"); 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 httpRequest.Headers.Add("Accept", "application/json; charset=utf-8"); httpRequest.Headers.Add("x-ms-version", "2015-01-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Serialize Request string requestContent = null; JToken requestDoc = null; JObject resourceValue = new JObject(); requestDoc = resourceValue; if (vaultCreationInput.Location != null) { resourceValue["location"] = vaultCreationInput.Location; } if (vaultCreationInput.Sku != null) { JObject skuValue = new JObject(); resourceValue["sku"] = skuValue; if (vaultCreationInput.Sku.Name != null) { skuValue["name"] = vaultCreationInput.Sku.Name; } } if (vaultCreationInput.Properties != null) { JObject propertiesValue = new JObject(); resourceValue["properties"] = propertiesValue; if (vaultCreationInput.Properties.ProvisioningState != null) { propertiesValue["provisioningState"] = vaultCreationInput.Properties.ProvisioningState; } } requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented); httpRequest.Content = new StringContent(requestContent, Encoding.UTF8); httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); // 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 && statusCode != HttpStatusCode.Created && statusCode != HttpStatusCode.Accepted) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result VaultCreateResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK || statusCode == HttpStatusCode.Created || statusCode == HttpStatusCode.Accepted) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new VaultCreateResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { JToken idValue = responseDoc["id"]; if (idValue != null && idValue.Type != JTokenType.Null) { string idInstance = ((string)idValue); result.Id = idInstance; } JToken nameValue = responseDoc["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); result.Name = nameInstance; } JToken typeValue = responseDoc["type"]; if (typeValue != null && typeValue.Type != JTokenType.Null) { string typeInstance = ((string)typeValue); result.Type = typeInstance; } JToken locationValue = responseDoc["location"]; if (locationValue != null && locationValue.Type != JTokenType.Null) { string locationInstance = ((string)locationValue); result.Location = locationInstance; } JToken tagsSequenceElement = ((JToken)responseDoc["tags"]); if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null) { foreach (JProperty property in tagsSequenceElement) { string tagsKey = ((string)property.Name); string tagsValue = ((string)property.Value); result.Tags.Add(tagsKey, tagsValue); } } JToken propertiesValue2 = responseDoc["properties"]; if (propertiesValue2 != null && propertiesValue2.Type != JTokenType.Null) { VaultProperties propertiesInstance = new VaultProperties(); result.Properties = propertiesInstance; JToken provisioningStateValue = propertiesValue2["provisioningState"]; if (provisioningStateValue != null && provisioningStateValue.Type != JTokenType.Null) { string provisioningStateInstance = ((string)provisioningStateValue); propertiesInstance.ProvisioningState = provisioningStateInstance; } } JToken etagValue = responseDoc["etag"]; if (etagValue != null && etagValue.Type != JTokenType.Null) { string etagInstance = ((string)etagValue); result.ETag = etagInstance; } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("ETag")) { result.ETag = httpResponse.Headers.GetValues("ETag").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(); } } }
/// <summary> /// Creates a vault /// </summary> /// <param name='resourceGroupName'> /// Required. The name of the (resource group) cloud service containing /// the job collection. /// </param> /// <param name='vaultName'> /// Optional. The name of the vault to create. /// </param> /// <param name='vaultCreationInput'> /// Required. Vault object to be created /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The response body contains the status of the specified asynchronous /// operation, indicating whether it has succeeded, is inprogress, or /// has failed. Note that this status is distinct from the HTTP status /// code returned for the Get Operation Status operation itself. If /// the asynchronous operation succeeded, the response body includes /// the HTTP status code for the successful request. If the /// asynchronous operation failed, the response body includes the HTTP /// status code for the failed request, and also includes error /// information regarding the failure. /// </returns> public async Task <RecoveryServicesOperationStatusResponse> CreateAsync(string resourceGroupName, string vaultName, VaultCreateArgs vaultCreationInput, CancellationToken cancellationToken) { RecoveryServicesManagementClient client = this.Client; bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("vaultName", vaultName); tracingParameters.Add("vaultCreationInput", vaultCreationInput); TracingAdapter.Enter(invocationId, this, "CreateAsync", tracingParameters); } cancellationToken.ThrowIfCancellationRequested(); VaultCreateResponse response = await client.Vaults.BeginCreatingAsync(resourceGroupName, vaultName, vaultCreationInput, cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); RecoveryServicesOperationStatusResponse result = await client.GetOperationStatusAsync(response.RequestId, cancellationToken).ConfigureAwait(false); int delayInSeconds = 15; if (client.LongRunningOperationInitialTimeout >= 0) { delayInSeconds = client.LongRunningOperationInitialTimeout; } while (result.Status == RecoveryServicesOperationStatus.InProgress) { cancellationToken.ThrowIfCancellationRequested(); await TaskEx.Delay(delayInSeconds * 1000, cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); result = await client.GetOperationStatusAsync(response.RequestId, cancellationToken).ConfigureAwait(false); delayInSeconds = 10; if (client.LongRunningOperationRetryTimeout >= 0) { delayInSeconds = client.LongRunningOperationRetryTimeout; } } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } if (result.Status != RecoveryServicesOperationStatus.Succeeded) { if (result.Error != null) { CloudException ex = new CloudException(result.Error.Code + " : " + result.Error.Message); ex.Error = new CloudError(); ex.Error.Code = result.Error.Code; ex.Error.Message = result.Error.Message; if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } else { CloudException ex = new CloudException(""); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } } result.ETag = response.ETag; return(result); }
/// <summary> /// Creates a vault /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.RecoveryServices.IVaultOperations. /// </param> /// <param name='cloudServiceName'> /// Required. The name of the cloud service containing the job /// collection. /// </param> /// <param name='vaultName'> /// Required. The name of the vault to create. /// </param> /// <param name='vaultCreationInput'> /// Required. Vault object to be created /// </param> /// <returns> /// The response body contains the status of the specified asynchronous /// operation, indicating whether it has succeeded, is inprogress, or /// has failed. Note that this status is distinct from the HTTP status /// code returned for the Get Operation Status operation itself. If /// the asynchronous operation succeeded, the response body includes /// the HTTP status code for the successful request. If the /// asynchronous operation failed, the response body includes the HTTP /// status code for the failed request, and also includes error /// information regarding the failure. /// </returns> public static RecoveryServicesOperationStatusResponse Create(this IVaultOperations operations, string cloudServiceName, string vaultName, VaultCreateArgs vaultCreationInput) { return(Task.Factory.StartNew((object s) => { return ((IVaultOperations)s).CreateAsync(cloudServiceName, vaultName, vaultCreationInput); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Creates a vault /// </summary> /// <param name='cloudServiceName'> /// Required. The name of the cloud service containing the job /// collection. /// </param> /// <param name='vaultName'> /// Required. The name of the vault to create. /// </param> /// <param name='vaultCreationInput'> /// Required. Vault object to be created /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The response model for the Vm group object. /// </returns> public async Task <VaultCreateResponse> BeginCreatingAsync(string cloudServiceName, string vaultName, VaultCreateArgs vaultCreationInput, CancellationToken cancellationToken) { // Validate if (cloudServiceName == null) { throw new ArgumentNullException("cloudServiceName"); } if (vaultName == null) { throw new ArgumentNullException("vaultName"); } if (vaultCreationInput == null) { throw new ArgumentNullException("vaultCreationInput"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("cloudServiceName", cloudServiceName); tracingParameters.Add("vaultName", vaultName); tracingParameters.Add("vaultCreationInput", vaultCreationInput); TracingAdapter.Enter(invocationId, this, "BeginCreatingAsync", 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(cloudServiceName); url = url + "/resources/"; url = url + "WAHyperVRecoveryManager"; url = url + "/"; url = url + "HyperVRecoveryManagerVault"; url = url + "/"; url = url + Uri.EscapeDataString(vaultName); 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 httpRequest.Headers.Add("Accept", "application/xml"); httpRequest.Headers.Add("x-ms-version", "2013-03-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Serialize Request string requestContent = null; XDocument requestDoc = new XDocument(); XElement resourceElement = new XElement(XName.Get("Resource", "http://schemas.microsoft.com/windowsazure")); requestDoc.Add(resourceElement); if (vaultCreationInput.ResourceProviderNamespace != null) { XElement resourceProviderNamespaceElement = new XElement(XName.Get("ResourceProviderNamespace", "http://schemas.microsoft.com/windowsazure")); resourceProviderNamespaceElement.Value = vaultCreationInput.ResourceProviderNamespace; resourceElement.Add(resourceProviderNamespaceElement); } if (vaultCreationInput.Type != null) { XElement typeElement = new XElement(XName.Get("Type", "http://schemas.microsoft.com/windowsazure")); typeElement.Value = vaultCreationInput.Type; resourceElement.Add(typeElement); } if (vaultCreationInput.Name != null) { XElement nameElement = new XElement(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")); nameElement.Value = vaultCreationInput.Name; resourceElement.Add(nameElement); } if (vaultCreationInput.Plan != null) { XElement planElement = new XElement(XName.Get("Plan", "http://schemas.microsoft.com/windowsazure")); planElement.Value = vaultCreationInput.Plan; resourceElement.Add(planElement); } if (vaultCreationInput.SchemaVersion != null) { XElement schemaVersionElement = new XElement(XName.Get("SchemaVersion", "http://schemas.microsoft.com/windowsazure")); schemaVersionElement.Value = vaultCreationInput.SchemaVersion; resourceElement.Add(schemaVersionElement); } if (vaultCreationInput.ETag != null) { XElement eTagElement = new XElement(XName.Get("ETag", "http://schemas.microsoft.com/windowsazure")); eTagElement.Value = vaultCreationInput.ETag; resourceElement.Add(eTagElement); } if (vaultCreationInput.Label != null) { XElement labelElement = new XElement(XName.Get("Label", "http://schemas.microsoft.com/windowsazure")); labelElement.Value = vaultCreationInput.Label; resourceElement.Add(labelElement); } requestContent = requestDoc.ToString(); httpRequest.Content = new StringContent(requestContent, Encoding.UTF8); httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/xml"); // 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.Accepted) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result VaultCreateResponse result = null; // Deserialize Response result = new VaultCreateResponse(); result.StatusCode = statusCode; if (httpResponse.Headers.Contains("ETag")) { result.ETag = httpResponse.Headers.GetValues("ETag").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(); } } }
/// <summary> /// Method to create Azure Site Recovery Vault /// </summary> /// <param name="cloudServiceName">name of the cloud service</param> /// <param name="vaultName">name of the vault</param> /// <param name="vaultCreateInput">vault creation input object</param> /// <returns>creation response object.</returns> public RecoveryServicesOperationStatusResponse CreateVault(string cloudServiceName, string vaultName, VaultCreateArgs vaultCreateInput) { return(this.GetRecoveryServicesClient.Vaults.Create(cloudServiceName, vaultName, vaultCreateInput)); }