Exemple #1
0
        /// <summary>
        /// Restores the disk based on the recovery point and other input parameters
        /// </summary>
        /// <param name="rp">Recovery point to restore the disk to</param>
        /// <param name="storageAccountId">ID of the storage account where to restore the disk</param>
        /// <param name="storageAccountLocation">Location of the storage account where to restore the disk</param>
        /// <param name="storageAccountType">Type of the storage account where to restore the disk</param>
        /// <returns>Job created by this operation</returns>
        public RestAzureNS.AzureOperationResponse RestoreDisk(
            AzureRecoveryPoint rp,
            string storageAccountLocation,
            RestoreRequestResource triggerRestoreRequest,
            string vaultName         = null,
            string resourceGroupName = null,
            string vaultLocation     = null)
        {
            vaultLocation = vaultLocation ?? BmsAdapter.GetResourceLocation();
            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
            string containerUri     = HelperUtils.GetContainerUri(uriDict, rp.Id);
            string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, rp.Id);
            string recoveryPointId  = rp.RecoveryPointId;

            //validtion block
            if (storageAccountLocation != vaultLocation)
            {
                throw new Exception(Resources.TriggerRestoreIncorrectRegion);
            }

            var response = BmsAdapter.Client.Restores.TriggerWithHttpMessagesAsync(
                vaultName ?? BmsAdapter.GetResourceName(),
                resourceGroupName ?? BmsAdapter.GetResourceGroupName(),
                AzureFabricName,
                containerUri,
                protectedItemUri,
                recoveryPointId,
                triggerRestoreRequest,
                cancellationToken: BmsAdapter.CmdletCancellationToken).Result;

            return(response);
        }
Exemple #2
0
        /// <summary>
        /// Restores the disk based on the recovery point and other input parameters
        /// </summary>
        /// <param name="rp">Recovery point to restore the disk to</param>
        /// <param name="storageAccountId">ID of the storage account where to restore the disk</param>
        /// <param name="storageAccountLocation">Location of the storage account where to restore the disk</param>
        /// <param name="storageAccountType">Type of the storage account where to restore the disk</param>
        /// <returns>Job created by this operation</returns>
        public RestAzureNS.AzureOperationResponse RestoreDisk(
            AzureVmRecoveryPoint rp,
            string storageAccountId,
            string storageAccountLocation,
            string storageAccountType,
            bool osaOption)
        {
            var useOsa = ShouldUseOsa(rp, osaOption);

            string resourceGroupName = BmsAdapter.GetResourceGroupName();
            string resourceName      = BmsAdapter.GetResourceName();
            string vaultLocation     = BmsAdapter.GetResourceLocation();
            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
            string containerUri     = HelperUtils.GetContainerUri(uriDict, rp.Id);
            string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, rp.Id);
            string recoveryPointId  = rp.RecoveryPointId;

            //validtion block
            if (storageAccountLocation != vaultLocation)
            {
                throw new Exception(Resources.RestoreDiskIncorrectRegion);
            }

            string vmType = containerUri.Split(';')[1].Equals("iaasvmcontainer", StringComparison.OrdinalIgnoreCase)
                ? "Classic" : "Compute";
            string strType = storageAccountType.Equals("Microsoft.ClassicStorage/StorageAccounts",
                                                       StringComparison.OrdinalIgnoreCase) ? "Classic" : "Compute";

            if (vmType != strType)
            {
                throw new Exception(string.Format(Resources.RestoreDiskStorageTypeError, vmType));
            }

            IaasVMRestoreRequest restoreRequest = new IaasVMRestoreRequest()
            {
                CreateNewCloudService = false,
                RecoveryPointId       = recoveryPointId,
                RecoveryType          = RecoveryType.RestoreDisks,
                Region                       = vaultLocation,
                StorageAccountId             = storageAccountId,
                SourceResourceId             = rp.SourceResourceId,
                OriginalStorageAccountOption = useOsa,
            };

            RestoreRequestResource triggerRestoreRequest = new RestoreRequestResource();

            triggerRestoreRequest.Properties = restoreRequest;

            var response = BmsAdapter.Client.Restores.TriggerWithHttpMessagesAsync(
                resourceName,
                resourceGroupName,
                AzureFabricName,
                containerUri,
                protectedItemUri,
                recoveryPointId,
                triggerRestoreRequest,
                cancellationToken: BmsAdapter.CmdletCancellationToken).Result;

            return(response);
        }
Exemple #3
0
        public BaseRecoveryServicesJobResponse RestoreDisk(AzureVmRecoveryPoint rp, string storageAccountId,
                                                           string storageAccountLocation, string storageAccountType)
        {
            string resourceGroupName = BmsAdapter.GetResourceGroupName();
            string resourceName      = BmsAdapter.GetResourceName();
            string vaultLocation     = BmsAdapter.GetResourceLocation();
            string containerName     = rp.ContainerName;
            string protectedItemName = rp.ItemName;
            string recoveryPointId   = rp.RecoveryPointId;

            //validtion block
            if (storageAccountLocation != vaultLocation)
            {
                throw new Exception(Resources.RestoreDiskIncorrectRegion);
            }
            string vmType = containerName.Split(';')[1].Equals("iaasvmcontainer", StringComparison.OrdinalIgnoreCase)
                ? "Classic" : "Compute";
            string strType = storageAccountType.Equals("Microsoft.ClassicStorage/StorageAccounts",
                                                       StringComparison.OrdinalIgnoreCase) ? "Classic" : "Compute";

            if (vmType != strType)
            {
                throw new Exception(String.Format(Resources.RestoreDiskStorageTypeError, vmType));
            }

            IaasVMRestoreRequest restoreRequest = new IaasVMRestoreRequest()
            {
                AffinityGroup = String.Empty,
                CloudServiceOrResourceGroup = String.Empty,
                CreateNewCloudService       = false,
                RecoveryPointId             = recoveryPointId,
                RecoveryType       = RecoveryType.RestoreDisks,
                Region             = vaultLocation,
                StorageAccountId   = storageAccountId,
                SubnetId           = string.Empty,
                VirtualMachineName = string.Empty,
                VirtualNetworkId   = string.Empty,
            };

            TriggerRestoreRequest triggerRestoreRequest = new TriggerRestoreRequest();

            triggerRestoreRequest.Item            = new RestoreRequestResource();
            triggerRestoreRequest.Item.Properties = new RestoreRequest();
            triggerRestoreRequest.Item.Properties = restoreRequest;

            var response = BmsAdapter.Client.Restores.TriggerRestoreAsync(
                resourceGroupName,
                resourceName,
                BmsAdapter.GetCustomRequestHeaders(),
                AzureFabricName,
                containerName,
                protectedItemName,
                recoveryPointId,
                triggerRestoreRequest,
                BmsAdapter.CmdletCancellationToken).Result;

            return(response);
        }