Ejemplo n.º 1
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)))
                {
                    itemModel = GetAzureVmItemModel(protectedItem);
                }

                if (protectedItem.Properties.GetType() ==
                    typeof(ServiceClientModel.AzureSqlProtectedItem))
                {
                    itemModel = GetAzureSqlItemModel(protectedItem);
                }

                if (protectedItem.Properties.GetType() ==
                    typeof(ServiceClientModel.AzureFileshareProtectedItem))
                {
                    itemModel = GetAzureFileShareItemModel(protectedItem);
                }

                if (protectedItem.Properties.GetType() ==
                    typeof(ServiceClientModel.AzureVmWorkloadSQLDatabaseProtectedItem))
                {
                    itemModel = GetAzureVmWorkloadItemModel(protectedItem);
                }
            }

            return(itemModel);
        }
Ejemplo n.º 2
0
        private static ItemBase GetAzureSqlItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
        {
            ItemBase itemModel;

            ServiceClientModel.AzureSqlProtectedItem azureSqlProtectedItem =
                (ServiceClientModel.AzureSqlProtectedItem)protectedItem.Properties;
            string policyName = null;
            string policyId   = azureSqlProtectedItem.PolicyId;

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

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

            itemModel = new AzureSqlItem(
                protectedItem,
                IdUtils.GetNameFromUri(containerUri),
                ContainerType.AzureSQL,
                policyName);
            return(itemModel);
        }
Ejemplo n.º 3
0
        private static ItemBase GetAzureVmWorkloadSAPHanaItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
        {
            ItemBase itemModel;
            string   policyName = null;
            // can try changing it to AzureVmWorkloadProtectedItem
            string policyId = ((ServiceClientModel.AzureVmWorkloadSAPHanaDatabaseProtectedItem)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 AzureWorkloadSAPHanaDatabaseProtectedItem(
                protectedItem,
                containerUri,
                ContainerType.AzureVMAppContainer,
                policyName);

            return(itemModel);
        }
        public void EnableAzureBackupProtectionTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];

                var client = GetServiceClient<RecoveryServicesBackupManagementClient>(resourceNamespace);

                ProtectedItemCreateOrUpdateRequest input = new ProtectedItemCreateOrUpdateRequest();
                AzureIaaSClassicComputeVMProtectedItem iaasVmProtectedItem = new AzureIaaSClassicComputeVMProtectedItem();
                iaasVmProtectedItem.PolicyId = ConfigurationManager.AppSettings["RsVaultIaasVMDefaultPolicyId"];

                ProtectedItemResource protectedItemResource = new ProtectedItemResource();
                protectedItemResource.Properties = iaasVmProtectedItem;
                input.Item = protectedItemResource;

                string itemUniqueName = ConfigurationManager.AppSettings["RsVaultIaasV1ContainerUniqueName"];
                string containerUniqueName = ConfigurationManager.AppSettings["RsVaultIaasV1ContainerUniqueName"];
                string containeType = ConfigurationManager.AppSettings["IaaSVMContainerType"];
                string itemType = ConfigurationManager.AppSettings["IaaSVMItemType"];
                string containerName = containeType + ";" + containerUniqueName;
                string itemName = itemType + ";" + itemUniqueName;
                string fabricName = ConfigurationManager.AppSettings["AzureBackupFabricName"];

                string rsVaultRgName = CommonTestHelper.GetSetting(TestConstants.RsVaultRgName);
                string rsVaultName = CommonTestHelper.GetSetting(TestConstants.RsVaultName);

                ProtectedItemTestHelper protectedItemTestHelper = new ProtectedItemTestHelper(client);

                var response = protectedItemTestHelper.AddOrUpdateProtectedItem(fabricName,
                    containerName, itemName, input);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
0
 public ItemBase(ServiceClientModel.ProtectedItemResource protectedItemResource,
                 string containerName, ContainerType containerType)
     : base((ServiceClientModel.ProtectedItem)protectedItemResource.Properties, containerName, containerType)
 {
     ServiceClientModel.ProtectedItem protectedItem = (ServiceClientModel.ProtectedItem)protectedItemResource.Properties;
     Name = protectedItemResource.Name;
     Id   = protectedItemResource.Id;
     LatestRecoveryPoint = protectedItem.LastRecoveryPoint;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructor. Takes the service client object representing the protected item 
 /// and converts it in to the PS protected item model
 /// </summary>
 /// <param name="protectedItemResource">Service client object representing the protected item resource</param>
 /// <param name="containerName">Name of the container associated with this protected item</param>
 /// <param name="containerType">Type of the container associated with this protected item</param>
 /// <param name="policyName">Name of the protection policy associated with this protected item</param>
 public AzureSqlItem(ProtectedItemResource protectedItemResource,
     string containerName, ContainerType containerType, string policyName)
     : base(protectedItemResource, containerName, containerType)
 {
     AzureSqlProtectedItem protectedItem = 
         (AzureSqlProtectedItem)protectedItemResource.Properties;
     ProtectedItemDataId = protectedItem.ProtectedItemDataId;
     ProtectionState = protectedItem.ProtectionState;
     ProtectionPolicyName = policyName;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Constructor. Takes the service client object representing the protected item 
 /// and converts it in to the PS protected item model
 /// </summary>
 /// <param name="protectedItemResource">Service client object representing the protected item resource</param>
 /// <param name="containerName">Name of the container associated with this protected item</param>
 /// <param name="containerType">Type of the container associated with this protected item</param>
 /// <param name="policyName">Name of the protection policy associated with this protected item</param>
 public AzureVmItem(ProtectedItemResource protectedItemResource,
     string containerName, ContainerType containerType, string policyName)
     : base(protectedItemResource, containerName, containerType)
 {
     AzureIaaSVMProtectedItem protectedItem = (AzureIaaSVMProtectedItem)protectedItemResource.Properties;
     LastBackupStatus = protectedItem.LastBackupStatus;
     ProtectionPolicyName = policyName;
     ProtectionState = EnumUtils.GetEnum<ItemProtectionState>(protectedItem.ProtectionState);
     ProtectionStatus = EnumUtils.GetEnum<ItemProtectionStatus>(protectedItem.ProtectionStatus);
     VirtualMachineId = protectedItem.VirtualMachineId;
 }
Ejemplo n.º 9
0
        private static ItemBase GetMabItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
        {
            ItemBase itemModel;

            string containerUri = (protectedItem.Properties as ServiceClientModel.MabFileFolderProtectedItem).ContainerName;

            itemModel = new MabItem(
                protectedItem,
                containerUri,
                ContainerType.Windows,
                null);
            return(itemModel);
        }
Ejemplo n.º 10
0
        private static ItemBase GetAzureFileShareItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
        {
            ItemBase itemModel;
            string   policyName = null;
            string   policyId   = ((ServiceClientModel.AzureFileshareProtectedItem)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 AzureFileShareItem(
                protectedItem,
                containerUri,
                ContainerType.AzureStorage,
                policyName);
            return(itemModel);
        }
        public void EnableProtection(string vaultRgName, string vaultName, string policyId, string containerUri, string itemUri)
        {
            string fabricName = ConfigurationManager.AppSettings["AzureBackupFabricName"];

            ProtectedItemCreateOrUpdateRequest input = new ProtectedItemCreateOrUpdateRequest();
            AzureIaaSClassicComputeVMProtectedItem iaasVmProtectedItem = new AzureIaaSClassicComputeVMProtectedItem();
            iaasVmProtectedItem.PolicyId = policyId;
            ProtectedItemResource protectedItemResource = new ProtectedItemResource();
            protectedItemResource.Properties = iaasVmProtectedItem;
            input.Item = protectedItemResource;

            AddOrUpdateProtectedItem(vaultRgName, vaultName, fabricName, containerUri, itemUri, input);
        }