@@ -30,15 +30,19 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
3030 [ Cmdlet ( VerbsCommon . Get , "AzureBackupContainer" ) , OutputType ( typeof ( AzureBackupContainer ) , typeof ( List < AzureBackupContainer > ) ) ]
3131 public class GetAzureBackupContainer : AzureBackupVaultCmdletBase
3232 {
33- [ Parameter ( Position = 2 , Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ContainerName ) ]
33+ [ Parameter ( Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ContainerResourceGroupName ) ]
3434 [ ValidateNotNullOrEmpty ]
35- public string VirtualMachine { get ; set ; }
35+ public string ContainerResourceGroupName { get ; set ; }
3636
37- [ Parameter ( Position = 2 , Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ContainerRegistrationStatus ) ]
37+ [ Parameter ( Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ContainerResourceName ) ]
38+ [ ValidateNotNullOrEmpty ]
39+ public string ContainerResourceName { get ; set ; }
40+
41+ [ Parameter ( Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ContainerRegistrationStatus ) ]
3842 [ ValidateNotNullOrEmpty ]
3943 public AzureBackupContainerStatus Status { get ; set ; }
4044
41- [ Parameter ( Position = 2 , Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ContainerType ) ]
45+ [ Parameter ( Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ContainerType ) ]
4246 [ ValidateNotNullOrEmpty ]
4347 public AzureBackupContainerType Type { get ; set ; }
4448
@@ -49,74 +53,63 @@ public override void ExecuteCmdlet()
4953 ExecutionBlock ( ( ) =>
5054 {
5155 string queryFilterString = string . Empty ;
52- // TODO: Construct query filter string based on input filters.
53- //queryFilterString = ConstructQueryFilterString();
54-
56+ queryFilterString = ConstructQueryFilterString ( ) ;
5557 ListContainerResponse listContainerResponse = AzureBackupClient . Container . ListAsync ( queryFilterString ,
5658 GetCustomRequestHeaders ( ) , CmdletCancellationToken ) . Result ;
5759
58- IEnumerable < AzureBackupContainer > containers = listContainerResponse . Objects . ToList ( ) . ConvertAll ( containerInfo =>
60+ List < ContainerInfo > containerInfos = listContainerResponse . Objects . ToList ( ) ;
61+
62+ // When resource group name is specified, remove all containers whose resource group name
63+ // doesn't match the given resource group name
64+ if ( ! string . IsNullOrEmpty ( ContainerResourceGroupName ) )
5965 {
60- return new AzureBackupContainer ( )
66+ containerInfos . RemoveAll ( containerInfo =>
6167 {
62- ContainerType = containerInfo . ContainerType ,
63- FriendlyName = containerInfo . FriendlyName ,
64- HealthStatus = containerInfo . HealthStatus ,
65- InstanceId = containerInfo . InstanceId ,
66- Name = containerInfo . Name ,
67- ParentContainerFriendlyName = containerInfo . ParentContainerFriendlyName ,
68- ParentContainerName = containerInfo . ParentContainerName ,
69- RegistrationStatus = containerInfo . RegistrationStatus ,
70- ResourceGroupName = ResourceGroupName ,
71- ResourceName = ResourceName ,
72- } ;
73- } ) ;
68+ return containerInfo . ParentContainerName != ContainerResourceGroupName ;
69+ } ) ;
70+ }
7471
75- WriteObject ( containers ) ;
72+ WriteObject ( containerInfos . ConvertAll ( containerInfo =>
73+ {
74+ return new AzureBackupContainer ( containerInfo ) ;
75+ } ) ) ;
7676 } ) ;
7777 }
7878
7979 private string ConstructQueryFilterString ( )
8080 {
81- string queryFilterString = string . Empty ;
8281 BMI . ContainerQueryObject containerQueryObject = new BMI . ContainerQueryObject ( ) ;
8382
84- if ( Type != null )
83+ switch ( Type )
8584 {
86- switch ( Type )
87- {
88- case AzureBackupContainerType . AzureVirtualMachine :
89- containerQueryObject . Type = BCI . ContainerType . IaasVMContainer . ToString ( ) ;
90- break ;
91- default :
92- break ;
93- }
85+ case AzureBackupContainerType . AzureVirtualMachine :
86+ containerQueryObject . Type = BCI . ContainerType . IaasVMContainer . ToString ( ) ;
87+ break ;
88+ default :
89+ break ;
9490 }
9591
96- if ( Status != null )
92+ switch ( Status )
9793 {
98- switch ( Status )
99- {
100- case AzureBackupContainerStatus . Registered :
101- containerQueryObject . Status = BCI . RegistrationStatus . Registered . ToString ( ) ;
102- break ;
103- case AzureBackupContainerStatus . Registering :
104- containerQueryObject . Status = BCI . RegistrationStatus . Registering . ToString ( ) ;
105- break ;
106- case AzureBackupContainerStatus . NotRegistered :
107- containerQueryObject . Status = BCI . RegistrationStatus . NotRegistered . ToString ( ) ;
108- break ;
109- default :
110- break ;
111- }
94+ case AzureBackupContainerStatus . Registered :
95+ containerQueryObject . Status = BCI . RegistrationStatus . Registered . ToString ( ) ;
96+ break ;
97+ case AzureBackupContainerStatus . Registering :
98+ containerQueryObject . Status = BCI . RegistrationStatus . Registering . ToString ( ) ;
99+ break ;
100+ case AzureBackupContainerStatus . NotRegistered :
101+ containerQueryObject . Status = BCI . RegistrationStatus . NotRegistered . ToString ( ) ;
102+ break ;
103+ default :
104+ break ;
112105 }
113106
114- if ( VirtualMachine != null )
107+ if ( ! string . IsNullOrEmpty ( ContainerResourceName ) )
115108 {
116-
109+ containerQueryObject . FriendlyName = ContainerResourceName ;
117110 }
118111
119- return queryFilterString ;
112+ return BMI . BackupManagementAPIHelper . GetQueryString ( containerQueryObject . GetNameValueCollection ( ) ) ;
120113 }
121114 }
122115}
0 commit comments