public void ListProtectionPolicyTest() { using (UndoContext context = UndoContext.Current) { context.Start(); string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"]; string resourceGroupName = ConfigurationManager.AppSettings["RsVaultRgNameRP"]; string resourceName = ConfigurationManager.AppSettings["RsVaultNameRP"]; string location = ConfigurationManager.AppSettings["vaultLocationRP"]; var client = GetServiceClient<RecoveryServicesBackupManagementClient>(resourceNamespace); // 1. Create vault VaultTestHelpers vaultTestHelper = new VaultTestHelpers(client); vaultTestHelper.CreateVault(resourceGroupName, resourceName, location); // ACTION: List policies PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client); ProtectionPolicyQueryParameters queryParams = new ProtectionPolicyQueryParameters(); ProtectionPolicyListResponse response = policyTestHelper.ListProtectionPolicy(resourceGroupName, resourceName, queryParams); // VALIDATION: At least default policy is expected Assert.NotNull(response.ItemList); Assert.NotNull(response.ItemList.Value); Assert.NotEmpty(response.ItemList.Value); foreach (ProtectionPolicyResource resource in response.ItemList.Value) { Assert.NotNull(resource.Id); Assert.NotNull(resource.Name); Assert.NotNull(resource.Type); Assert.NotNull(resource.Properties); } } }
public void ListProtectionPolicyTest() { using (UndoContext context = UndoContext.Current) { context.Start(); string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"]; string rsVaultRgName = CommonTestHelper.GetSetting(TestConstants.RsVaultRgName); string rsVaultName = CommonTestHelper.GetSetting(TestConstants.RsVaultName); var client = GetServiceClient<RecoveryServicesBackupManagementClient>(resourceNamespace); PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client); ProtectionPolicyQueryParameters queryParams = new ProtectionPolicyQueryParameters(); queryParams.BackupManagementType = ConfigurationManager.AppSettings["ProviderTypeAzureSql"]; ProtectionPolicyListResponse response = policyTestHelper.ListProtectionPolicy(rsVaultRgName, rsVaultName, queryParams); // atleast one default policy is expected Assert.NotNull(response.ItemList); Assert.NotNull(response.ItemList.Value); IList<ProtectionPolicyResource> policyList = response.ItemList.Value; // atleast one default policy should be there Assert.NotEmpty(policyList); foreach (ProtectionPolicyResource resource in policyList) { Assert.NotNull(resource.Id); Assert.NotNull(resource.Name); Assert.NotNull(resource.Type); Assert.NotNull(resource.Properties); } } }
public ProtectionPolicyListResponse ListProtectionPolicy(string rsVaultRgName, string rsVaultName, ProtectionPolicyQueryParameters queryParams) { ProtectionPolicyListResponse response = Client.ProtectionPolicies.ListAsync(rsVaultRgName, rsVaultName, queryParams, CommonTestHelper.GetCustomRequestHeaders()).Result; Assert.NotNull(response); Assert.Equal(HttpStatusCode.OK, response.StatusCode); return response; }
/// <summary> /// Lists protection policies according to the input query filter /// </summary> /// <param name="queryFilter">Query filter</param> /// <returns>List of protection policies</returns> public ProtectionPolicyListResponse ListProtectionPolicy( ProtectionPolicyQueryParameters queryFilter) { return BmsAdapter.Client.ProtectionPolicies.ListAsync( BmsAdapter.GetResourceGroupName(), BmsAdapter.GetResourceName(), queryFilter, BmsAdapter.GetCustomRequestHeaders(), BmsAdapter.CmdletCancellationToken).Result; }
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); } }); }
/// <summary> /// Lists all the protection policies in your Recovery Services Vault /// according to the query and pagination parameters supplied in the /// arguments. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.RecoveryServices.Backup.IProtectionPolicyOperations. /// </param> /// <param name='resourceGroupName'> /// Required. Resource group name of your recovery services vault. /// </param> /// <param name='resourceName'> /// Required. Name of your recovery services vault. /// </param> /// <param name='queryFilter'> /// Optional. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <returns> /// List of protection policies as returned by the service with the /// list policies call. /// </returns> public static Task<ProtectionPolicyListResponse> ListAsync(this IProtectionPolicyOperations operations, string resourceGroupName, string resourceName, ProtectionPolicyQueryParameters queryFilter, CustomRequestHeaders customRequestHeaders) { return operations.ListAsync(resourceGroupName, resourceName, queryFilter, customRequestHeaders, CancellationToken.None); }
/// <summary> /// Lists all the protection policies in your Recovery Services Vault /// according to the query and pagination parameters supplied in the /// arguments. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.RecoveryServices.Backup.IProtectionPolicyOperations. /// </param> /// <param name='resourceGroupName'> /// Required. Resource group name of your recovery services vault. /// </param> /// <param name='resourceName'> /// Required. Name of your recovery services vault. /// </param> /// <param name='queryFilter'> /// Optional. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <returns> /// List of protection policies as returned by the service with the /// list policies call. /// </returns> public static ProtectionPolicyListResponse List(this IProtectionPolicyOperations operations, string resourceGroupName, string resourceName, ProtectionPolicyQueryParameters queryFilter, CustomRequestHeaders customRequestHeaders) { return Task.Factory.StartNew((object s) => { return ((IProtectionPolicyOperations)s).ListAsync(resourceGroupName, resourceName, queryFilter, customRequestHeaders); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
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); } else if (WorkloadType == Models.WorkloadType.AzureSQLDatabase) { serviceClientProviderType = ServiceClientHelpers.GetServiceClientProviderType(Models.WorkloadType.AzureSQLDatabase); } 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 { 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); } }); }