示例#1
0
        private static ItemBase GetAzureVmItemModelCrr(CrrModel.ProtectedItemResource protectedItem)
        {
            ItemBase itemModel;
            string   policyName = null;
            string   policyId   = ((CrrModel.AzureIaaSVMProtectedItem)protectedItem.Properties).PolicyId;

            if (!string.IsNullOrEmpty(policyId))
            {
                Dictionary <UriEnums, string> keyValueDict =
                    HelperUtils.ParseUri(policyId);
                policyName = HelperUtils.GetPolicyNameFromPolicyId(keyValueDict, policyId);
            }

            string containerUri = HelperUtils.GetContainerUri(
                HelperUtils.ParseUri(protectedItem.Id),
                protectedItem.Id);

            itemModel = new AzureVmItem(
                protectedItem,
                IdUtils.GetNameFromUri(containerUri),
                ContainerType.AzureVM,
                policyName);

            return(itemModel);
        }
        /// <summary>
        /// Lists recovery points generated for the given item
        /// </summary>
        /// <returns>List of recovery point PowerShell model objects</returns>
        public List <CmdletModel.RecoveryPointBase> ListRecoveryPoints()
        {
            DateTime    startDate = (DateTime)(ProviderData[GetRecoveryPointParams.StartDate]);
            DateTime    endDate   = (DateTime)(ProviderData[GetRecoveryPointParams.EndDate]);
            AzureVmItem item      = ProviderData[GetRecoveryPointParams.Item]
                                    as AzureVmItem;

            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
            string containerUri      = HelperUtils.GetContainerUri(uriDict, item.Id);
            string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

            TimeSpan duration = endDate - startDate;

            if (duration.TotalDays > 30)
            {
                throw new Exception(Resources.RestoreDiskTimeRangeError);
            }

            //we need to fetch the list of RPs
            RecoveryPointQueryParameters queryFilter = new RecoveryPointQueryParameters();

            queryFilter.StartDate = CommonHelpers.GetDateTimeStringForService(startDate);
            queryFilter.EndDate   = CommonHelpers.GetDateTimeStringForService(endDate);
            RecoveryPointListResponse rpListResponse = null;

            rpListResponse = ServiceClientAdapter.GetRecoveryPoints(containerUri, protectedItemName, queryFilter);
            return(RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item));
        }
示例#3
0
        /// <summary>
        /// Lists recovery points generated for the given item
        /// </summary>
        /// <returns>List of recovery point PowerShell model objects</returns>
        public List <RecoveryPointBase> ListRecoveryPoints()
        {
            DateTime startDate = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
            DateTime endDate   = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);

            AzureVmItem item = ProviderData[RecoveryPointParams.Item]
                               as AzureVmItem;

            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
            string containerUri      = HelperUtils.GetContainerUri(uriDict, item.Id);
            string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

            TimeSpan duration = endDate - startDate;

            if (duration.TotalDays > 30)
            {
                throw new Exception(Resources.RestoreDiskTimeRangeError);
            }

            //we need to fetch the list of RPs
            var queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
            {
                StartDate = startDate,
                EndDate   = endDate
            });

            ODataQuery <BMSRPQueryObject> queryFilter = new ODataQuery <BMSRPQueryObject>();

            queryFilter.Filter = queryFilterString;

            List <RecoveryPointResource> rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
                containerUri, protectedItemName, queryFilter);

            return(RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item));
        }
示例#4
0
        /// <summary>
        /// Fetches the detail info for the given recovery point
        /// </summary>
        /// <returns>Recovery point detail as returned by the service</returns>
        public RecoveryPointBase GetRecoveryPointDetails()
        {
            AzureVmItem item = ProviderData[RecoveryPointParams.Item]
                               as AzureVmItem;

            string recoveryPointId = ProviderData[RecoveryPointParams.RecoveryPointId].ToString();

            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
            string containerUri      = HelperUtils.GetContainerUri(uriDict, item.Id);
            string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

            var rpResponse = ServiceClientAdapter.GetRecoveryPointDetails(
                containerUri, protectedItemName, recoveryPointId);

            var rp = RecoveryPointConversions.GetPSAzureRecoveryPoints(rpResponse, item) as AzureVmRecoveryPoint;

            if (rp.EncryptionEnabled && rp.KeyAndSecretDetails != null)
            {
                string keyFileDownloadLocation =
                    (string)ProviderData[RecoveryPointParams.KeyFileDownloadLocation];
                string keyFileContent = rp.KeyAndSecretDetails.KeyBackupData;
                if (!string.IsNullOrEmpty(keyFileDownloadLocation))
                {
                    string absoluteFilePath = Path.Combine(keyFileDownloadLocation, "key.blob");
                    File.WriteAllBytes(absoluteFilePath, Convert.FromBase64String(keyFileContent));
                }
            }
            return(rp);
        }
示例#5
0
        /// <summary>
        /// Helper function to convert ps backup policy item from service response.
        /// </summary>
        public static ItemBase GetItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
        {
            ItemBase itemModel = null;

            if (protectedItem != null &&
                protectedItem.Properties != null)
            {
                if (protectedItem.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.AzureIaaSVMProtectedItem)))
                {
                    string policyName = null;
                    string policyId   = ((ServiceClientModel.AzureIaaSVMProtectedItem)protectedItem.Properties).PolicyId;
                    if (!string.IsNullOrEmpty(policyId))
                    {
                        Dictionary <UriEnums, string> keyValueDict =
                            HelperUtils.ParseUri(policyId);
                        policyName = HelperUtils.GetPolicyNameFromPolicyId(keyValueDict, policyId);
                    }

                    string containerUri = HelperUtils.GetContainerUri(
                        HelperUtils.ParseUri(protectedItem.Id),
                        protectedItem.Id);

                    itemModel = new AzureVmItem(
                        protectedItem,
                        IdUtils.GetNameFromUri(containerUri),
                        Cmdlets.Models.ContainerType.AzureVM,
                        policyName);
                }
            }

            return(itemModel);
        }
        /// <summary>
        /// Triggers the disable protection operation for the given item
        /// </summary>
        /// <returns>The job response returned from the service</returns>
        public BaseRecoveryServicesJobResponse DisableProtection()
        {
            bool deleteBackupData = (bool)ProviderData[ItemParams.DeleteBackupData];

            ItemBase itemBase = (ItemBase)
                                ProviderData[ItemParams.Item];

            AzureVmItem item = (AzureVmItem)
                               ProviderData[ItemParams.Item];

            // do validations

            ValidateAzureVMDisableProtectionRequest(itemBase);

            Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id);
            string containerUri     = HelperUtils.GetContainerUri(keyValueDict, item.Id);
            string protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id);

            bool isComputeAzureVM = false;

            if (deleteBackupData)
            {
                return(ServiceClientAdapter.DeleteProtectedItem(
                           containerUri,
                           protectedItemUri));
            }
            else
            {
                isComputeAzureVM = IsComputeAzureVM(item.VirtualMachineId);

                // construct Service Client protectedItem request

                AzureIaaSVMProtectedItem properties;
                if (isComputeAzureVM == false)
                {
                    properties = new AzureIaaSClassicComputeVMProtectedItem();
                }
                else
                {
                    properties = new AzureIaaSComputeVMProtectedItem();
                }

                properties.PolicyId         = string.Empty;
                properties.ProtectionState  = ItemProtectionState.ProtectionStopped.ToString();
                properties.SourceResourceId = item.SourceResourceId;

                ProtectedItemCreateOrUpdateRequest serviceClientRequest = new ProtectedItemCreateOrUpdateRequest()
                {
                    Item = new ProtectedItemResource()
                    {
                        Properties = properties,
                    }
                };

                return(ServiceClientAdapter.CreateOrUpdateProtectedItem(
                           containerUri,
                           protectedItemUri,
                           serviceClientRequest));
            }
        }
        /// <summary>
        /// Triggers the backup operation for the given item
        /// </summary>
        /// <returns>The job response returned from the service</returns>
        public BaseRecoveryServicesJobResponse TriggerBackup()
        {
            ItemBase    item       = (ItemBase)ProviderData[ItemParams.Item];
            AzureVmItem iaasVmItem = item as AzureVmItem;

            return(ServiceClientAdapter.TriggerBackup(IdUtils.GetValueByName(iaasVmItem.Id, IdUtils.IdNames.ProtectionContainerName),
                                                      IdUtils.GetValueByName(iaasVmItem.Id, IdUtils.IdNames.ProtectedItemName)));
        }
示例#8
0
        /// <summary>
        /// Triggers the backup operation for the given item
        /// </summary>
        /// <returns>The job response returned from the service</returns>
        public RestAzureNS.AzureOperationResponse TriggerBackup()
        {
            ItemBase    item           = (ItemBase)ProviderData[ItemParams.Item];
            DateTime?   expiryDateTime = (DateTime?)ProviderData[ItemParams.ExpiryDateTimeUTC];
            AzureVmItem iaasVmItem     = item as AzureVmItem;

            return(ServiceClientAdapter.TriggerBackup(
                       IdUtils.GetValueByName(iaasVmItem.Id, IdUtils.IdNames.ProtectionContainerName),
                       IdUtils.GetValueByName(iaasVmItem.Id, IdUtils.IdNames.ProtectedItemName),
                       expiryDateTime));
        }
        /// <summary>
        /// Fetches the detail info for the given recovery point
        /// </summary>
        /// <returns>Recovery point detail as returned by the service</returns>
        public CmdletModel.RecoveryPointBase GetRecoveryPointDetails()
        {
            AzureVmItem item = ProviderData[GetRecoveryPointParams.Item]
                               as AzureVmItem;

            string recoveryPointId = ProviderData[GetRecoveryPointParams.RecoveryPointId].ToString();

            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
            string containerUri      = HelperUtils.GetContainerUri(uriDict, item.Id);
            string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

            var rpResponse = ServiceClientAdapter.GetRecoveryPointDetails(containerUri, protectedItemName, recoveryPointId);

            return(RecoveryPointConversions.GetPSAzureRecoveryPoints(rpResponse, item));
        }
        /// <summary>
        /// Triggers the enable protection operation for the given item
        /// </summary>
        /// <returns>The job response returned from the service</returns>
        public BaseRecoveryServicesJobResponse EnableProtection()
        {
            string azureVMName              = (string)ProviderData[ItemParams.AzureVMName];
            string azureVMCloudServiceName  = (string)ProviderData[ItemParams.AzureVMCloudServiceName];
            string azureVMResourceGroupName = (string)ProviderData[ItemParams.AzureVMResourceGroupName];
            string parameterSetName         = (string)ProviderData[ItemParams.ParameterSetName];

            PolicyBase policy = (PolicyBase)
                                ProviderData[ItemParams.Policy];

            ItemBase itemBase = (ItemBase)
                                ProviderData[ItemParams.Item];

            AzureVmItem item = (AzureVmItem)
                               ProviderData[ItemParams.Item];
            // do validations

            string containerUri     = "";
            string protectedItemUri = "";
            bool   isComputeAzureVM = false;

            if (itemBase == null)
            {
                isComputeAzureVM = string.IsNullOrEmpty(azureVMCloudServiceName) ? true : false;
                string azureVMRGName = (isComputeAzureVM) ?
                                       azureVMResourceGroupName : azureVMCloudServiceName;

                ValidateAzureVMWorkloadType(policy.WorkloadType);

                ValidateAzureVMEnableProtectionRequest(
                    azureVMName,
                    azureVMCloudServiceName,
                    azureVMResourceGroupName,
                    policy);

                ProtectableObjectResource protectableObjectResource =
                    GetAzureVMProtectableObject(azureVMName, azureVMRGName, isComputeAzureVM);

                Dictionary <UriEnums, string> keyValueDict =
                    HelperUtils.ParseUri(protectableObjectResource.Id);
                containerUri     = HelperUtils.GetContainerUri(keyValueDict, protectableObjectResource.Id);
                protectedItemUri = HelperUtils.GetProtectableItemUri(
                    keyValueDict, protectableObjectResource.Id);
            }
            else
            {
                ValidateAzureVMWorkloadType(item.WorkloadType, policy.WorkloadType);
                ValidateAzureVMModifyProtectionRequest(itemBase, policy);

                isComputeAzureVM = IsComputeAzureVM(item.VirtualMachineId);
                Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id);
                containerUri     = HelperUtils.GetContainerUri(keyValueDict, item.Id);
                protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id);
            }

            // construct Service Client protectedItem request

            AzureIaaSVMProtectedItem properties;

            if (isComputeAzureVM == false)
            {
                properties = new AzureIaaSClassicComputeVMProtectedItem();
            }
            else
            {
                properties = new AzureIaaSComputeVMProtectedItem();
            }

            properties.PolicyId = policy.Id;

            ProtectedItemCreateOrUpdateRequest serviceClientRequest = new ProtectedItemCreateOrUpdateRequest()
            {
                Item = new ProtectedItemResource()
                {
                    Properties = properties,
                }
            };

            return(ServiceClientAdapter.CreateOrUpdateProtectedItem(
                       containerUri,
                       protectedItemUri,
                       serviceClientRequest));
        }
示例#11
0
        // <summary>
        /// Helper function to convert ps recovery point model from service response.
        /// </summary>
        public static RecoveryPointBase GetPSAzureRecoveryPoints(ServiceClientModel.RecoveryPointResponse rpResponse, AzureVmItem item)
        {
            if (rpResponse == null || rpResponse.RecPoint == null)
            {
                throw new ArgumentNullException(Resources.GetRPResponseIsNull);
            }

            ServiceClientModel.RecoveryPoint recPoint = rpResponse.RecPoint.Properties as ServiceClientModel.RecoveryPoint;
            Dictionary <UriEnums, string>    uriDict  = HelperUtils.ParseUri(item.Id);
            string   containerUri      = HelperUtils.GetContainerUri(uriDict, item.Id);
            string   protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
            DateTime recPointTime      = DateTime.ParseExact(
                recPoint.RecoveryPointTime,
                @"MM/dd/yyyy HH:mm:ss",
                CultureInfo.InvariantCulture);

            AzureVmRecoveryPoint result = new AzureVmRecoveryPoint()
            {
                RecoveryPointId      = rpResponse.RecPoint.Name,
                BackupManagementType = item.BackupManagementType,
                ItemName             = protectedItemName,
                ContainerName        = containerUri,
                ContainerType        = item.ContainerType,
                RecoveryPointTime    = recPointTime,
                RecoveryPointType    = recPoint.RecoveryPointType,
                Id           = rpResponse.RecPoint.Id,
                WorkloadType = item.WorkloadType,
                RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
                SourceResourceId            = item.SourceResourceId,
            };

            return(result);
        }
示例#12
0
        /// <summary>
        /// Helper function to convert ps recovery points list model from service response.
        /// </summary>
        public static List <RecoveryPointBase> GetPSAzureRecoveryPoints(ServiceClientModel.RecoveryPointListResponse rpList, AzureVmItem item)
        {
            if (rpList == null || rpList.RecoveryPointList == null ||
                rpList.RecoveryPointList.RecoveryPoints == null)
            {
                throw new ArgumentNullException("RPList");
            }

            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
            string containerUri      = HelperUtils.GetContainerUri(uriDict, item.Id);
            string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

            List <RecoveryPointBase> result = new List <RecoveryPointBase>();

            foreach (ServiceClientModel.RecoveryPointResource rp in rpList.RecoveryPointList.RecoveryPoints)
            {
                ServiceClientModel.RecoveryPoint recPoint = rp.Properties as ServiceClientModel.RecoveryPoint;

                DateTime             recPointTime = DateTime.ParseExact(recPoint.RecoveryPointTime, @"MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                AzureVmRecoveryPoint rpBase       = new AzureVmRecoveryPoint()
                {
                    RecoveryPointId      = rp.Name,
                    BackupManagementType = item.BackupManagementType,
                    ItemName             = protectedItemName,
                    ContainerName        = containerUri,
                    ContainerType        = item.ContainerType,
                    RecoveryPointTime    = recPointTime,
                    RecoveryPointType    = recPoint.RecoveryPointType,
                    Id           = rp.Id,
                    WorkloadType = item.WorkloadType,
                    RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
                    SourceVMStorageType         = recPoint.SourceVMStorageType,
                    SourceResourceId            = item.SourceResourceId,
                };
                result.Add(rpBase);
            }

            return(result);
        }