@@ -30,15 +30,19 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
30
30
[ Cmdlet ( VerbsCommon . Get , "AzureBackupContainer" ) , OutputType ( typeof ( AzureBackupContainer ) , typeof ( List < AzureBackupContainer > ) ) ]
31
31
public class GetAzureBackupContainer : AzureBackupVaultCmdletBase
32
32
{
33
- [ Parameter ( Position = 2 , Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ContainerName ) ]
33
+ [ Parameter ( Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ContainerResourceGroupName ) ]
34
34
[ ValidateNotNullOrEmpty ]
35
- public string VirtualMachine { get ; set ; }
35
+ public string ContainerResourceGroupName { get ; set ; }
36
36
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 ) ]
38
42
[ ValidateNotNullOrEmpty ]
39
43
public AzureBackupContainerStatus Status { get ; set ; }
40
44
41
- [ Parameter ( Position = 2 , Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ContainerType ) ]
45
+ [ Parameter ( Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ContainerType ) ]
42
46
[ ValidateNotNullOrEmpty ]
43
47
public AzureBackupContainerType Type { get ; set ; }
44
48
@@ -49,74 +53,63 @@ public override void ExecuteCmdlet()
49
53
ExecutionBlock ( ( ) =>
50
54
{
51
55
string queryFilterString = string . Empty ;
52
- // TODO: Construct query filter string based on input filters.
53
- //queryFilterString = ConstructQueryFilterString();
54
-
56
+ queryFilterString = ConstructQueryFilterString ( ) ;
55
57
ListContainerResponse listContainerResponse = AzureBackupClient . Container . ListAsync ( queryFilterString ,
56
58
GetCustomRequestHeaders ( ) , CmdletCancellationToken ) . Result ;
57
59
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 ) )
59
65
{
60
- return new AzureBackupContainer ( )
66
+ containerInfos . RemoveAll ( containerInfo =>
61
67
{
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
+ }
74
71
75
- WriteObject ( containers ) ;
72
+ WriteObject ( containerInfos . ConvertAll ( containerInfo =>
73
+ {
74
+ return new AzureBackupContainer ( containerInfo ) ;
75
+ } ) ) ;
76
76
} ) ;
77
77
}
78
78
79
79
private string ConstructQueryFilterString ( )
80
80
{
81
- string queryFilterString = string . Empty ;
82
81
BMI . ContainerQueryObject containerQueryObject = new BMI . ContainerQueryObject ( ) ;
83
82
84
- if ( Type != null )
83
+ switch ( Type )
85
84
{
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 ;
94
90
}
95
91
96
- if ( Status != null )
92
+ switch ( Status )
97
93
{
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 ;
112
105
}
113
106
114
- if ( VirtualMachine != null )
107
+ if ( ! string . IsNullOrEmpty ( ContainerResourceName ) )
115
108
{
116
-
109
+ containerQueryObject . FriendlyName = ContainerResourceName ;
117
110
}
118
111
119
- return queryFilterString ;
112
+ return BMI . BackupManagementAPIHelper . GetQueryString ( containerQueryObject . GetNameValueCollection ( ) ) ;
120
113
}
121
114
}
122
115
}
0 commit comments