예제 #1
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

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

                WriteDebug(string.Format("Input params - Name:{0}, " +
                                         "WorkloadType: {1}, BackupManagementType:{2}, " +
                                         "ParameterSetName: {3}",
                                         Name == null ? "NULL" : Name,
                                         WorkloadType.HasValue ? WorkloadType.ToString() : "NULL",
                                         BackupManagementType.HasValue ?
                                         BackupManagementType.ToString() : "NULL",
                                         this.ParameterSetName));

                if (ParameterSetName == PolicyNameParamSet)
                {
                    // validate policyName
                    PolicyCmdletHelpers.ValidateProtectionPolicyName(Name);

                    // query service
                    ServiceClientModel.ProtectionPolicyResource policy =
                        PolicyCmdletHelpers.GetProtectionPolicyByName(
                            Name,
                            ServiceClientAdapter,
                            vaultName: vaultName,
                            resourceGroupName: resourceGroupName);
                    if (policy == null)
                    {
                        throw new ArgumentException(string.Format(Resources.PolicyNotFoundException, Name));
                    }

                    WriteObject(ConversionHelpers.GetPolicyModel(policy));
                }
                else
                {
                    List <PolicyBase> policyList     = new List <PolicyBase>();
                    string serviceClientProviderType = null;

                    switch (this.ParameterSetName)
                    {
                    case WorkloadParamSet:
                        if (WorkloadType == Models.WorkloadType.AzureVM)
                        {
                            serviceClientProviderType =
                                ServiceClientHelpers.GetServiceClientProviderType(Models.WorkloadType.AzureVM);
                        }
                        else if (WorkloadType == Models.WorkloadType.AzureSQLDatabase)
                        {
                            serviceClientProviderType = ServiceClientHelpers.GetServiceClientProviderType(Models.WorkloadType.AzureSQLDatabase);
                        }
                        else if (WorkloadType == Models.WorkloadType.AzureFiles)
                        {
                            serviceClientProviderType = ServiceClientHelpers.GetServiceClientProviderType(Models.WorkloadType.AzureFiles);
                        }
                        else if (WorkloadType == Models.WorkloadType.MSSQL)
                        {
                            serviceClientProviderType = ServiceClientHelpers.GetServiceClientProviderType(Models.WorkloadType.MSSQL);
                        }
                        break;

                    case WorkloadBackupMangementTypeParamSet:
                        if (WorkloadType == Models.WorkloadType.AzureVM)
                        {
                            if (BackupManagementType != Models.BackupManagementType.AzureVM)
                            {
                                throw new ArgumentException(
                                    Resources.AzureVMUnsupportedBackupManagementTypeException);
                            }
                            serviceClientProviderType = ServiceClientHelpers.
                                                        GetServiceClientProviderType(Models.WorkloadType.AzureVM);
                        }
                        else if (WorkloadType == Models.WorkloadType.AzureSQLDatabase)
                        {
                            if (BackupManagementType != Models.BackupManagementType.AzureSQL)
                            {
                                throw new ArgumentException(
                                    Resources.AzureSqlUnsupportedBackupManagementTypeException);
                            }
                            serviceClientProviderType =
                                ServiceClientHelpers.GetServiceClientProviderType(
                                    Models.WorkloadType.AzureSQLDatabase);
                        }
                        else if (WorkloadType == Models.WorkloadType.AzureFiles)
                        {
                            if (BackupManagementType != Models.BackupManagementType.AzureStorage)
                            {
                                throw new ArgumentException(
                                    Resources.AzureFileUnsupportedBackupManagementTypeException);
                            }
                            serviceClientProviderType =
                                ServiceClientHelpers.GetServiceClientProviderType(
                                    Models.WorkloadType.AzureFiles);
                        }
                        else if (WorkloadType == Models.WorkloadType.AzureFiles)
                        {
                            if (BackupManagementType != Models.BackupManagementType.AzureStorage)
                            {
                                throw new ArgumentException(
                                    Resources.AzureFileUnsupportedBackupManagementTypeException);
                            }
                            serviceClientProviderType =
                                ServiceClientHelpers.GetServiceClientProviderType(
                                    Models.WorkloadType.AzureFiles);
                        }
                        else if (WorkloadType == Models.WorkloadType.MSSQL)
                        {
                            if (BackupManagementType != Models.BackupManagementType.AzureWorkload)
                            {
                                throw new ArgumentException(
                                    Resources.AzureFileUnsupportedBackupManagementTypeException);
                            }
                            serviceClientProviderType =
                                ServiceClientHelpers.GetServiceClientProviderType(
                                    Models.WorkloadType.MSSQL);
                        }
                        else
                        {
                            throw new ArgumentException(string.Format(
                                                            Resources.UnsupportedWorkloadBackupManagementTypeException,
                                                            WorkloadType.ToString(),
                                                            BackupManagementType.ToString()));
                        }
                        break;

                    default:
                        break;
                    }

                    var backupManagementTypeFilter = serviceClientProviderType;


                    ODataQuery <ServiceClientModel.ProtectionPolicyQueryObject> queryParams
                        = new ODataQuery <ServiceClientModel.ProtectionPolicyQueryObject>(
                              q => q.BackupManagementType == backupManagementTypeFilter);

                    WriteDebug("going to query service to get list of policies");
                    List <ServiceClientModel.ProtectionPolicyResource> respList =
                        ServiceClientAdapter.ListProtectionPolicy(
                            queryParams,
                            vaultName: vaultName,
                            resourceGroupName: resourceGroupName);
                    WriteDebug("Successfully got response from service");

                    policyList = ConversionHelpers.GetPolicyModelList(respList);
                    WriteObject(policyList, enumerateCollection: true);
                }
            });
        }
예제 #2
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                WriteDebug(string.Format("Input params - Name:{0}, " +
                                         "WorkloadType: {1}, BackupManagementType:{2}, " +
                                         "ParameterSetName: {3}",
                                         Name == null ? "NULL" : Name,
                                         WorkloadType.HasValue ? WorkloadType.ToString() : "NULL",
                                         BackupManagementType.HasValue ?
                                         BackupManagementType.ToString() : "NULL",
                                         this.ParameterSetName));

                if (this.ParameterSetName == PolicyNameParamSet)
                {
                    // validate policyName
                    PolicyCmdletHelpers.ValidateProtectionPolicyName(Name);

                    // query service
                    ServiceClientModel.ProtectionPolicyResponse policy =
                        PolicyCmdletHelpers.GetProtectionPolicyByName(
                            Name,
                            ServiceClientAdapter);
                    if (policy == null)
                    {
                        throw new ArgumentException(string.Format(Resources.PolicyNotFoundException, Name));
                    }

                    WriteObject(ConversionHelpers.GetPolicyModel(policy.Item));
                }
                else
                {
                    List <PolicyBase> policyList     = new List <PolicyBase>();
                    string serviceClientProviderType = null;

                    switch (this.ParameterSetName)
                    {
                    case WorkloadParamSet:
                        if (WorkloadType == Models.WorkloadType.AzureVM)
                        {
                            serviceClientProviderType =
                                ServiceClientHelpers.GetServiceClientProviderType(Models.WorkloadType.AzureVM);
                        }
                        break;

                    case WorkloadBackupMangementTypeParamSet:
                        if (WorkloadType == Models.WorkloadType.AzureVM)
                        {
                            if (BackupManagementType != Models.BackupManagementType.AzureVM)
                            {
                                throw new ArgumentException(
                                    Resources.AzureVMUnsupportedBackupManagementTypeException);
                            }
                            serviceClientProviderType = ServiceClientHelpers.
                                                        GetServiceClientProviderType(Models.WorkloadType.AzureVM);
                        }
                        else
                        {
                            throw new ArgumentException(string.Format(
                                                            Resources.UnsupportedWorkloadBackupManagementTypeException,
                                                            WorkloadType.ToString(),
                                                            BackupManagementType.ToString()));
                        }
                        break;

                    default:
                        break;
                    }

                    ServiceClientModel.ProtectionPolicyQueryParameters queryParams =
                        new ServiceClientModel.ProtectionPolicyQueryParameters()
                    {
                        BackupManagementType = serviceClientProviderType
                    };

                    WriteDebug("going to query service to get list of policies");
                    ServiceClientModel.ProtectionPolicyListResponse respList =
                        ServiceClientAdapter.ListProtectionPolicy(queryParams);
                    WriteDebug("Successfully got response from service");

                    policyList = ConversionHelpers.GetPolicyModelList(respList);
                    WriteObject(policyList, enumerateCollection: true);
                }
            });
        }