Skip to content

Commit 891bc6b

Browse files
Samuel Anudeepsiddharth7
authored andcommitted
Added Azure File Share support for get container and get item
1 parent d4fa66d commit 891bc6b

File tree

27 files changed

+926
-357
lines changed

27 files changed

+926
-357
lines changed

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

Lines changed: 88 additions & 39 deletions
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;
@@ -277,55 +282,99 @@ public static ItemBase GetItemModel(ServiceClientModel.ProtectedItemResource pro
277282
{
278283
if (protectedItem.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.AzureIaaSVMProtectedItem)))
279284
{
280-
string policyName = null;
281-
string policyId = ((ServiceClientModel.AzureIaaSVMProtectedItem)protectedItem.Properties).PolicyId;
282-
if (!string.IsNullOrEmpty(policyId))
283-
{
284-
Dictionary<UriEnums, string> keyValueDict =
285-
HelperUtils.ParseUri(policyId);
286-
policyName = HelperUtils.GetPolicyNameFromPolicyId(keyValueDict, policyId);
287-
}
288-
289-
string containerUri = HelperUtils.GetContainerUri(
290-
HelperUtils.ParseUri(protectedItem.Id),
291-
protectedItem.Id);
292-
293-
itemModel = new AzureVmItem(
294-
protectedItem,
295-
IdUtils.GetNameFromUri(containerUri),
296-
ContainerType.AzureVM,
297-
policyName);
285+
itemModel = GetAzureVmItemModel(protectedItem);
298286
}
299287

300288
if (protectedItem.Properties.GetType() ==
301289
typeof(ServiceClientModel.AzureSqlProtectedItem))
302290
{
303-
ServiceClientModel.AzureSqlProtectedItem azureSqlProtectedItem =
304-
(ServiceClientModel.AzureSqlProtectedItem)protectedItem.Properties;
305-
string policyName = null;
306-
string policyId = azureSqlProtectedItem.PolicyId;
307-
if (!string.IsNullOrEmpty(policyId))
308-
{
309-
Dictionary<UriEnums, string> keyVauleDict =
310-
HelperUtils.ParseUri(policyId);
311-
policyName = HelperUtils.GetPolicyNameFromPolicyId(keyVauleDict, policyId);
312-
}
313-
314-
string containerUri = HelperUtils.GetContainerUri(
315-
HelperUtils.ParseUri(protectedItem.Id),
316-
protectedItem.Id);
317-
318-
itemModel = new AzureSqlItem(
319-
protectedItem,
320-
IdUtils.GetNameFromUri(containerUri),
321-
ContainerType.AzureSQL,
322-
policyName);
291+
itemModel = GetAzureSqlItemModel(protectedItem);
292+
}
293+
294+
if (protectedItem.Properties.GetType() ==
295+
typeof(ServiceClientModel.AzureFileshareProtectedItem))
296+
{
297+
itemModel = GetAzureFileShareItemModel(protectedItem);
323298
}
324299
}
325300

326301
return itemModel;
327302
}
328303

304+
private static ItemBase GetAzureFileShareItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
305+
{
306+
ItemBase itemModel;
307+
string policyName = null;
308+
string policyId = ((ServiceClientModel.AzureFileshareProtectedItem)protectedItem.Properties).PolicyId;
309+
if (!string.IsNullOrEmpty(policyId))
310+
{
311+
Dictionary<UriEnums, string> keyValueDict =
312+
HelperUtils.ParseUri(policyId);
313+
policyName = HelperUtils.GetPolicyNameFromPolicyId(keyValueDict, policyId);
314+
}
315+
316+
string containerUri = HelperUtils.GetContainerUri(
317+
HelperUtils.ParseUri(protectedItem.Id),
318+
protectedItem.Id);
319+
320+
itemModel = new AzureFileShareItem(
321+
protectedItem,
322+
IdUtils.GetNameFromUri(containerUri),
323+
ContainerType.AzureStorage,
324+
policyName);
325+
return itemModel;
326+
}
327+
328+
private static ItemBase GetAzureSqlItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
329+
{
330+
ItemBase itemModel;
331+
ServiceClientModel.AzureSqlProtectedItem azureSqlProtectedItem =
332+
(ServiceClientModel.AzureSqlProtectedItem)protectedItem.Properties;
333+
string policyName = null;
334+
string policyId = azureSqlProtectedItem.PolicyId;
335+
if (!string.IsNullOrEmpty(policyId))
336+
{
337+
Dictionary<UriEnums, string> keyVauleDict =
338+
HelperUtils.ParseUri(policyId);
339+
policyName = HelperUtils.GetPolicyNameFromPolicyId(keyVauleDict, policyId);
340+
}
341+
342+
string containerUri = HelperUtils.GetContainerUri(
343+
HelperUtils.ParseUri(protectedItem.Id),
344+
protectedItem.Id);
345+
346+
itemModel = new AzureSqlItem(
347+
protectedItem,
348+
IdUtils.GetNameFromUri(containerUri),
349+
ContainerType.AzureSQL,
350+
policyName);
351+
return itemModel;
352+
}
353+
354+
private static ItemBase GetAzureVmItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
355+
{
356+
ItemBase itemModel;
357+
string policyName = null;
358+
string policyId = ((ServiceClientModel.AzureIaaSVMProtectedItem)protectedItem.Properties).PolicyId;
359+
if (!string.IsNullOrEmpty(policyId))
360+
{
361+
Dictionary<UriEnums, string> keyValueDict =
362+
HelperUtils.ParseUri(policyId);
363+
policyName = HelperUtils.GetPolicyNameFromPolicyId(keyValueDict, policyId);
364+
}
365+
366+
string containerUri = HelperUtils.GetContainerUri(
367+
HelperUtils.ParseUri(protectedItem.Id),
368+
protectedItem.Id);
369+
370+
itemModel = new AzureVmItem(
371+
protectedItem,
372+
IdUtils.GetNameFromUri(containerUri),
373+
ContainerType.AzureVM,
374+
policyName);
375+
return itemModel;
376+
}
377+
329378
/// <summary>
330379
/// Helper function to convert ps backup policy item list from service response.
331380
/// </summary>
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 File Share 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,97 @@
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 Microsoft.Azure.Management.RecoveryServices.Backup.Models;
17+
18+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
19+
{
20+
/// <summary>
21+
/// Azure File Share Item Class
22+
/// </summary>
23+
public class AzureFileShareItem : ItemBase
24+
{
25+
/// <summary>
26+
/// Protection Status of the item
27+
/// </summary>
28+
public ItemProtectionStatus ProtectionStatus { get; set; }
29+
30+
/// <summary>
31+
/// Protection State of the item
32+
/// </summary>
33+
public ItemProtectionState ProtectionState { get; set; }
34+
35+
/// <summary>
36+
/// Last Backup Status for the item
37+
/// </summary>
38+
public string LastBackupStatus { get; set; }
39+
40+
/// <summary>
41+
/// Last Backup Time for the item
42+
/// </summary>
43+
public DateTime? LastBackupTime { get; set; }
44+
45+
/// <summary>
46+
/// Protection Policy Name for the Item
47+
/// </summary>
48+
public string ProtectionPolicyName { get; set; }
49+
50+
/// <summary>
51+
/// ExtendedInfo for the Item
52+
/// </summary
53+
public AzureFileShareItemExtendedInfo ExtendedInfo { get; set; }
54+
55+
/// <summary>
56+
/// Constructor. Takes the service client object representing the protected item
57+
/// and converts it in to the PS protected item model
58+
/// </summary>
59+
/// <param name="protectedItemResource">Service client object representing the protected item resource</param>
60+
/// <param name="containerName">Name of the container associated with this protected item</param>
61+
/// <param name="containerType">Type of the container associated with this protected item</param>
62+
/// <param name="policyName">Name of the protection policy associated with this protected item</param>
63+
public AzureFileShareItem(ProtectedItemResource protectedItemResource,
64+
string containerName, ContainerType containerType, string policyName)
65+
: base(protectedItemResource, containerName, containerType)
66+
{
67+
AzureFileshareProtectedItem protectedItem = (AzureFileshareProtectedItem)protectedItemResource.Properties;
68+
LastBackupStatus = protectedItem.LastBackupStatus;
69+
LastBackupTime = protectedItem.LastBackupTime;
70+
ProtectionPolicyName = policyName;
71+
ProtectionState =
72+
EnumUtils.GetEnum<ItemProtectionState>(protectedItem.ProtectionState.ToString());
73+
ProtectionStatus = EnumUtils.GetEnum<ItemProtectionStatus>(protectedItem.ProtectionStatus);
74+
}
75+
}
76+
77+
/// <summary>
78+
/// Azure File Share Item ExtendedInfo Class
79+
/// </summary>
80+
public class AzureFileShareItemExtendedInfo : ItemExtendedInfoBase
81+
{
82+
/// <summary>
83+
/// Oldest Recovery Point for the Item
84+
/// </summary
85+
public DateTime? OldestRecoveryPoint { get; set; }
86+
87+
/// <summary>
88+
/// Recovery Points Count for the Item
89+
/// </summary
90+
public int RecoveryPointCount { get; set; }
91+
92+
/// <summary>
93+
/// PolicyState for the Item
94+
/// </summary
95+
public string PolicyState { get; set; }
96+
}
97+
}
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/CmdletParamEnums.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public enum PolicyParams
7171

7272
public enum ItemParams
7373
{
74-
AzureVMName,
74+
ItemName,
7575
AzureVMCloudServiceName,
7676
AzureVMResourceGroupName,
7777
WorkloadType,

0 commit comments

Comments
 (0)