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

                List<CSMProtectedItemResponse> azureBackupDatasourceObjects = null;
                List<CSMItemResponse> azureBackupPOObjects = null;

                WriteDebug(Resources.MakingClientCall);
                CSMProtectedItemQueryObject DSQueryParam = new CSMProtectedItemQueryObject()
                {
                    ProtectionStatus = this.ProtectionStatus,
                    Status = this.Status,
                    Type = GetItemType(this.Type)
                };

                CSMItemQueryObject POQueryParam = new CSMItemQueryObject()
                {
                    Status = this.ProtectionStatus,
                    Type = GetItemType(this.Type)
                };

                var azureBackupDatasourceListResponse = AzureBackupClient.ListDataSources(Container.ResourceGroupName, Container.ResourceName, DSQueryParam);

                if (azureBackupDatasourceListResponse != null)
                {
                    azureBackupDatasourceObjects = azureBackupDatasourceListResponse.Where(x => x.Properties.ContainerId.Split('/').Last().Equals(Container.ContainerUniqueName, System.StringComparison.InvariantCultureIgnoreCase)).ToList();
                }

                if (this.Status == null)
                {
                    var azureBackupPOListResponse = AzureBackupClient.ListProtectableObjects(Container.ResourceGroupName, Container.ResourceName, POQueryParam);
                    if (azureBackupPOListResponse != null)
                    {
                        azureBackupPOObjects = azureBackupPOListResponse.Where(x => x.Properties.ContainerId.Split('/').Last().Equals(Container.ContainerUniqueName, System.StringComparison.InvariantCultureIgnoreCase)).ToList();
                    }
                }

                WriteDebug(Resources.AzureBackupItemResponse);
                WriteAzureBackupItem(azureBackupDatasourceObjects, azureBackupPOObjects, Container);
            });
        }
        public void ListAzureBackupItemDSTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                CSMProtectedItemQueryObject DSQueryParam = new CSMProtectedItemQueryObject()
                {
                    ProtectionStatus = null,
                    Status = null,
                    Type = null
                };

                var client = GetServiceClient<BackupServicesManagementClient>();

                var response = client.DataSource.ListCSMAsync(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, DSQueryParam, GetCustomRequestHeaders()).Result;
                foreach (var ds in response.CSMProtectedItemListResponse.Value)
                {
                    Assert.True(!string.IsNullOrEmpty(ds.Properties.ContainerId), "ContainerId can't be null or empty");
                    Assert.True(!string.IsNullOrEmpty(ds.Properties.FriendlyName), "FriendlyName can't be null or empty");
                    Assert.True(!string.IsNullOrEmpty(ds.Properties.ItemType), "ItemType can't be null or empty");
                    Assert.True(!string.IsNullOrEmpty(ds.Properties.ProtectionPolicyId), "ProtectionPolicyId can't be null or empty");
                    Assert.True(!string.IsNullOrEmpty(ds.Properties.ProtectionStatus), "ProtectionStatus can't be null or empty");
                    Assert.True(!string.IsNullOrEmpty(ds.Properties.RecoveryPointsCount.ToString()), "RecoveryPointsCount can't be null or empty");
                    Assert.True(!string.IsNullOrEmpty(ds.Properties.Status), "Status can't be null or empty");
                    Assert.True(!string.IsNullOrEmpty(ds.Name), "Name can't be null or empty");
                    Assert.True(!string.IsNullOrEmpty(ds.Type), "Type can't be null or empty"); 
                }

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Lists datasources in the vault
 /// </summary>
 /// <param name="query"></param>
 /// <returns></returns>
 public IList<CSMProtectedItemResponse> ListDataSources(string resourceGroupName, string resourceName, CSMProtectedItemQueryObject query)
 {
     var response = AzureBackupClient.DataSource.ListCSMAsync(resourceGroupName, resourceName, query, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
     return (response != null) ? response.CSMProtectedItemListResponse.Value : null;
 }
 /// <summary>
 /// Get the list of all Datasources.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.BackupServices.IDataSourceOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required.
 /// </param>
 /// <param name='resourceName'>
 /// Required.
 /// </param>
 /// <param name='csmparameters'>
 /// Optional. DataSource query parameter.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// The definition of a CSMProtectedItemListOperationResponse.
 /// </returns>
 public static Task<CSMProtectedItemListOperationResponse> ListCSMAsync(this IDataSourceOperations operations, string resourceGroupName, string resourceName, CSMProtectedItemQueryObject csmparameters, CustomRequestHeaders customRequestHeaders)
 {
     return operations.ListCSMAsync(resourceGroupName, resourceName, csmparameters, customRequestHeaders, CancellationToken.None);
 }
 /// <summary>
 /// Get the list of all Datasources.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.BackupServices.IDataSourceOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required.
 /// </param>
 /// <param name='resourceName'>
 /// Required.
 /// </param>
 /// <param name='csmparameters'>
 /// Optional. DataSource query parameter.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// The definition of a CSMProtectedItemListOperationResponse.
 /// </returns>
 public static CSMProtectedItemListOperationResponse ListCSM(this IDataSourceOperations operations, string resourceGroupName, string resourceName, CSMProtectedItemQueryObject csmparameters, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IDataSourceOperations)s).ListCSMAsync(resourceGroupName, resourceName, csmparameters, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }