Example #1
0
        /// <summary>
        /// Lists protection containers according to the provider data
        /// </summary>
        /// <returns>List of protection containers</returns>
        public List <Models.ContainerBase> ListProtectionContainers()
        {
            string name = (string)this.ProviderData[ContainerParams.Name];

            ProtectionContainerListQueryParams queryParams =
                new ProtectionContainerListQueryParams();

            queryParams.BackupManagementType =
                ServiceClientModel.BackupManagementType.AzureSql.ToString();

            var listResponse = ServiceClientAdapter.ListContainers(queryParams);

            List <ContainerBase> containerModels =
                ConversionHelpers.GetContainerModelList(listResponse);

            if (!string.IsNullOrEmpty(name))
            {
                if (containerModels != null)
                {
                    containerModels = containerModels.Where(x => x.Name == name).ToList();
                }
            }

            return(containerModels);
        }
Example #2
0
        /// <summary>
        /// Lists protection containers according to the provider data
        /// </summary>
        /// <returns>List of protection containers</returns>
        public List <ContainerBase> ListProtectionContainers()
        {
            string vaultName         = (string)ProviderData[VaultParams.VaultName];
            string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            string name = (string)ProviderData[ContainerParams.FriendlyName];

            ODataQuery <BMSContainerQueryObject> queryParams =
                new ODataQuery <BMSContainerQueryObject>(
                    q => q.BackupManagementType
                    == ServiceClientModel.BackupManagementType.AzureSql);

            var listResponse = ServiceClientAdapter.ListContainers(
                queryParams,
                vaultName: vaultName,
                resourceGroupName: resourceGroupName);

            List <ContainerBase> containerModels =
                ConversionHelpers.GetContainerModelList(listResponse);

            if (!string.IsNullOrEmpty(name))
            {
                if (containerModels != null)
                {
                    containerModels = containerModels.Where(x => x.Name == name).ToList();
                }
            }

            return(containerModels);
        }
        /// <summary>
        /// Lists containers registered to the recovery services vault according to the provider data
        /// </summary>
        /// <returns>List of protection containers</returns>
        public List <ContainerBase> ListProtectionContainers()
        {
            string name = (string)ProviderData[ContainerParams.Name];

            ODataQuery <BMSContainerQueryObject> queryParams =
                new ODataQuery <BMSContainerQueryObject>(
                    q => q.FriendlyName == name &&
                    q.BackupManagementType == ServiceClientModel.BackupManagementType.MAB);

            var listResponse = ServiceClientAdapter.ListContainers(queryParams);

            List <ContainerBase> containerModels = ConversionHelpers.GetContainerModelList(listResponse);

            return(containerModels);
        }
        public List <CmdletModel.ContainerBase> ListProtectionContainers(
            Dictionary <Enum, object> providerData,
            string backupManagementType)
        {
            string vaultName = (string)providerData[CmdletModel.VaultParams.VaultName];
            string vaultResourceGroupName = (string)providerData[CmdletModel.VaultParams.ResourceGroupName];
            string name         = (string)providerData[CmdletModel.ContainerParams.Name];
            string friendlyName = (string)providerData[CmdletModel.ContainerParams.FriendlyName];

            CmdletModel.ContainerRegistrationStatus status =
                (CmdletModel.ContainerRegistrationStatus)providerData[CmdletModel.ContainerParams.Status];

            string nameQueryFilter = friendlyName;

            if (!string.IsNullOrEmpty(name))
            {
                Logger.Instance.WriteWarning(Resources.GetContainerNameParamDeprecated);

                if (string.IsNullOrEmpty(friendlyName))
                {
                    nameQueryFilter = name;
                }
            }

            ODataQuery <ServiceClientModel.BMSContainerQueryObject> queryParams = null;

            if (status == 0)
            {
                queryParams = new ODataQuery <ServiceClientModel.BMSContainerQueryObject>(
                    q => q.FriendlyName == nameQueryFilter &&
                    q.BackupManagementType == backupManagementType);
            }
            else
            {
                var statusString = status.ToString();
                queryParams = new ODataQuery <ServiceClientModel.BMSContainerQueryObject>(
                    q => q.FriendlyName == nameQueryFilter &&
                    q.BackupManagementType == backupManagementType &&
                    q.Status == statusString);
            }

            var listResponse = ServiceClientAdapter.ListContainers(
                queryParams,
                vaultName: vaultName,
                resourceGroupName: vaultResourceGroupName);

            return(ConversionHelpers.GetContainerModelList(listResponse));
        }
Example #5
0
        private List <ContainerBase> GetRegisteredStorageAccounts(string vaultName = null,
                                                                  string vaultResourceGroupName = null)
        {
            ODataQuery <BMSContainerQueryObject> queryParams = null;

            queryParams = new ODataQuery <BMSContainerQueryObject>(
                q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureStorage);

            var listResponse = ServiceClientAdapter.ListContainers(
                queryParams,
                vaultName: vaultName,
                resourceGroupName: vaultResourceGroupName);

            List <ContainerBase> containerModels = ConversionHelpers.GetContainerModelList(listResponse);

            return(containerModels);
        }
Example #6
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                string containerName = Container != null ? Container.Name : ResourceId.Split('/')[8];
                ConfirmAction(
                    Force.IsPresent,
                    string.Format(Resources.RegisterContainerWarning, containerName),
                    Resources.RegisterContainerMessage,
                    containerName, () =>
                {
                    base.ExecuteCmdlet();

                    ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId);
                    string vaultName = resourceIdentifier.ResourceName;
                    string vaultResourceGroupName = resourceIdentifier.ResourceGroupName;

                    PsBackupProviderManager providerManager =
                        new PsBackupProviderManager(new Dictionary <Enum, object>()
                    {
                        { VaultParams.VaultName, vaultName },
                        { VaultParams.ResourceGroupName, vaultResourceGroupName },
                        { ContainerParams.Name, containerName },
                        { ContainerParams.ContainerType, ServiceClientHelpers.GetServiceClientWorkloadType(WorkloadType).ToString() },
                        { ContainerParams.BackupManagementType, BackupManagementType.ToString() },
                        { ContainerParams.Container, Container }
                    }, ServiceClientAdapter);

                    IPsBackupProvider psBackupProvider =
                        providerManager.GetProviderInstance(WorkloadType, BackupManagementType);
                    psBackupProvider.RegisterContainer();

                    // List containers
                    string backupManagementType = BackupManagementType.ToString();
                    ODataQuery <BMSContainerQueryObject> queryParams = new ODataQuery <BMSContainerQueryObject>(
                        q => q.FriendlyName == containerName &&
                        q.BackupManagementType == backupManagementType);

                    var listResponse = ServiceClientAdapter.ListContainers(queryParams,
                                                                           vaultName: vaultName, resourceGroupName: vaultResourceGroupName);
                    var containerModels = ConversionHelpers.GetContainerModelList(listResponse);
                    WriteObject(containerModels, enumerateCollection: true);
                });
            }, ShouldProcess(ResourceId, VerbsLifecycle.Register));
        }
Example #7
0
        /// <summary>
        /// Lists containers registered to the recovery services vault according to the provider data
        /// </summary>
        /// <returns>List of protection containers</returns>
        public List <Models.ContainerBase> ListProtectionContainers()
        {
            string name = (string)this.ProviderData[ContainerParams.Name];

            ProtectionContainerListQueryParams queryParams = new ProtectionContainerListQueryParams();

            // 1. Filter by Name
            queryParams.FriendlyName = name;

            // 2. Filter by ContainerType
            queryParams.BackupManagementType = ServiceClientModel.BackupManagementType.MAB.ToString();

            var listResponse = ServiceClientAdapter.ListContainers(queryParams);

            List <ContainerBase> containerModels = ConversionHelpers.GetContainerModelList(listResponse);

            return(containerModels);
        }
        /// <summary>
        /// Lists protection containers according to the provider data
        /// </summary>
        /// <returns>List of protection containers</returns>
        public List <ContainerBase> ListProtectionContainers()
        {
            Models.ContainerType containerType =
                (Models.ContainerType) this.ProviderData[ContainerParams.ContainerType];
            Models.BackupManagementType?backupManagementTypeNullable =
                (Models.BackupManagementType?) this.ProviderData[ContainerParams.BackupManagementType];
            string name = (string)this.ProviderData[ContainerParams.Name];
            string resourceGroupName           = (string)this.ProviderData[ContainerParams.ResourceGroupName];
            ContainerRegistrationStatus status =
                (ContainerRegistrationStatus)this.ProviderData[ContainerParams.Status];

            if (backupManagementTypeNullable.HasValue)
            {
                ValidateAzureVMBackupManagementType(backupManagementTypeNullable.Value);
            }

            ProtectionContainerListQueryParams queryParams = new ProtectionContainerListQueryParams();

            // 1. Filter by Name
            queryParams.FriendlyName = name;

            // 2. Filter by ContainerType
            queryParams.BackupManagementType =
                ServiceClientModel.BackupManagementType.AzureIaasVM.ToString();

            // 3. Filter by Status
            if (status != 0)
            {
                queryParams.RegistrationStatus = status.ToString();
            }

            var listResponse = ServiceClientAdapter.ListContainers(queryParams);

            List <ContainerBase> containerModels = ConversionHelpers.GetContainerModelList(listResponse);

            // 4. Filter by RG Name
            if (!string.IsNullOrEmpty(resourceGroupName))
            {
                containerModels = containerModels.Where(containerModel =>
                                                        (containerModel as AzureVmContainer).ResourceGroupName == resourceGroupName).ToList();
            }

            return(containerModels);
        }
Example #9
0
        /// <summary>
        /// Lists protection containers according to the provider data
        /// </summary>
        /// <returns>List of protection containers</returns>
        public List <ContainerBase> ListProtectionContainers()
        {
            ContainerType containerType =
                (ContainerType)ProviderData[ContainerParams.ContainerType];

            CmdletModel.BackupManagementType?backupManagementTypeNullable =
                (CmdletModel.BackupManagementType?)
                ProviderData[ContainerParams.BackupManagementType];
            string name                        = (string)ProviderData[ContainerParams.Name];
            string friendlyName                = (string)ProviderData[ContainerParams.FriendlyName];
            string resourceGroupName           = (string)ProviderData[ContainerParams.ResourceGroupName];
            ContainerRegistrationStatus status =
                (ContainerRegistrationStatus)ProviderData[ContainerParams.Status];

            if (backupManagementTypeNullable.HasValue)
            {
                ValidateAzureVMBackupManagementType(backupManagementTypeNullable.Value);
            }

            string nameQueryFilter = friendlyName;

            if (!string.IsNullOrEmpty(name))
            {
                Logger.Instance.WriteWarning(Resources.GetContainerNameParamDeprecated);

                if (string.IsNullOrEmpty(friendlyName))
                {
                    nameQueryFilter = name;
                }
            }

            ODataQuery <BMSContainerQueryObject> queryParams = null;

            if (status == 0)
            {
                queryParams = new ODataQuery <BMSContainerQueryObject>(
                    q => q.FriendlyName == nameQueryFilter &&
                    q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureIaasVM);
            }
            else
            {
                var statusString = status.ToString();
                queryParams = new ODataQuery <BMSContainerQueryObject>(
                    q => q.FriendlyName == nameQueryFilter &&
                    q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureIaasVM &&
                    q.Status == statusString);
            }

            var listResponse = ServiceClientAdapter.ListContainers(queryParams);

            List <ContainerBase> containerModels = ConversionHelpers.GetContainerModelList(listResponse);

            // 4. Filter by RG Name
            if (!string.IsNullOrEmpty(resourceGroupName))
            {
                containerModels = containerModels.Where(
                    containerModel =>
                {
                    return(string.Compare(
                               (containerModel as AzureVmContainer).ResourceGroupName,
                               resourceGroupName,
                               true) == 0);
                }).ToList();
            }

            return(containerModels);
        }