GetPSLongTermRetentionPolicy() public static method

Helper function to convert ps long term retention policy from service response.
public static GetPSLongTermRetentionPolicy ( Microsoft.Azure.Management.RecoveryServices.Backup.Models serviceClientRetPolicy ) : LongTermRetentionPolicy
serviceClientRetPolicy Microsoft.Azure.Management.RecoveryServices.Backup.Models
return LongTermRetentionPolicy
        /// <summary>
        /// Helper function to convert ps backup policy model for AzureVM from service response.
        /// </summary>
        public static PolicyBase GetPolicyModelForAzureIaaSVM(ServiceClientModel.ProtectionPolicyResource serviceClientResponse,
                                                              PolicyBase policyModel)
        {
            if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy.GetType() !=
                typeof(ServiceClientModel.LongTermRetentionPolicy))
            {
                Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
                                           ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy.GetType());
                Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
                return(null);
            }

            if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy.GetType() !=
                typeof(ServiceClientModel.SimpleSchedulePolicy))
            {
                Logger.Instance.WriteDebug("Unknown SchedulePolicy object received: " +
                                           ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy.GetType());
                Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
                return(null);
            }

            policyModel = new AzureVmPolicy();
            AzureVmPolicy iaasPolicyModel = policyModel as AzureVmPolicy;

            iaasPolicyModel.WorkloadType         = WorkloadType.AzureVM;
            iaasPolicyModel.BackupManagementType = BackupManagementType.AzureVM;
            iaasPolicyModel.RetentionPolicy      = PolicyHelpers.GetPSLongTermRetentionPolicy((ServiceClientModel.LongTermRetentionPolicy)
                                                                                                  ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy,
                                                                                              ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TimeZone);
            iaasPolicyModel.SchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy((ServiceClientModel.SimpleSchedulePolicy)
                                                                                         ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy,
                                                                                     ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TimeZone);
            return(policyModel);
        }
Example #2
0
        /// <summary>
        /// Helper function to convert ps backup policy model from service response.
        /// </summary>
        public static PolicyBase GetPolicyModel(ServiceClientModel.ProtectionPolicyResource serviceClientResponse)
        {
            PolicyBase policyModel = null;

            if (serviceClientResponse == null || serviceClientResponse.Properties == null)
            {
                Logger.Instance.WriteDebug("Policy Service Client response is Null/Empty");
                throw new ArgumentException(Resources.EmptyServiceClientResponseException);
            }

            if (serviceClientResponse.Properties.GetType() == typeof(ServiceClientModel.AzureIaaSVMProtectionPolicy))
            {
                if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy.GetType() !=
                    typeof(ServiceClientModel.LongTermRetentionPolicy))
                {
                    Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
                                               ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy.GetType());
                    Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
                    return(null);
                }

                if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy.GetType() !=
                    typeof(ServiceClientModel.SimpleSchedulePolicy))
                {
                    Logger.Instance.WriteDebug("Unknown SchedulePolicy object received: " +
                                               ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy.GetType());
                    Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
                    return(null);
                }

                policyModel = new AzureVmPolicy();
                AzureVmPolicy iaasPolicyModel = policyModel as AzureVmPolicy;
                iaasPolicyModel.WorkloadType         = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType.AzureVM;
                iaasPolicyModel.BackupManagementType = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.BackupManagementType.AzureVM;
                iaasPolicyModel.RetentionPolicy      = PolicyHelpers.GetPSLongTermRetentionPolicy((ServiceClientModel.LongTermRetentionPolicy)
                                                                                                      ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy);
                iaasPolicyModel.SchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy((ServiceClientModel.SimpleSchedulePolicy)
                                                                                             ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy);
            }
            else
            {
                // we will enter this case when service supports new workload and customer
                // still using old version of azure powershell. Trace warning message, ignore and return
                Logger.Instance.WriteDebug("Unknown Policy object received: " +
                                           serviceClientResponse.Properties.GetType());
                Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
                return(null);
            }

            policyModel.Name = serviceClientResponse.Name;
            policyModel.Id   = serviceClientResponse.Id;

            return(policyModel);
        }
        /// <summary>
        /// Helper function to convert ps backup policy model for AzureVM from service response.
        /// </summary>
        public static PolicyBase GetPolicyModelForAzureIaaSVM(ServiceClientModel.ProtectionPolicyResource serviceClientResponse,
                                                              PolicyBase policyModel)
        {
            string backupManagementType = Management.RecoveryServices.Backup.Models.BackupManagementType.AzureIaasVM;

            if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy.GetType() !=
                typeof(ServiceClientModel.LongTermRetentionPolicy))
            {
                Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
                                           ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy.GetType());
                Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
                return(null);
            }

            if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy.GetType() !=
                typeof(ServiceClientModel.SimpleSchedulePolicy))
            {
                Logger.Instance.WriteDebug("Unknown SchedulePolicy object received: " +
                                           ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy.GetType());
                Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
                return(null);
            }

            policyModel = new AzureVmPolicy();
            AzureVmPolicy iaasPolicyModel = policyModel as AzureVmPolicy;

            iaasPolicyModel.WorkloadType            = WorkloadType.AzureVM;
            iaasPolicyModel.BackupManagementType    = BackupManagementType.AzureVM;
            iaasPolicyModel.SnapshotRetentionInDays = ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.
                                                       Properties).InstantRpRetentionRangeInDays;
            iaasPolicyModel.ProtectedItemsCount = ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.
                                                   Properties).ProtectedItemsCount;
            iaasPolicyModel.RetentionPolicy = PolicyHelpers.GetPSLongTermRetentionPolicy((ServiceClientModel.LongTermRetentionPolicy)
                                                                                             ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy,
                                                                                         ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TimeZone,
                                                                                         backupManagementType);
            iaasPolicyModel.SchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy((ServiceClientModel.SimpleSchedulePolicy)
                                                                                         ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy,
                                                                                     ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TimeZone);
            iaasPolicyModel.AzureBackupRGName =
                ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).InstantRPDetails.AzureBackupRGNamePrefix;
            iaasPolicyModel.AzureBackupRGNameSuffix =
                ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).InstantRPDetails.AzureBackupRGNameSuffix;
            return(policyModel);
        }
Example #4
0
        /// <summary>
        /// Helper function to convert ps backup policy model for Azure FileShare from service response.
        /// </summary>
        public static PolicyBase GetPolicyModelForAzureFileShare(ServiceClientModel.ProtectionPolicyResource serviceClientResponse,
                                                                 PolicyBase policyModel)
        {
            string backupManagementType = Management.RecoveryServices.Backup.Models.BackupManagementType.AzureStorage;

            ServiceClientModel.AzureFileShareProtectionPolicy azureFileSharePolicy =
                (ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties;

            if (azureFileSharePolicy.RetentionPolicy.GetType() !=
                typeof(ServiceClientModel.LongTermRetentionPolicy))
            {
                Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
                                           azureFileSharePolicy.RetentionPolicy.GetType());
                Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
                return(null);
            }

            if (azureFileSharePolicy.SchedulePolicy.GetType() !=
                typeof(ServiceClientModel.SimpleSchedulePolicy))
            {
                Logger.Instance.WriteDebug("Unknown SchedulePolicy object received: " +
                                           azureFileSharePolicy.SchedulePolicy.GetType());
                Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
                return(null);
            }


            policyModel = new AzureFileSharePolicy();
            AzureFileSharePolicy fileSharePolicyModel = policyModel as AzureFileSharePolicy;

            fileSharePolicyModel.WorkloadType         = WorkloadType.AzureFiles;
            fileSharePolicyModel.BackupManagementType = BackupManagementType.AzureStorage;
            fileSharePolicyModel.RetentionPolicy      =
                PolicyHelpers.GetPSLongTermRetentionPolicy((ServiceClientModel.LongTermRetentionPolicy)((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy,
                                                           ((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).TimeZone, backupManagementType);
            fileSharePolicyModel.SchedulePolicy =
                PolicyHelpers.GetPSSimpleSchedulePolicy((ServiceClientModel.SimpleSchedulePolicy)
                                                            ((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy,
                                                        ((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).TimeZone);
            fileSharePolicyModel.ProtectedItemsCount = ((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.
                                                        Properties).ProtectedItemsCount;
            return(policyModel);
        }
        public static void GetPSSubProtectionPolicy(AzureVmWorkloadPolicy azureVmWorkloadPolicyModel,
                                                    ServiceClientModel.ProtectionPolicyResource serviceClientResponse, string timeZone)
        {
            foreach (var subProtectionPolicy in
                     ((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).SubProtectionPolicy)
            {
                if (string.Compare(subProtectionPolicy.PolicyType, "Full") == 0)
                {
                    azureVmWorkloadPolicyModel.FullBackupSchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy(
                        (ServiceClientModel.SimpleSchedulePolicy)subProtectionPolicy.SchedulePolicy,
                        ((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);

                    azureVmWorkloadPolicyModel.FullBackupRetentionPolicy = PolicyHelpers.GetPSLongTermRetentionPolicy(
                        (ServiceClientModel.LongTermRetentionPolicy)subProtectionPolicy.RetentionPolicy,
                        ((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);
                }
                else if (string.Compare(subProtectionPolicy.PolicyType, "Differential") == 0)
                {
                    azureVmWorkloadPolicyModel.DifferentialBackupSchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy(
                        (ServiceClientModel.SimpleSchedulePolicy)subProtectionPolicy.SchedulePolicy,
                        ((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);
                    azureVmWorkloadPolicyModel.DifferentialBackupRetentionPolicy = PolicyHelpers.GetPSSimpleRetentionPolicy(
                        (ServiceClientModel.SimpleRetentionPolicy)subProtectionPolicy.RetentionPolicy,
                        ((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone, "AzureWorkload");
                    azureVmWorkloadPolicyModel.IsDifferentialBackupEnabled = true;
                }
                else if (string.Compare(subProtectionPolicy.PolicyType, "Log") == 0)
                {
                    azureVmWorkloadPolicyModel.LogBackupSchedulePolicy = PolicyHelpers.GetPSLogSchedulePolicy((ServiceClientModel.LogSchedulePolicy)
                                                                                                              subProtectionPolicy.SchedulePolicy,
                                                                                                              ((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);
                    azureVmWorkloadPolicyModel.LogBackupRetentionPolicy = PolicyHelpers.GetPSSimpleRetentionPolicy((ServiceClientModel.SimpleRetentionPolicy)
                                                                                                                   subProtectionPolicy.RetentionPolicy,
                                                                                                                   ((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone, "AzureWorkload");
                    azureVmWorkloadPolicyModel.IsLogBackupEnabled = true;
                }
            }
        }