Skip to content

Commit d8a39ec

Browse files
author
Samuel Anudeep
committed
Bugfixes:
1. Bug 1526979: Get-AzureRmRecoveryServicesBackupItem should do case insensitive comparison for container name filter 2. AzureVmItem should have property displaying ServiceClientModel.AzureIaaSVMProtectedItem.LastBackupTime 3. Some foundation for - Bug 1524000: [PowerShell][New-Ask] For V2 Vm restores, block storage accounts with Kind "Blob Storage" at PowerShell Removing traces of changes made for Storage.Kind
1 parent 2b5322e commit d8a39ec

File tree

5 files changed

+56
-47
lines changed

5 files changed

+56
-47
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public class AzureVmItem : ItemBase
3939
/// </summary>
4040
public string LastBackupStatus { get; set; }
4141

42+
/// <summary>
43+
/// Last Backup Time for the item
44+
/// </summary>
45+
public DateTime? LastBackupTime { get; set; }
46+
4247
/// <summary>
4348
/// Protection Policy Name for the Item
4449
/// </summary>
@@ -63,6 +68,7 @@ public AzureVmItem(ProtectedItemResource protectedItemResource,
6368
{
6469
AzureIaaSVMProtectedItem protectedItem = (AzureIaaSVMProtectedItem)protectedItemResource.Properties;
6570
LastBackupStatus = protectedItem.LastBackupStatus;
71+
LastBackupTime = protectedItem.LastBackupTime;
6672
ProtectionPolicyName = policyName;
6773
ProtectionState =
6874
EnumUtils.GetEnum<ItemProtectionState>(protectedItem.ProtectionState.ToString());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ public List<ItemBase> ListProtectedItems()
677677

678678
var delimIndex = containerUri.IndexOf(';');
679679
string containerName = containerUri.Substring(delimIndex + 1);
680-
return containerName.Equals(container.Name);
680+
return containerName.ToLower().Equals(container.Name.ToLower());
681681
}).ToList();
682682
}
683683

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Test/ScenarioTests/IaasVm/ItemTests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function Test-AzureVMGetItems
4747
-Name $vm.Name;
4848
Assert-True { $items.Count -eq 1 }
4949
Assert-True { $items.VirtualMachineId -contains $vm.Id }
50+
Assert-NotNull $items[0].LastBackupTime
5051

5152
# VARIATION-3: Get items for container with ProtectionStatus filter
5253
$items = Get-AzureRmRecoveryServicesBackupItem `

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/Cmdlets/Restore/RestoreAzureRMRecoveryServicesBackupItem.cs

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -60,55 +60,17 @@ public override void ExecuteCmdlet()
6060
ExecutionBlock(() =>
6161
{
6262
base.ExecuteCmdlet();
63-
StorageAccountName = StorageAccountName.ToLower();
64-
ResourceIdentity identity = new ResourceIdentity();
65-
identity.ResourceName = StorageAccountName;
66-
identity.ResourceProviderNamespace = "Microsoft.ClassicStorage/storageAccounts";
67-
identity.ResourceProviderApiVersion = "2015-12-01";
68-
identity.ResourceType = string.Empty;
69-
identity.ParentResourcePath = string.Empty;
7063

71-
GenericResource resource = null;
72-
try
73-
{
74-
WriteDebug(string.Format("Query Microsoft.ClassicStorage with name = {0}",
75-
StorageAccountName));
76-
resource = RmClient.Resources.GetAsync(
77-
StorageAccountResourceGroupName,
78-
identity.ResourceProviderNamespace,
79-
identity.ParentResourcePath,
80-
identity.ResourceType,
81-
identity.ResourceName,
82-
identity.ResourceProviderApiVersion,
83-
CancellationToken.None).Result;
84-
}
85-
catch (Exception)
86-
{
87-
identity.ResourceProviderNamespace = "Microsoft.Storage/storageAccounts";
88-
identity.ResourceProviderApiVersion = "2016-01-01";
89-
resource = RmClient.Resources.GetAsync(
90-
StorageAccountResourceGroupName,
91-
identity.ResourceProviderNamespace,
92-
identity.ParentResourcePath,
93-
identity.ResourceType,
94-
identity.ResourceName,
95-
identity.ResourceProviderApiVersion,
96-
CancellationToken.None).Result;
97-
}
98-
99-
string storageAccountId = resource.Id;
100-
string storageAccountlocation = resource.Location;
101-
string storageAccountType = resource.Type;
102-
103-
WriteDebug(string.Format("StorageId = {0}", storageAccountId));
64+
GenericResource storageAccountResource = GetStorageAccountResource();
65+
WriteDebug(string.Format("StorageId = {0}", storageAccountResource.Id));
10466

10567
PsBackupProviderManager providerManager = new PsBackupProviderManager(
10668
new Dictionary<Enum, object>()
10769
{
10870
{RestoreBackupItemParams.RecoveryPoint, RecoveryPoint},
109-
{RestoreBackupItemParams.StorageAccountId, storageAccountId},
110-
{RestoreBackupItemParams.StorageAccountLocation, storageAccountlocation},
111-
{RestoreBackupItemParams.StorageAccountType, storageAccountType}
71+
{RestoreBackupItemParams.StorageAccountId, storageAccountResource.Id},
72+
{RestoreBackupItemParams.StorageAccountLocation, storageAccountResource.Location},
73+
{RestoreBackupItemParams.StorageAccountType, storageAccountResource.Type}
11274
}, ServiceClientAdapter);
11375

11476
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(
@@ -119,5 +81,46 @@ public override void ExecuteCmdlet()
11981
HandleCreatedJob(jobResponse, Resources.RestoreOperation);
12082
}, ShouldProcess(RecoveryPoint.ItemName, VerbsData.Restore));
12183
}
84+
85+
private GenericResource GetStorageAccountResource()
86+
{
87+
StorageAccountName = StorageAccountName.ToLower();
88+
ResourceIdentity identity = new ResourceIdentity();
89+
identity.ResourceName = StorageAccountName;
90+
identity.ResourceProviderNamespace = "Microsoft.ClassicStorage/storageAccounts";
91+
identity.ResourceProviderApiVersion = "2015-12-01";
92+
identity.ResourceType = string.Empty;
93+
identity.ParentResourcePath = string.Empty;
94+
95+
GenericResource resource = null;
96+
try
97+
{
98+
WriteDebug(string.Format("Query Microsoft.ClassicStorage with name = {0}",
99+
StorageAccountName));
100+
resource = RmClient.Resources.GetAsync(
101+
StorageAccountResourceGroupName,
102+
identity.ResourceProviderNamespace,
103+
identity.ParentResourcePath,
104+
identity.ResourceType,
105+
identity.ResourceName,
106+
identity.ResourceProviderApiVersion,
107+
CancellationToken.None).Result;
108+
}
109+
catch (Exception)
110+
{
111+
identity.ResourceProviderNamespace = "Microsoft.Storage/storageAccounts";
112+
identity.ResourceProviderApiVersion = "2016-01-01";
113+
resource = RmClient.Resources.GetAsync(
114+
StorageAccountResourceGroupName,
115+
identity.ResourceProviderNamespace,
116+
identity.ParentResourcePath,
117+
identity.ResourceType,
118+
identity.ResourceName,
119+
identity.ResourceProviderApiVersion,
120+
CancellationToken.None).Result;
121+
}
122+
123+
return resource;
124+
}
122125
}
123126
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
using System.Collections.Generic;
1717
using System.Management.Automation;
1818
using Microsoft.Azure.Commands.Common.Authentication;
19-
using Microsoft.Azure.Commands.Common.Authentication.Models;
19+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
2020
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS;
2121
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
2222
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
@@ -26,7 +26,6 @@
2626
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2727
using ResourcesNS = Microsoft.Azure.Management.Internal.Resources;
2828
using SystemNet = System.Net;
29-
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
3029

3130
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
3231
{
@@ -52,7 +51,7 @@ protected void InitializeAzureBackupCmdlet()
5251
{
5352
ServiceClientAdapter = new ServiceClientAdapter(DefaultContext);
5453

55-
WriteDebug("InsideRestore. going to create ResourceManager Client");
54+
WriteDebug("Inside Restore. Going to create ResourceClient.");
5655
RmClient = AzureSession.Instance.ClientFactory.CreateArmClient<ResourcesNS.ResourceManagementClient>(DefaultContext, AzureEnvironment.Endpoint.ResourceManager);
5756

5857
WriteDebug("Client Created successfully");

0 commit comments

Comments
 (0)