Skip to content

Commit 31092e6

Browse files
author
dragonfly91
committed
Get Container Filters
1 parent 8512eb9 commit 31092e6

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

src/ResourceManager/RecoveryServices.Backup/Cmdlets/Container/GetAzureRmRecoveryServicesContainer.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class GetAzureRmRecoveryServicesContainer : RecoveryServicesBackupCmdletB
4747
[ValidateNotNullOrEmpty]
4848
public string ResourceGroupName { get; set; }
4949

50-
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Container.Get.Status)]
50+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Container.Get.Status)]
5151
[ValidateNotNullOrEmpty]
5252
public ContainerRegistrationStatus Status { get; set; }
5353

@@ -56,16 +56,28 @@ public override void ExecuteCmdlet()
5656
base.ExecuteCmdlet();
5757

5858
ProtectionContainerListQueryParams queryParams = new ProtectionContainerListQueryParams();
59+
60+
// 1. Filter by Name
5961
queryParams.FriendlyName = Name;
60-
61-
// TODO: Removing hardcoding of ProviderType
62-
queryParams.ProviderType = ProviderType.AzureIaasVM.ToString();
62+
63+
// 2. Filter by ContainerType
64+
queryParams.ProviderType = HydraHelpers.GetHydraProviderType(ContainerType);
65+
66+
// 3. Filter by Status
6367
queryParams.RegistrationStatus = Status.ToString();
68+
6469
var listResponse = HydraAdapter.ListContainers(Vault.Name, Vault.ResouceGroupName, queryParams);
6570

66-
// TODO: Filter the response
71+
List<AzureRmRecoveryServicesContainerBase> containerModels = ConversionHelpers.GetContainerModelList(listResponse);
72+
73+
// 4. Filter by RG Name
74+
if (ContainerType == Models.ContainerType.AzureVM)
75+
{
76+
containerModels.RemoveAll(containerModel =>
77+
(containerModel as AzureRmRecoveryServicesIaasVmContainer).ResourceGroupName == ResourceGroupName);
78+
}
6779

68-
WriteObject((ConversionHelpers.GetContainerModelList(listResponse)));
80+
WriteObject(containerModels);
6981
}
7082
}
7183
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Commands.RecoveryServices.Backup.Helpers.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
</ItemGroup>
4444
<ItemGroup>
4545
<Compile Include="ConversionHelpers.cs" />
46+
<Compile Include="HydraHelpers.cs" />
4647
<Compile Include="Properties\AssemblyInfo.cs" />
4748
</ItemGroup>
4849
<ItemGroup>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
16+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Linq;
20+
using System.Text;
21+
using System.Threading.Tasks;
22+
23+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
24+
{
25+
public class HydraHelpers
26+
{
27+
public static string GetHydraProviderType(ContainerType containerType)
28+
{
29+
string providerType = string.Empty;
30+
31+
switch (containerType)
32+
{
33+
case ContainerType.AzureVM:
34+
providerType = ProviderType.AzureIaasVM.ToString();
35+
break;
36+
default:
37+
break;
38+
}
39+
40+
return providerType;
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)