Skip to content

Commit 2c067e2

Browse files
author
Samuel Anudeep
committed
Merge pull request #176 from MabOneSdk/anudeeb-dev1
Get Container Cmdlet Phase 1
2 parents 1bc5cb1 + 29d7c7b commit 2c067e2

File tree

14 files changed

+247
-28
lines changed

14 files changed

+247
-28
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Text;
19+
using System.Threading.Tasks;
20+
21+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
22+
{
23+
internal static class ParamHelpMsg
24+
{
25+
internal static class Container
26+
{
27+
internal static class Get
28+
{
29+
public const string Name = "The name of the resource being managed by the Azure Backup service (for example: resource name of the VM).";
30+
public const string ResourceGroupName = "The ResourceGroup of the resource being managed by the Azure Backup service (for example: ResourceGroup name of the VM).";
31+
public const string Status = "The registration status of the Azure Backup container.";
32+
public const string ContainerType = "The type of the Azure Backup container. This can be a Windows Server, an Azure IaaS VM, or a Data Protection Manager server.";
33+
}
34+
}
35+
36+
internal static class Common
37+
{
38+
public const string Vault = "The Azure Backup vault object which is the parent resource.";
39+
}
40+
}
41+
}

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

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
1616
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
17+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
18+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
1719
using System;
1820
using System.Collections.Generic;
1921
using System.Linq;
@@ -23,43 +25,59 @@
2325

2426
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
2527
{
26-
[Cmdlet(VerbsCommon.Get, "AzureRmRecoveryServicesContainer"), OutputType(typeof(List<AzureRmRecoveryServicesContainerBase>))]
28+
/// <summary>
29+
/// Get list of containers
30+
/// </summary>
31+
[Cmdlet(VerbsCommon.Get, "AzureRmRecoveryServicesContainer"), OutputType(typeof(List<AzureRmRecoveryServicesContainerBase>), typeof(AzureRmRecoveryServicesContainerBase))]
2732
public class GetAzureRmRecoveryServicesContainer : RecoveryServicesBackupCmdletBase
2833
{
29-
[Parameter(Mandatory = false, HelpMessage = "", ValueFromPipeline = true)]
34+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Common.Vault, ValueFromPipeline = true)]
3035
[ValidateNotNullOrEmpty]
3136
public ARSVault Vault { get; set; }
3237

33-
[Parameter(Mandatory = true, HelpMessage = "")]
38+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Container.Get.ContainerType)]
3439
[ValidateNotNullOrEmpty]
3540
public ContainerType ContainerType { get; set; }
3641

37-
[Parameter(Mandatory = false, HelpMessage = "")]
42+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Container.Get.Name)]
3843
[ValidateNotNullOrEmpty]
3944
public string Name { get; set; }
4045

41-
[Parameter(Mandatory = false, HelpMessage = "")]
46+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Container.Get.ResourceGroupName)]
4247
[ValidateNotNullOrEmpty]
4348
public string ResourceGroupName { get; set; }
4449

45-
[Parameter(Mandatory = false, HelpMessage = "")]
50+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Container.Get.Status)]
4651
[ValidateNotNullOrEmpty]
4752
public ContainerRegistrationStatus Status { get; set; }
4853

4954
public override void ExecuteCmdlet()
5055
{
5156
base.ExecuteCmdlet();
5257

53-
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()
58+
ProtectionContainerListQueryParams queryParams = new ProtectionContainerListQueryParams();
59+
60+
// 1. Filter by Name
61+
queryParams.FriendlyName = Name;
62+
63+
// 2. Filter by ContainerType
64+
queryParams.ProviderType = HydraHelpers.GetHydraProviderType(ContainerType);
65+
66+
// 3. Filter by Status
67+
queryParams.RegistrationStatus = Status.ToString();
68+
69+
var listResponse = HydraAdapter.ListContainers(Vault.Name, Vault.ResouceGroupName, queryParams);
70+
71+
List<AzureRmRecoveryServicesContainerBase> containerModels = ConversionHelpers.GetContainerModelList(listResponse);
72+
73+
// 4. Filter by RG Name
74+
if (ContainerType == Models.ContainerType.AzureVM)
5475
{
55-
{GetContainerParams.Vault, Vault},
56-
{GetContainerParams.ContainerType, ContainerType},
57-
{GetContainerParams.Name, Name},
58-
{GetContainerParams.ResourceGroupName, ResourceGroupName},
59-
{GetContainerParams.Status, Status},
60-
}, HydraAdapter);
76+
containerModels.RemoveAll(containerModel =>
77+
(containerModel as AzureRmRecoveryServicesIaasVmContainer).ResourceGroupName == ResourceGroupName);
78+
}
6179

62-
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(ContainerType.AzureVM);
80+
WriteObject(containerModels);
6381
}
6482
}
6583
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
<SpecificVersion>False</SpecificVersion>
4343
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.6.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
4444
</Reference>
45+
<Reference Include="Microsoft.Azure.Management.RecoveryServicesBackupManagement, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
46+
<SpecificVersion>False</SpecificVersion>
47+
<HintPath>Commands.RecoveryServices.Backup.HydraAdapter\Resources\Microsoft.Azure.Management.RecoveryServicesBackupManagement.dll</HintPath>
48+
</Reference>
4549
<Reference Include="Microsoft.Rest.ClientRuntime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4650
<SpecificVersion>False</SpecificVersion>
4751
<HintPath>..\..\packages\Microsoft.Rest.ClientRuntime.1.8.2\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
@@ -75,6 +79,7 @@
7579
<DependentUpon>Resources.resx</DependentUpon>
7680
</Compile>
7781
<Compile Include="RecoveryServicesBackupCmdletBase.cs" />
82+
<Compile Include="CmdletParameterHelpMessages.cs" />
7883
</ItemGroup>
7984
<ItemGroup>
8085
<Folder Include="Cmdlets\Backup\" />

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>
3232
<ItemGroup>
33+
<Reference Include="Microsoft.Azure.Management.RecoveryServicesBackupManagement">
34+
<HintPath>..\Commands.RecoveryServices.Backup.HydraAdapter\Resources\Microsoft.Azure.Management.RecoveryServicesBackupManagement.dll</HintPath>
35+
</Reference>
3336
<Reference Include="System" />
3437
<Reference Include="System.Core" />
3538
<Reference Include="System.Xml.Linq" />
@@ -39,8 +42,16 @@
3942
<Reference Include="System.Xml" />
4043
</ItemGroup>
4144
<ItemGroup>
45+
<Compile Include="ConversionHelpers.cs" />
46+
<Compile Include="HydraHelpers.cs" />
4247
<Compile Include="Properties\AssemblyInfo.cs" />
4348
</ItemGroup>
49+
<ItemGroup>
50+
<ProjectReference Include="..\Commands.RecoveryServices.Backup.Models\Commands.RecoveryServices.Backup.Models.csproj">
51+
<Project>{30b92759-50b3-494e-b9f0-ec9a2ce9d57b}</Project>
52+
<Name>Commands.RecoveryServices.Backup.Models</Name>
53+
</ProjectReference>
54+
</ItemGroup>
4455
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
4556
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
4657
Other similar extension points exist, see Microsoft.Common.targets.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 ConversionHelpers
26+
{
27+
public static AzureRmRecoveryServicesContainerBase GetContainerModel(ProtectionContainerResource protectionContainer)
28+
{
29+
AzureRmRecoveryServicesContainerBase containerModel = null;
30+
31+
if (protectionContainer != null &&
32+
protectionContainer.Properties != null)
33+
{
34+
if (protectionContainer.Properties.GetType() == typeof(AzureIaaSVMProtectionContainer))
35+
{
36+
new AzureRmRecoveryServicesIaasVmContainer(protectionContainer);
37+
}
38+
}
39+
40+
return containerModel;
41+
}
42+
43+
public static List<AzureRmRecoveryServicesContainerBase> GetContainerModelList(IEnumerable<ProtectionContainerResource> protectionContainers)
44+
{
45+
List<AzureRmRecoveryServicesContainerBase> containerModels = new List<AzureRmRecoveryServicesContainerBase>();
46+
47+
foreach (var protectionContainer in protectionContainers)
48+
{
49+
containerModels.Add(GetContainerModel(protectionContainer));
50+
}
51+
52+
return containerModels;
53+
}
54+
}
55+
}
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,32 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
16+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
1517
using System;
1618
using System.Collections.Generic;
1719
using System.Linq;
1820
using System.Text;
1921
using System.Threading.Tasks;
2022

21-
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
23+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
2224
{
23-
public class AzureRmRecoveryServicesIaasVmContainer : AzureRmRecoveryServicesContainerBase
25+
public class HydraHelpers
2426
{
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+
}
2542
}
2643
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.HydraAdapter/BMSAPIs/ContainerAPIs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public partial class HydraAdapter
2828
/// </summary>
2929
/// <param name="parameters"></param>
3030
/// <returns></returns>
31-
public IEnumerable<ProtectionContainerResource> RecoveryServicesListContainers(string resourceGroupName, string resourceName, ProtectionContainerListQueryParams queryParams)
31+
public IEnumerable<ProtectionContainerResource> ListContainers(string resourceGroupName, string resourceName, ProtectionContainerListQueryParams queryParams)
3232
{
3333
var listResponse = BmsAdapter.Client.Container.ListAsync(resourceGroupName, resourceName, queryParams,
3434
BmsAdapter.GetCustomRequestHeaders(), BmsAdapter.CmdletCancellationToken).Result;
@@ -39,7 +39,7 @@ public IEnumerable<ProtectionContainerResource> RecoveryServicesListContainers(s
3939
/// Triggers refresh of container catalog in service
4040
/// </summary>
4141
/// <returns></returns>
42-
public BaseRecoveryServicesJobResponse RecoveryServicesRefreshContainers(string resourceGroupName, string resourceName)
42+
public BaseRecoveryServicesJobResponse RefreshContainers(string resourceGroupName, string resourceName)
4343
{
4444
var response = BmsAdapter.Client.Container.RefreshAsync(
4545
resourceGroupName, resourceName,

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.HydraAdapter/HydraAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public partial class HydraAdapter
2929
const string ProviderNamespaceKey = "ProviderNamespace";
3030
const string AzureFabricName = "AzureIaasVM";
3131

32-
public ClientProxy<RecoveryServicesNS.RecoveryServicesBackupManagementClient, RecoveryServicesModelsNS.CustomRequestHeaders> BmsAdapter;
32+
ClientProxy<RecoveryServicesNS.RecoveryServicesBackupManagementClient, RecoveryServicesModelsNS.CustomRequestHeaders> BmsAdapter;
3333

3434
public HydraAdapter(SubscriptionCloudCredentials creds, Uri baseUri)
3535
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.Management.RecoveryServices.Backup.Models;
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Text;
20+
using System.Threading.Tasks;
21+
22+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
23+
{
24+
public class AzureRmRecoveryServicesIaasVmContainer : AzureRmRecoveryServicesContainerBase
25+
{
26+
/// <summary>
27+
/// Resource Group where the Container is present
28+
/// </summary>
29+
public string ResourceGroupName { get; set; }
30+
31+
/// <summary>
32+
/// Registration Status
33+
/// </summary>
34+
public string Status { get; set; }
35+
36+
public AzureRmRecoveryServicesIaasVmContainer(ProtectionContainerResource protectionContainer)
37+
: base(protectionContainer)
38+
{
39+
AzureIaaSVMProtectionContainer iaasVmProtectionContainer = (AzureIaaSVMProtectionContainer)protectionContainer.Properties;
40+
ContainerType = ContainerType.AzureVM;
41+
ResourceGroupName = IdUtils.GetResourceGroupName(protectionContainer.Id);
42+
Status = iaasVmProtectionContainer.RegistrationStatus;
43+
}
44+
}
45+
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/BaseObjects.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
1516
using System;
1617
using System.Collections.Generic;
1718
using System.Linq;
@@ -30,15 +31,17 @@ public virtual void Validate()
3031

3132
public class AzureRmRecoveryServicesContainerBase : AzureRmRecoveryServicesObjectBase
3233
{
34+
/// <summary>
35+
/// Container Name
36+
/// </summary>
3337
public string Name { get; set; }
3438

35-
public string ResourceGroupName { get; set; }
36-
37-
public string Status { get; set; }
38-
3939
public ContainerType ContainerType { get; set; }
4040

41-
public int BackupItemsCount { get; set; }
41+
public AzureRmRecoveryServicesContainerBase(ProtectionContainerResource protectionContainer)
42+
{
43+
Name = protectionContainer.Name;
44+
}
4245
}
4346

4447
public class AzureRmRecoveryServicesItemBase : AzureRmRecoveryServicesObjectBase
@@ -72,5 +75,5 @@ public class AzureRmRecoveryServicesSchedulePolicyBase : AzureRmRecoveryServices
7275
public override void Validate()
7376
{
7477
}
75-
}
78+
}
7679
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>
3232
<ItemGroup>
33+
<Reference Include="Microsoft.Azure.Management.RecoveryServicesBackupManagement">
34+
<HintPath>..\Commands.RecoveryServices.Backup.HydraAdapter\Resources\Microsoft.Azure.Management.RecoveryServicesBackupManagement.dll</HintPath>
35+
</Reference>
3336
<Reference Include="System" />
3437
<Reference Include="System.Core" />
3538
<Reference Include="System.Xml.Linq" />
@@ -45,9 +48,9 @@
4548
<Compile Include="CommonModels\Enums.cs" />
4649
<Compile Include="CommonModels\PolicyRetentionObjects.cs" />
4750
<Compile Include="CommonModels\PolicyScheduleObjects.cs" />
48-
<Compile Include="IaasVmModels\AzureRmRecoveryServicesIaasVmPolicy.cs" />
49-
<Compile Include="IaasVmModels\AzureRmRecoveryServicesIaasVmItem.cs" />
50-
<Compile Include="IaasVmModels\AzureRmRecoveryServicesIaasVmContainer.cs" />
51+
<Compile Include="AzureVmModels\AzureRmRecoveryServicesAzureVmPolicy.cs" />
52+
<Compile Include="AzureVmModels\AzureRmRecoveryServicesAzureVmItem.cs" />
53+
<Compile Include="AzureVmModels\AzureRmRecoveryServicesAzureVmContainer.cs" />
5154
<Compile Include="Properties\AssemblyInfo.cs" />
5255
</ItemGroup>
5356
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

0 commit comments

Comments
 (0)