Skip to content

Commit 9002a70

Browse files
committed
Incorporating CSM feedback changes in powershell
1 parent dc0f4eb commit 9002a70

File tree

7 files changed

+38
-21
lines changed

7 files changed

+38
-21
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,11 @@ public static AzureRmRecoveryServicesItemBase GetItemModel(ProtectedItemResource
183183
{
184184
if (protectedItem.Properties.GetType().IsSubclassOf(typeof(AzureIaaSVMProtectedItem)))
185185
{
186-
itemModel = new AzureRmRecoveryServicesIaasVmItem(protectedItem, container);
186+
string policyId = ((AzureIaaSVMProtectedItem)protectedItem.Properties).PolicyId;
187+
Dictionary<UriEnums, string> keyVauleDict =
188+
HelperUtils.ParseUri(policyId);
189+
string policyName = HelperUtils.GetPolicyNameFromPolicyId(keyVauleDict, policyId);
190+
itemModel = new AzureRmRecoveryServicesIaasVmItem(protectedItem, container, policyName);
187191
}
188192
}
189193

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Utils.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ public static string GetProtectableItemUri(Dictionary<CmdletModel.UriEnums, stri
126126
}
127127
return protectableItemUri;
128128
}
129+
130+
public static string GetPolicyNameFromPolicyId(Dictionary<CmdletModel.UriEnums, string> keyValuePairDict, string id)
131+
{
132+
string policyName = string.Empty;
133+
134+
if (keyValuePairDict.ContainsKey(CmdletModel.UriEnums.BackupPolicies))
135+
{
136+
policyName = keyValuePairDict[CmdletModel.UriEnums.BackupPolicies];
137+
}
138+
else
139+
{
140+
throw new ArgumentException(string.Format(Resources.URIValueNotFound,
141+
CmdletModel.UriEnums.BackupPolicies.ToString(), id));
142+
}
143+
return policyName;
144+
}
129145

130146
}
131147
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ public BaseRecoveryServicesJobResponse RestoreDisk(AzureRmRecoveryServicesIaasVm
4848
CreateNewCloudService = false,
4949
RecoveryPointId = recoveryPointId,
5050
RecoveryType = RecoveryType.RestoreDisks,
51-
Region = vaultLocation,
52-
StorageAccountName = storageAccountId,
53-
SubnetName = string.Empty,
54-
VirtualMachineName = string.Empty,
55-
VirtualNetworkName = string.Empty,
51+
Region = vaultLocation // TBD - To be fixed by Mkherani
5652
};
5753

5854
TriggerRestoreRequest triggerRestoreRequest = new TriggerRestoreRequest();

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
2626
/// </summary>
2727
public class AzureRmRecoveryServicesIaasVmItem : AzureRmRecoveryServicesItemBase
2828
{
29-
/// <summary>
30-
/// Friendly Name for the Item
31-
/// </summary>
32-
public string Name { get; set; }
33-
3429
public string VirtualMachineId { get; set; }
3530

3631
/// <summary>
@@ -59,16 +54,15 @@ public class AzureRmRecoveryServicesIaasVmItem : AzureRmRecoveryServicesItemBase
5954
public AzureRmRecoveryServicesIaasVmItemExtendedInfo ExtendedInfo { get; set; }
6055

6156
public AzureRmRecoveryServicesIaasVmItem(ProtectedItemResource protectedItemResource,
62-
AzureRmRecoveryServicesContainerBase container)
57+
AzureRmRecoveryServicesContainerBase container, string policyName)
6358
: base(protectedItemResource, container)
6459
{
6560
AzureIaaSVMProtectedItem protectedItem = (AzureIaaSVMProtectedItem)protectedItemResource.Properties;
6661
LastBackupStatus = protectedItem.LastBackupStatus;
67-
ProtectionPolicyName = protectedItem.PolicyName;
62+
ProtectionPolicyName = policyName;
6863
ProtectionState = EnumUtils.GetEnum<ItemStatus>(protectedItem.ProtectionState);
6964
ProtectionStatus = EnumUtils.GetEnum<ItemProtectionStatus>(protectedItem.ProtectionStatus);
7065
VirtualMachineId = protectedItem.VirtualMachineId;
71-
Name = protectedItem.FriendlyName;
7266
}
7367
}
7468

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/BaseObjects.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public AzureRmRecoveryServicesItemContext(ProtectedItem protectedItem,
121121
: base(container.ContainerType, protectedItem.BackupManagementType)
122122
{
123123
WorkloadType = ConversionUtils.GetPsWorkloadType(protectedItem.WorkloadType);
124-
ContainerName = protectedItem.ContainerName;
124+
ContainerName = container.Name;
125125
}
126126
}
127127

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public class IaasVmPsBackupProvider : IPsBackupProvider
3333
{
3434
private const int defaultOperationStatusRetryTimeInMilliSec = 5 * 1000; // 5 sec
3535
private const string separator = ";";
36-
private const string computeAzureVMVersion = "Compute";
37-
private const string classicComputeAzureVMVersion = "ClassicCompute";
36+
private const string computeAzureVMVersion = "Microsoft.Compute";
37+
private const string classicComputeAzureVMVersion = "Microsoft.ClassicCompute";
3838

3939
ProviderData ProviderData { get; set; }
4040
HydraAdapter.HydraAdapter HydraAdapter { get; set; }
@@ -107,7 +107,7 @@ public BaseRecoveryServicesJobResponse EnableProtection()
107107
properties = new AzureIaaSComputeVMProtectedItem();
108108
}
109109

110-
properties.PolicyName = policy.Name;
110+
properties.PolicyId = policy.Id;
111111

112112
ProtectedItemCreateOrUpdateRequest hydraRequest = new ProtectedItemCreateOrUpdateRequest()
113113
{
@@ -164,7 +164,7 @@ public BaseRecoveryServicesJobResponse DisableProtection()
164164
properties = new AzureIaaSComputeVMProtectedItem();
165165
}
166166

167-
properties.PolicyName = string.Empty;
167+
properties.PolicyId = string.Empty;
168168
properties.ProtectionState = ItemStatus.ProtectionStopped.ToString();
169169

170170
ProtectedItemCreateOrUpdateRequest hydraRequest = new ProtectedItemCreateOrUpdateRequest()
@@ -760,6 +760,7 @@ private bool IsDiscoveryNeeded(string vmName, string rgName, bool isComputeAzure
760760
protectableObjectResource = null;
761761
string vmVersion = string.Empty;
762762
vmVersion = (isComputeAzureVM) == true ? computeAzureVMVersion : classicComputeAzureVMVersion;
763+
string virtualMachineId = GetAzureIaasVirtualMachineId(rgName, vmVersion, vmName);
763764

764765
ProtectableObjectListQueryParameters queryParam = new ProtectableObjectListQueryParameters();
765766
// --- TBD To be added once bug is fixed in hydra and service
@@ -785,8 +786,8 @@ private bool IsDiscoveryNeeded(string vmName, string rgName, bool isComputeAzure
785786
AzureIaaSVMProtectableItem iaaSVMProtectableItem = (AzureIaaSVMProtectableItem)protectableItem.Properties;
786787
if (iaaSVMProtectableItem != null &&
787788
string.Compare(iaaSVMProtectableItem.FriendlyName, vmName, true) == 0
788-
&& string.Compare(iaaSVMProtectableItem.ResourceGroup, rgName, true) == 0
789-
&& string.Compare(iaaSVMProtectableItem.VirtualMachineVersion, vmVersion, true) == 0)
789+
&& iaaSVMProtectableItem.VirtualMachineId.IndexOf(virtualMachineId,
790+
StringComparison.InvariantCultureIgnoreCase) >= 0)
790791
{
791792
protectableObjectResource = protectableItem;
792793
isDiscoveryNeed = false;
@@ -862,6 +863,12 @@ private HttpStatusCode TrackRefreshContainerOperation(string operationResultLink
862863
return status;
863864
}
864865

866+
private static string GetAzureIaasVirtualMachineId(string resourceGroup, string vmVersion, string name)
867+
{
868+
string IaasVMIdFormat = "/resourceGroups/{0}/providers/{1}/virtualMachines/{2}";
869+
return string.Format(IaasVMIdFormat, resourceGroup, vmVersion, name);
870+
}
871+
865872
private void CopyScheduleTimeToRetentionTimes(AzureRmRecoveryServicesBackupLongTermRetentionPolicy retPolicy,
866873
AzureRmRecoveryServicesBackupSimpleSchedulePolicy schPolicy)
867874
{

0 commit comments

Comments
 (0)