Skip to content

Commit ff15a1e

Browse files
author
Samuel Anudeep
committed
AFS Get-Container
1 parent 14d3e2b commit ff15a1e

File tree

13 files changed

+245
-74
lines changed

13 files changed

+245
-74
lines changed

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/Conversions/ConversionHelpers.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionConta
4141
{
4242
containerModel = new AzureVmContainer(protectionContainer);
4343
}
44-
if (protectionContainer.Properties.GetType() == typeof(ServiceClientModel.MabContainer))
44+
else if (protectionContainer.Properties.GetType() == typeof(ServiceClientModel.MabContainer))
4545
{
4646
containerModel = new MabContainer(protectionContainer);
4747
}
@@ -50,6 +50,11 @@ public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionConta
5050
{
5151
containerModel = new AzureSqlContainer(protectionContainer);
5252
}
53+
else if (protectionContainer.Properties.GetType() ==
54+
typeof(ServiceClientModel.AzureStorageContainer))
55+
{
56+
containerModel = new AzureFileShareContainer(protectionContainer);
57+
}
5358
}
5459

5560
return containerModel;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
17+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
18+
{
19+
/// <summary>
20+
/// Azure VM specific container class.
21+
/// </summary>
22+
public class AzureFileShareContainer : AzureContainer
23+
{
24+
/// <summary>
25+
/// Constructor. Takes the service client object representing the container
26+
/// and converts it in to the PS container model
27+
/// </summary>
28+
/// <param name="protectionContainerResource">Service client object representing the container</param>
29+
public AzureFileShareContainer(ProtectionContainerResource protectionContainerResource)
30+
: base(protectionContainerResource) { }
31+
}
32+
}
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.Management.RecoveryServices.Backup.Models;
16+
17+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
18+
{
19+
public class AzureContainer : ContainerBase
20+
{
21+
/// <summary>
22+
/// Resource Group where the Container is present
23+
/// </summary>
24+
public string ResourceGroupName { get; set; }
25+
/// <summary>
26+
/// Friendly name of the container
27+
/// </summary>
28+
public string FriendlyName { get; set; }
29+
30+
/// <summary>
31+
/// Registration Status
32+
/// </summary>
33+
public ContainerRegistrationStatus Status { get; set; }
34+
35+
public AzureContainer(ProtectionContainerResource protectionContainer)
36+
: base(protectionContainer)
37+
{
38+
ResourceGroupName = IdUtils.GetResourceGroupName(protectionContainer.Id);
39+
FriendlyName = protectionContainer.Properties.FriendlyName;
40+
Status = EnumUtils.GetEnum<ContainerRegistrationStatus>(protectionContainer.Properties.RegistrationStatus);
41+
}
42+
}
43+
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/AzureVmModels/AzureVmContainer.cs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,14 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
1919
/// <summary>
2020
/// Azure VM specific container class.
2121
/// </summary>
22-
public class AzureVmContainer : ContainerBase
22+
public class AzureVmContainer : AzureContainer
2323
{
24-
/// <summary>
25-
/// Resource Group where the Container is present
26-
/// </summary>
27-
public string ResourceGroupName { get; set; }
28-
29-
/// <summary>
30-
/// Friendly name of the container
31-
/// </summary>
32-
public string FriendlyName { get; set; }
33-
34-
/// <summary>
35-
/// Registration Status
36-
/// </summary>
37-
public ContainerRegistrationStatus Status { get; set; }
38-
3924
/// <summary>
4025
/// Constructor. Takes the service client object representing the container
4126
/// and converts it in to the PS container model
4227
/// </summary>
4328
/// <param name="protectionContainer">Service client object representing the container</param>
4429
public AzureVmContainer(ProtectionContainerResource protectionContainer)
45-
: base(protectionContainer)
46-
{
47-
IaaSVMContainer iaasVmProtectionContainer =
48-
(IaaSVMContainer)protectionContainer.Properties;
49-
ResourceGroupName = IdUtils.GetResourceGroupName(protectionContainer.Id);
50-
FriendlyName = iaasVmProtectionContainer.FriendlyName;
51-
Status = EnumUtils.GetEnum<ContainerRegistrationStatus>(iaasVmProtectionContainer.RegistrationStatus);
52-
}
30+
: base(protectionContainer) { }
5331
}
5432
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
<ItemGroup>
5050
<Compile Include="AzureFileShareModels\AzureFileSharePolicy.cs" />
5151
<Compile Include="AzureFileShareModels\AzureFileShareItem.cs" />
52+
<Compile Include="AzureFileShareModels\AzureFileShareContainer.cs" />
53+
<Compile Include="AzureModels\AzureContainer.cs" />
5254
<Compile Include="AzureSqlModels\AzureSqlContainer.cs" />
5355
<Compile Include="AzureSqlModels\AzureSqlItem.cs" />
5456
<Compile Include="AzureSqlModels\AzureSqlPolicy.cs" />
@@ -94,9 +96,7 @@
9496
<None Include="packages.config">
9597
</None>
9698
</ItemGroup>
97-
<ItemGroup>
98-
<Folder Include="AzureWorkloadModels\" />
99-
</ItemGroup>
99+
<ItemGroup />
100100
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
101101
<Import Project="..\..\..\..\tools\Common.Dependencies.targets" />
102102
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/AzureWorkloadProviderHelper.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,52 @@ public void RefreshContainer(string vaultName = null, string resourceGroupName =
156156

157157
return itemModels;
158158
}
159+
160+
public List<CmdletModel.ContainerBase> ListProtectionContainers(
161+
Dictionary<Enum, object> providerData,
162+
string backupManagementType)
163+
{
164+
string vaultName = (string)providerData[CmdletModel.VaultParams.VaultName];
165+
string vaultResourceGroupName = (string)providerData[CmdletModel.VaultParams.ResourceGroupName];
166+
string name = (string)providerData[CmdletModel.ContainerParams.Name];
167+
string friendlyName = (string)providerData[CmdletModel.ContainerParams.FriendlyName];
168+
CmdletModel.ContainerRegistrationStatus status =
169+
(CmdletModel.ContainerRegistrationStatus)providerData[CmdletModel.ContainerParams.Status];
170+
171+
string nameQueryFilter = friendlyName;
172+
173+
if (!string.IsNullOrEmpty(name))
174+
{
175+
Logger.Instance.WriteWarning(Resources.GetContainerNameParamDeprecated);
176+
177+
if (string.IsNullOrEmpty(friendlyName))
178+
{
179+
nameQueryFilter = name;
180+
}
181+
}
182+
183+
ODataQuery<ServiceClientModel.BMSContainerQueryObject> queryParams = null;
184+
if (status == 0)
185+
{
186+
queryParams = new ODataQuery<ServiceClientModel.BMSContainerQueryObject>(
187+
q => q.FriendlyName == nameQueryFilter &&
188+
q.BackupManagementType == backupManagementType);
189+
}
190+
else
191+
{
192+
var statusString = status.ToString();
193+
queryParams = new ODataQuery<ServiceClientModel.BMSContainerQueryObject>(
194+
q => q.FriendlyName == nameQueryFilter &&
195+
q.BackupManagementType == backupManagementType &&
196+
q.Status == statusString);
197+
}
198+
199+
var listResponse = ServiceClientAdapter.ListContainers(
200+
queryParams,
201+
vaultName: vaultName,
202+
resourceGroupName: vaultResourceGroupName);
203+
204+
return ConversionHelpers.GetContainerModelList(listResponse);
205+
}
159206
}
160207
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureFilesPsBackupBackupProvider.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Linq;
1818
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
1919
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS;
20+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
2021
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
2122
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2223
using RestAzureNS = Microsoft.Rest.Azure;
@@ -67,8 +68,20 @@ public RestAzureNS.AzureOperationResponse DisableProtection()
6768

6869
public List<ContainerBase> ListProtectionContainers()
6970
{
70-
throw new NotImplementedException();
71+
CmdletModel.BackupManagementType? backupManagementTypeNullable =
72+
(CmdletModel.BackupManagementType?)
73+
ProviderData[ContainerParams.BackupManagementType];
74+
75+
if (backupManagementTypeNullable.HasValue)
76+
{
77+
ValidateAzureStorageBackupManagementType(backupManagementTypeNullable.Value);
78+
}
79+
80+
return AzureWorkloadProviderHelper.ListProtectionContainers(
81+
ProviderData,
82+
ServiceClientModel.BackupManagementType.AzureStorage);
7183
}
84+
7285
public RestAzureNS.AzureOperationResponse TriggerBackup()
7386
{
7487
throw new NotImplementedException();
@@ -223,5 +236,16 @@ public ResourceBackupStatus CheckBackupStatus()
223236
{
224237
throw new NotImplementedException();
225238
}
239+
240+
private void ValidateAzureStorageBackupManagementType(
241+
CmdletModel.BackupManagementType backupManagementType)
242+
{
243+
if (backupManagementType != CmdletModel.BackupManagementType.AzureStorage)
244+
{
245+
throw new ArgumentException(string.Format(Resources.UnExpectedBackupManagementTypeException,
246+
CmdletModel.BackupManagementType.AzureStorage.ToString(),
247+
backupManagementType.ToString()));
248+
}
249+
}
226250
}
227251
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/IaasVmPsBackupProvider.cs

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -649,60 +649,21 @@ public RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> ModifyPolicy
649649
/// <returns>List of protection containers</returns>
650650
public List<ContainerBase> ListProtectionContainers()
651651
{
652-
string vaultName = (string)ProviderData[VaultParams.VaultName];
653-
string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
654-
CmdletModel.ContainerType containerType =
655-
(CmdletModel.ContainerType)ProviderData[ContainerParams.ContainerType];
652+
string resourceGroupName = (string)ProviderData[ContainerParams.ResourceGroupName];
656653
CmdletModel.BackupManagementType? backupManagementTypeNullable =
657654
(CmdletModel.BackupManagementType?)
658655
ProviderData[ContainerParams.BackupManagementType];
659-
string name = (string)ProviderData[ContainerParams.Name];
660-
string friendlyName = (string)ProviderData[ContainerParams.FriendlyName];
661-
string resourceGroupName = (string)ProviderData[ContainerParams.ResourceGroupName];
662-
ContainerRegistrationStatus status =
663-
(ContainerRegistrationStatus)ProviderData[ContainerParams.Status];
664656

665657
if (backupManagementTypeNullable.HasValue)
666658
{
667659
ValidateAzureVMBackupManagementType(backupManagementTypeNullable.Value);
668660
}
669661

670-
string nameQueryFilter = friendlyName;
671-
672-
if (!string.IsNullOrEmpty(name))
673-
{
674-
Logger.Instance.WriteWarning(Resources.GetContainerNameParamDeprecated);
675-
676-
if (string.IsNullOrEmpty(friendlyName))
677-
{
678-
nameQueryFilter = name;
679-
}
680-
}
681-
682-
ODataQuery<BMSContainerQueryObject> queryParams = null;
683-
if (status == 0)
684-
{
685-
queryParams = new ODataQuery<BMSContainerQueryObject>(
686-
q => q.FriendlyName == nameQueryFilter &&
687-
q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureIaasVM);
688-
}
689-
else
690-
{
691-
var statusString = status.ToString();
692-
queryParams = new ODataQuery<BMSContainerQueryObject>(
693-
q => q.FriendlyName == nameQueryFilter &&
694-
q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureIaasVM &&
695-
q.Status == statusString);
696-
}
697-
698-
var listResponse = ServiceClientAdapter.ListContainers(
699-
queryParams,
700-
vaultName: vaultName,
701-
resourceGroupName: vaultResourceGroupName);
702-
703-
List<ContainerBase> containerModels = ConversionHelpers.GetContainerModelList(listResponse);
662+
var containerModels = AzureWorkloadProviderHelper.ListProtectionContainers(
663+
ProviderData,
664+
ServiceClientModel.BackupManagementType.AzureIaasVM);
704665

705-
// 4. Filter by RG Name
666+
// Filter by RG Name
706667
if (!string.IsNullOrEmpty(resourceGroupName))
707668
{
708669
containerModels = containerModels.Where(

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/PsBackupProviderManager.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ public IPsBackupProvider GetProviderInstance
108108
containerType));
109109
}
110110
break;
111+
case ContainerType.AzureStorage:
112+
if (backupManagementType == BackupManagementType.AzureStorage ||
113+
backupManagementType == null)
114+
{
115+
providerType = PsBackupProviderTypes.AzureFiles;
116+
}
117+
else
118+
{
119+
throw new ArgumentException(
120+
string.Format(
121+
Resources.BackupManagementTypeRequiredForContainerType,
122+
containerType));
123+
}
124+
break;
111125
default:
112126
throw new ArgumentException(
113127
string.Format(Resources.UnsupportedContainerType,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,17 @@
146146
</ItemGroup>
147147
<ItemGroup>
148148
<Compile Include="Properties\AssemblyInfo.cs" />
149+
<Compile Include="ScenarioTests\AzureFiles\ContainerTests.cs" />
149150
<Compile Include="ScenarioTests\AzureFiles\ItemTests.cs" />
150151
<Compile Include="ScenarioTests\AzureFiles\PolicyTests.cs" />
151152
<Compile Include="ScenarioTests\IaasVm\ProtectionCheckTests.cs" />
152153
<Compile Include="TestConstants.cs" />
153154
<None Include="packages.config">
154155
<SubType>Designer</SubType>
155156
</None>
157+
<None Include="ScenarioTests\AzureFiles\ContainerTests.ps1">
158+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
159+
</None>
156160
<None Include="ScenarioTests\AzureFiles\ItemTests.ps1">
157161
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
158162
</None>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.WindowsAzure.Commands.ScenarioTest;
17+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
18+
using Xunit;
19+
20+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Test.ScenarioTests
21+
{
22+
public partial class ContainerTests : RMTestBase
23+
{
24+
[Fact]
25+
[Trait(Category.AcceptanceType, Category.CheckIn)]
26+
[Trait(TestConstants.Workload, TestConstants.AzureFile)]
27+
public void TestAzureFileContainer()
28+
{
29+
TestController.NewInstance.RunPsTest(
30+
_logger, PsBackupProviderTypes.AzureFiles, "Test-AzureFileContainer");
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)