Skip to content

Commit 907c7e4

Browse files
author
Samuel Anudeep
committed
Merge pull request #206 from MabOneSdk/anudeeb-dev1
Get-Item cmdlet for RS Vault Backup
2 parents 88cad0e + d71f98b commit 907c7e4

File tree

21 files changed

+687
-106
lines changed

21 files changed

+687
-106
lines changed

src/ResourceManager/RecoveryServices.Backup/CmdletParameterHelpMessages.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ internal static class Item
6464
public const string AzureVMServiceName = "Cloud Service Name for Azure Classic Compute VM.";
6565
public const string AzureVMResourceGroupName = "Resource Group Name for Azure Compute VM .";
6666
public const string ProtectedItem = "Filter value for status of job.";
67+
public const string ProtectionStatus = "Protection status of Item";
68+
public const string Status = "Status of the data source";
69+
public const string Container = "Container where the item resides";
6770
}
6871
}
6972
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Linq;
20+
using System.Management.Automation;
21+
using System.Text;
22+
using System.Threading.Tasks;
23+
24+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
25+
{
26+
/// <summary>
27+
/// Get list of items
28+
/// </summary>
29+
[Cmdlet(VerbsCommon.Get, "AzureRmRecoveryServicesItem"), OutputType(typeof(List<AzureRmRecoveryServicesItemBase>), typeof(AzureRmRecoveryServicesItemBase))]
30+
public class GetAzureRmRecoveryServicesItem : RecoveryServicesBackupCmdletBase
31+
{
32+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Item.Container)]
33+
[ValidateNotNullOrEmpty]
34+
public AzureRmRecoveryServicesContainerBase Container { get; set; }
35+
36+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Item.AzureVMName)]
37+
[ValidateNotNullOrEmpty]
38+
public string Name { get; set; }
39+
40+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Item.ProtectionStatus)]
41+
[ValidateNotNullOrEmpty]
42+
public ItemProtectionStatus ProtectionStatus { get; set; }
43+
44+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Item.Status)]
45+
[ValidateNotNullOrEmpty]
46+
public ItemStatus Status { get; set; }
47+
48+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
49+
[ValidateNotNullOrEmpty]
50+
public WorkloadType WorkloadType { get; set; }
51+
52+
public override void ExecuteCmdlet()
53+
{
54+
ExecutionBlock(() =>
55+
{
56+
base.ExecuteCmdlet();
57+
58+
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()
59+
{
60+
{ItemParams.Container, Container},
61+
{ItemParams.AzureVMName, Name},
62+
{ItemParams.ProtectionStatus, ProtectionStatus},
63+
{ItemParams.Status, Status},
64+
{ItemParams.WorkloadType, WorkloadType},
65+
}, HydraAdapter);
66+
67+
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(WorkloadType,
68+
(Container as AzureRmRecoveryServicesBackupManagementContext).BackupManagementType);
69+
var itemModels = psBackupProvider.ListProtectedItems();
70+
71+
if (itemModels.Count == 1)
72+
{
73+
WriteObject(itemModels.First());
74+
}
75+
else
76+
{
77+
WriteObject(itemModels);
78+
}
79+
});
80+
}
81+
}
82+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<ItemGroup>
7171
<Compile Include="Cmdlets\Container\GetAzureRmRecoveryServicesContainer.cs" />
7272
<Compile Include="Cmdlets\Item\EnableAzureRmRecoveryServicesProtection.cs" />
73+
<Compile Include="Cmdlets\Item\GetAzureRmRecoveryServicesItem.cs" />
7374
<Compile Include="Cmdlets\Jobs\GetAzureRmRecoveryServicesJob.cs" />
7475
<Compile Include="Cmdlets\Jobs\GetAzureRmRecoveryServicesJobDetails.cs" />
7576
<Compile Include="Cmdlets\Jobs\WaitAzureRmRecoveryServicesJob.cs" />

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,37 @@ public static List<AzureRmRecoveryServicesPolicyBase> GetPolicyModelList(Protect
132132
}
133133

134134
#endregion
135+
136+
#region Item
137+
138+
public static AzureRmRecoveryServicesItemBase GetItemModel(ProtectedItemResource protectedItem, AzureRmRecoveryServicesContainerBase container)
139+
{
140+
AzureRmRecoveryServicesItemBase itemModel = null;
141+
142+
if (protectedItem != null &&
143+
protectedItem.Properties != null)
144+
{
145+
if (protectedItem.Properties.GetType().IsSubclassOf(typeof(AzureIaaSVMProtectedItem)))
146+
{
147+
itemModel = new AzureRmRecoveryServicesIaasVmItem((AzureIaaSVMProtectedItem)protectedItem.Properties, container);
148+
}
149+
}
150+
151+
return itemModel;
152+
}
153+
154+
public static List<AzureRmRecoveryServicesItemBase> GetItemModelList(IEnumerable<ProtectedItemResource> protectedItems, AzureRmRecoveryServicesContainerBase container)
155+
{
156+
List<AzureRmRecoveryServicesItemBase> itemModels = new List<AzureRmRecoveryServicesItemBase>();
157+
158+
foreach (var protectedItem in protectedItems)
159+
{
160+
itemModels.Add(GetItemModel(protectedItem, container));
161+
}
162+
163+
return itemModels;
164+
}
165+
166+
#endregion
135167
}
136168
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private static AzureRmRecoveryServicesAzureVmJob GetPSAzureVmJob(JobResource hyd
9393
response.VmVersion = vmJob.VirtualMachineVersion;
9494
response.WorkloadName = vmJob.EntityFriendlyName;
9595
response.ActivityId = vmJob.ActivityId;
96-
response.BackupManagementType = vmJob.BackupManagementType;
96+
response.BackupManagementType = EnumUtils.GetEnum<BackupManagementType>(vmJob.BackupManagementType);
9797
response.Operation = vmJob.Operation;
9898

9999
if (vmJob.ErrorDetails != null)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public BaseRecoveryServicesJobResponse CreateOrUpdateProtectedItem(
2929
ProtectedItemCreateOrUpdateRequest request)
3030
{
3131
string resourceName = BmsAdapter.GetResourceName();
32-
string resourceGroupName = BmsAdapter.GetResourceName();
32+
string resourceGroupName = BmsAdapter.GetResourceGroupName();
3333

3434
return BmsAdapter.Client.ProtectedItem.CreateOrUpdateProtectedItemAsync(
3535
resourceGroupName,
@@ -47,7 +47,7 @@ public BaseRecoveryServicesJobResponse DeleteProtectedItem(
4747
string protectedItemName)
4848
{
4949
string resourceName = BmsAdapter.GetResourceName();
50-
string resourceGroupName = BmsAdapter.GetResourceName();
50+
string resourceGroupName = BmsAdapter.GetResourceGroupName();
5151

5252
return BmsAdapter.Client.ProtectedItem.DeleteProtectedItemAsync(
5353
resourceGroupName,
@@ -65,7 +65,7 @@ public ProtectedItemResponse GetProtectedItem(
6565
GetProtectedItemQueryParam queryFilter)
6666
{
6767
string resourceName = BmsAdapter.GetResourceName();
68-
string resourceGroupName = BmsAdapter.GetResourceName();
68+
string resourceGroupName = BmsAdapter.GetResourceGroupName();
6969

7070
return BmsAdapter.Client.ProtectedItem.GetAsync(
7171
resourceGroupName,
@@ -80,10 +80,10 @@ public ProtectedItemResponse GetProtectedItem(
8080

8181
public ProtectedItemListResponse ListProtectedItem(
8282
ProtectedItemListQueryParam queryFilter,
83-
PaginationRequest paginationParams)
83+
PaginationRequest paginationParams = null)
8484
{
8585
string resourceName = BmsAdapter.GetResourceName();
86-
string resourceGroupName = BmsAdapter.GetResourceName();
86+
string resourceGroupName = BmsAdapter.GetResourceGroupName();
8787

8888
return BmsAdapter.Client.ProtectedItem.ListAsync(
8989
resourceGroupName,

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,23 @@ public class AzureRmRecoveryServicesIaasVmContainer : AzureRmRecoveryServicesCon
2828
/// </summary>
2929
public string ResourceGroupName { get; set; }
3030

31+
/// <summary>
32+
/// Friendly name of the container
33+
/// </summary>
34+
public string FriendlyName { get; set; }
35+
3136
/// <summary>
3237
/// Registration Status
3338
/// </summary>
34-
public string Status { get; set; }
39+
public ContainerRegistrationStatus Status { get; set; }
3540

3641
public AzureRmRecoveryServicesIaasVmContainer(ProtectionContainerResource protectionContainer)
37-
: base(protectionContainer.Properties as ProtectionContainer)
42+
: base(protectionContainer)
3843
{
3944
AzureIaaSVMProtectionContainer iaasVmProtectionContainer = (AzureIaaSVMProtectionContainer)protectionContainer.Properties;
40-
ContainerType = ContainerType.AzureVM;
4145
ResourceGroupName = IdUtils.GetResourceGroupName(protectionContainer.Id);
42-
Status = iaasVmProtectionContainer.RegistrationStatus;
46+
FriendlyName = iaasVmProtectionContainer.FriendlyName;
47+
Status = EnumUtils.GetEnum<ContainerRegistrationStatus>(iaasVmProtectionContainer.RegistrationStatus);
4348
}
4449
}
4550
}

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
2525
/// Represents IaaSVM Item Class
2626
/// </summary>
2727
public class AzureRmRecoveryServicesIaasVmItem : AzureRmRecoveryServicesItemBase
28-
{
28+
{
29+
/// <summary>
30+
/// Friendly Name for the Item
31+
/// </summary>
32+
public string Name { get; set; }
33+
2934
public string VirtualMachineId { get; set; }
3035

3136
/// <summary>
3237
/// Protection Status of the item
3338
/// </summary>
34-
public string ProtectionStatus { get; set; }
39+
public ItemProtectionStatus ProtectionStatus { get; set; }
3540

3641
/// <summary>
3742
/// Protection State of the item
3843
/// </summary>
39-
public string ProtectionState { get; set; }
44+
public ItemStatus ProtectionState { get; set; }
4045

4146
/// <summary>
4247
/// Last Backup Status for the item
@@ -53,11 +58,16 @@ public class AzureRmRecoveryServicesIaasVmItem : AzureRmRecoveryServicesItemBase
5358
/// </summary
5459
public AzureRmRecoveryServicesIaasVmItemExtendedInfo ExtendedInfo { get; set; }
5560

56-
public AzureRmRecoveryServicesIaasVmItem(AzureIaaSVMProtectedItem protectedItem,
61+
public AzureRmRecoveryServicesIaasVmItem(AzureIaaSVMProtectedItem protectedItem,
5762
AzureRmRecoveryServicesContainerBase container)
5863
: base(protectedItem, container)
5964
{
60-
65+
LastBackupStatus = protectedItem.LastBackupStatus;
66+
ProtectionPolicyName = protectedItem.PolicyName;
67+
ProtectionState = EnumUtils.GetEnum<ItemStatus>(protectedItem.ProtectionState);
68+
ProtectionStatus = EnumUtils.GetEnum<ItemProtectionStatus>(protectedItem.ProtectionStatus);
69+
VirtualMachineId = protectedItem.VirtualMachineId;
70+
Name = protectedItem.FriendlyName;
6171
}
6272
}
6373

0 commit comments

Comments
 (0)