public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                BackupManagementType?backupManagementTypeNullable = null;
                BackupManagementType backupManagementType;
                if (BackupManagementType != null)
                {
                    Enum.TryParse(BackupManagementType, out backupManagementType);
                    backupManagementTypeNullable = backupManagementType;
                }

                // Forcing this cmdlet to return only Registered containers for now.
                // Once we support containers returning other status types, one can undo this behavior.
                Status = ContainerRegistrationStatus.Registered;

                PsBackupProviderManager providerManager =
                    new PsBackupProviderManager(new Dictionary <Enum, object>()
                {
                    { ContainerParams.ContainerType, ContainerType },
                    { ContainerParams.BackupManagementType, backupManagementTypeNullable },
                    { ContainerParams.Name, Name },
                    { ContainerParams.FriendlyName, FriendlyName },
                    { ContainerParams.ResourceGroupName, ResourceGroupName },
                    { ContainerParams.Status, Status },
                }, ServiceClientAdapter);

                IPsBackupProvider psBackupProvider =
                    providerManager.GetProviderInstance(ContainerType, backupManagementTypeNullable);
                var containerModels = psBackupProvider.ListProtectionContainers();
                WriteObject(containerModels, enumerateCollection: true);
            });
        }
 public AzureContainer(ProtectionContainerResource protectionContainer)
     : base(protectionContainer)
 {
     ResourceGroupName = IdUtils.GetResourceGroupName(protectionContainer.Id);
     FriendlyName      = protectionContainer.Properties.FriendlyName;
     Status            = EnumUtils.GetEnum <ContainerRegistrationStatus>(protectionContainer.Properties.RegistrationStatus);
 }
Example #3
0
 public MabContainer(ProtectionContainerResource protectionContainer)
     : base(protectionContainer)
 {
     MabProtectionContainer mabProtectionContainer = (MabProtectionContainer)protectionContainer.Properties;
     FriendlyName = mabProtectionContainer.FriendlyName;
     Status = EnumUtils.GetEnum<ContainerRegistrationStatus>(mabProtectionContainer.RegistrationStatus);
 }
Example #4
0
 public MabContainer(ServiceClientModel.ProtectionContainerResource protectionContainer)
     : base(protectionContainer)
 {
     ServiceClientModel.MabContainer mabProtectionContainer =
         (ServiceClientModel.MabContainer)protectionContainer.Properties;
     FriendlyName = mabProtectionContainer.FriendlyName;
     Status       = EnumUtils.GetEnum <ContainerRegistrationStatus>(mabProtectionContainer.RegistrationStatus);
 }
 // <summary>
 /// Constructor. Takes the service client object representing the container 
 /// and converts it in to the PS container model
 /// </summary>
 /// <param name="protectionContainer">Service client object representing the container</param>
 public AzureSqlContainer(ProtectionContainerResource protectionContainer)
     : base(protectionContainer)
 {
     AzureSqlProtectionContainer sqlProtectionContainer = 
         (AzureSqlProtectionContainer)protectionContainer.Properties;
     Status = EnumUtils.GetEnum<ContainerRegistrationStatus>(
         sqlProtectionContainer.RegistrationStatus);
 }
 /// <summary>
 /// Constructor. Takes the service client object representing the container 
 /// and converts it in to the PS container model
 /// </summary>
 /// <param name="protectionContainer">Service client object representing the container</param>
 public AzureVmContainer(ProtectionContainerResource protectionContainer)
     : base(protectionContainer)
 {
     AzureIaaSVMProtectionContainer iaasVmProtectionContainer = (AzureIaaSVMProtectionContainer)protectionContainer.Properties;
     ResourceGroupName = IdUtils.GetResourceGroupName(protectionContainer.Id);
     FriendlyName = iaasVmProtectionContainer.FriendlyName;
     Status = EnumUtils.GetEnum<ContainerRegistrationStatus>(iaasVmProtectionContainer.RegistrationStatus);
 }
 /// <summary>
 /// Constructor. Takes the service client object representing the container
 /// and converts it in to the PS container model
 /// </summary>
 /// <param name="protectionContainer">Service client object representing the container</param>
 public AzureSqlContainer(
     ServiceClientModel.ProtectionContainerResource protectionContainer)
     : base(protectionContainer)
 {
     ServiceClientModel.AzureSqlContainer sqlProtectionContainer =
         (ServiceClientModel.AzureSqlContainer)protectionContainer.Properties;
     Status = EnumUtils.GetEnum <ContainerRegistrationStatus>(
         sqlProtectionContainer.RegistrationStatus);
 }
Example #8
0
        /// <summary>
        /// Constructor. Takes the service client object representing the container
        /// and converts it in to the PS container model
        /// </summary>
        /// <param name="protectionContainer">Service client object representing the container</param>
        public AzureVmContainer(ProtectionContainerResource protectionContainer)
            : base(protectionContainer)
        {
            AzureIaaSVMProtectionContainer iaasVmProtectionContainer = (AzureIaaSVMProtectionContainer)protectionContainer.Properties;

            ResourceGroupName = IdUtils.GetResourceGroupName(protectionContainer.Id);
            FriendlyName      = iaasVmProtectionContainer.FriendlyName;
            Status            = EnumUtils.GetEnum <ContainerRegistrationStatus>(iaasVmProtectionContainer.RegistrationStatus);
        }
        // <summary>
        /// Constructor. Takes the service client object representing the container
        /// and converts it in to the PS container model
        /// </summary>
        /// <param name="protectionContainer">Service client object representing the container</param>
        public AzureSqlContainer(ProtectionContainerResource protectionContainer)
            : base(protectionContainer)
        {
            AzureSqlProtectionContainer sqlProtectionContainer =
                (AzureSqlProtectionContainer)protectionContainer.Properties;

            Status = EnumUtils.GetEnum <ContainerRegistrationStatus>(
                sqlProtectionContainer.RegistrationStatus);
        }
        /// <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 #11
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);
        }