Skip to content

Commit 10e77e3

Browse files
author
Samuel Anudeep
committed
Merge pull request #12 from MabOneSdk/anudeeb
Get-AzureBackupContainer
2 parents 7605325 + af110f8 commit 10e77e3

File tree

5 files changed

+79
-12
lines changed

5 files changed

+79
-12
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Container/GetAzureBackupContainer.cs

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

15+
using BCI = Microsoft.BackupManagementService.CommonInterface;
16+
using BMI = Microsoft.BackupManagementService.ManagementInterface;
17+
using Microsoft.Azure.Management.BackupServices.Models;
1518
using System;
1619
using System.Collections.Generic;
1720
using System.Linq;
@@ -29,11 +32,7 @@ public class GetAzureBackupContainer : AzureBackupVaultCmdletBase
2932
{
3033
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ContainerName)]
3134
[ValidateNotNullOrEmpty]
32-
public string Name { get; set; }
33-
34-
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ContainerId)]
35-
[ValidateNotNullOrEmpty]
36-
public string Id { get; set; }
35+
public string VirtualMachine { get; set; }
3736

3837
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ContainerRegistrationStatus)]
3938
[ValidateNotNullOrEmpty]
@@ -49,12 +48,75 @@ public override void ExecuteCmdlet()
4948

5049
ExecutionBlock(() =>
5150
{
52-
IEnumerable<AzureBackupContainer> containers = new List<AzureBackupContainer>();
51+
string queryFilterString = string.Empty;
52+
// TODO: Construct query filter string based on input filters.
53+
//queryFilterString = ConstructQueryFilterString();
5354

54-
// TODO: Call Hydra
55+
ListContainerResponse listContainerResponse = AzureBackupClient.Container.ListAsync(queryFilterString,
56+
GetCustomRequestHeaders(), CmdletCancellationToken).Result;
57+
58+
IEnumerable<AzureBackupContainer> containers = listContainerResponse.Objects.ToList().ConvertAll(containerInfo =>
59+
{
60+
return new AzureBackupContainer()
61+
{
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+
});
5574

5675
WriteObject(containers);
5776
});
5877
}
78+
79+
private string ConstructQueryFilterString()
80+
{
81+
string queryFilterString = string.Empty;
82+
BMI.ContainerQueryObject containerQueryObject = new BMI.ContainerQueryObject();
83+
84+
if (Type != null)
85+
{
86+
switch (Type)
87+
{
88+
case AzureBackupContainerType.AzureVirtualMachine:
89+
containerQueryObject.Type = BCI.ContainerType.IaasVMContainer.ToString();
90+
break;
91+
default:
92+
break;
93+
}
94+
}
95+
96+
if (Status != null)
97+
{
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+
}
112+
}
113+
114+
if (VirtualMachine != null)
115+
{
116+
117+
}
118+
119+
return queryFilterString;
120+
}
59121
}
60122
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
<Prefer32Bit>false</Prefer32Bit>
4444
</PropertyGroup>
4545
<ItemGroup>
46+
<Reference Include="BackupManagementInterface, Version=1.0.523.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
47+
<SpecificVersion>False</SpecificVersion>
48+
<HintPath>Resources\BackupManagementInterface.dll</HintPath>
49+
</Reference>
50+
<Reference Include="BMSCommonInterface, Version=1.0.523.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
51+
<SpecificVersion>False</SpecificVersion>
52+
<HintPath>Resources\BMSCommonInterface.dll</HintPath>
53+
</Reference>
4654
<Reference Include="Hyak.Common">
4755
<HintPath>..\..\..\packages\Hyak.Common.1.0.2\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
4856
</Reference>
@@ -169,6 +177,8 @@
169177
</EmbeddedResource>
170178
</ItemGroup>
171179
<ItemGroup>
180+
<Content Include="Resources\BackupManagementInterface.dll" />
181+
<Content Include="Resources\BMSCommonInterface.dll" />
172182
<Content Include="Resources\Microsoft.WindowsAzure.Management.Common.dll" />
173183
<Content Include="Resources\Security.Cryptography.dll" />
174184
</ItemGroup>

src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/AzureBackupContainer.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ public class AzureBackupContainer : AzureBackupContainerContextObject
6060
/// </summary>
6161
public string ParentContainerName { get; set; }
6262

63-
/// <summary>
64-
/// Region where this container is present
65-
/// </summary>
66-
public string Region { get; set; }
67-
6863
/// <summary>
6964
/// Status of registration of the container
7065
/// </summary>

0 commit comments

Comments
 (0)