Skip to content

Commit c1deefd

Browse files
committed
remove the revert-on-error code
1 parent 8c081de commit c1deefd

File tree

1 file changed

+14
-63
lines changed

1 file changed

+14
-63
lines changed

src/ResourceManager/Compute/Commands.Compute/Extension/AzureDiskEncryption/SetAzureDiskEncryptionExtension.cs

Lines changed: 14 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -309,30 +309,18 @@ private AzureOperationResponse<VirtualMachine> UpdateVmEncryptionSettings(DiskEn
309309

310310
AzureOperationResponse<VirtualMachine> updateResult = null;
311311

312-
// The 2nd pass. If something goes wrong here, try to revert to encryptionSettingsBackup.
312+
// The 2nd pass. TODO: If something goes wrong here, try to revert to encryptionSettingsBackup.
313313
if (encryptionSettingsBackup.Enabled != true)
314314
{
315-
try
316-
{
317-
updateResult = this.ComputeClient.ComputeManagementClient.VirtualMachines.CreateOrUpdateWithHttpMessagesAsync(
318-
this.ResourceGroupName,
319-
vmParameters.Name,
320-
parameters).GetAwaiter().GetResult();
321-
} catch (Exception e)
322-
{
323-
revertVm(encryptionSettingsBackup);
324-
throw e;
325-
}
326-
327-
if (!updateResult.Response.IsSuccessStatusCode)
328-
{
329-
revertVm(encryptionSettingsBackup);
330-
}
315+
updateResult = this.ComputeClient.ComputeManagementClient.VirtualMachines.CreateOrUpdateWithHttpMessagesAsync(
316+
this.ResourceGroupName,
317+
vmParameters.Name,
318+
parameters).GetAwaiter().GetResult();
331319
}
332320
else
333321
{
334322

335-
// For premium storage VMs, stop-update-start
323+
// stop-update-start
336324
// stop vm
337325
this.ComputeClient.ComputeManagementClient.VirtualMachines
338326
.DeallocateWithHttpMessagesAsync(this.ResourceGroupName, this.VMName).GetAwaiter()
@@ -354,38 +342,15 @@ private AzureOperationResponse<VirtualMachine> UpdateVmEncryptionSettings(DiskEn
354342
Location = vmParameters.Location,
355343
Tags = vmParameters.Tags
356344
};
357-
AzureOperationResponse<Azure.Management.Compute.Models.OperationStatusResponse> startOp = null;
358-
try
359-
{
360-
updateResult = this.ComputeClient.ComputeManagementClient.VirtualMachines.CreateOrUpdateWithHttpMessagesAsync(
361-
this.ResourceGroupName,
362-
vmParameters.Name,
363-
parameters).GetAwaiter().GetResult();
364345

365-
// start vm
366-
startOp = this.ComputeClient.ComputeManagementClient.VirtualMachines
367-
.StartWithHttpMessagesAsync(ResourceGroupName, this.VMName).GetAwaiter().GetResult();
368-
} catch (Exception e)
369-
{
370-
// in case of error: stop-revert-start
371-
this.ComputeClient.ComputeManagementClient.VirtualMachines
372-
.DeallocateWithHttpMessagesAsync(this.ResourceGroupName, this.VMName).GetAwaiter()
373-
.GetResult();
374-
revertVm(encryptionSettingsBackup);
375-
this.ComputeClient.ComputeManagementClient.VirtualMachines
376-
.StartWithHttpMessagesAsync(this.ResourceGroupName, this.VMName).GetAwaiter().GetResult();
377-
throw e;
378-
}
379-
if (!updateResult.Response.IsSuccessStatusCode || !startOp.Response.IsSuccessStatusCode)
380-
{
381-
// in case of error: stop-revert-start
382-
this.ComputeClient.ComputeManagementClient.VirtualMachines
383-
.DeallocateWithHttpMessagesAsync(this.ResourceGroupName, this.VMName).GetAwaiter()
384-
.GetResult();
385-
revertVm(encryptionSettingsBackup);
386-
this.ComputeClient.ComputeManagementClient.VirtualMachines
387-
.StartWithHttpMessagesAsync(this.ResourceGroupName, this.VMName).GetAwaiter().GetResult();
388-
}
346+
updateResult = this.ComputeClient.ComputeManagementClient.VirtualMachines.CreateOrUpdateWithHttpMessagesAsync(
347+
this.ResourceGroupName,
348+
vmParameters.Name,
349+
parameters).GetAwaiter().GetResult();
350+
351+
// start vm
352+
this.ComputeClient.ComputeManagementClient.VirtualMachines
353+
.StartWithHttpMessagesAsync(ResourceGroupName, this.VMName).GetAwaiter().GetResult();
389354
}
390355

391356
return updateResult;
@@ -551,19 +516,5 @@ public override void ExecuteCmdlet()
551516
}
552517
});
553518
}
554-
555-
private AzureOperationResponse<VirtualMachine> revertVm(DiskEncryptionSettings encryptionSettingsBackup)
556-
{
557-
var vmRevertParameters = (this.ComputeClient.ComputeManagementClient.VirtualMachines.Get(
558-
this.ResourceGroupName, this.VMName));
559-
vmRevertParameters.StorageProfile.OsDisk.EncryptionSettings = encryptionSettingsBackup;
560-
561-
return this.ComputeClient.ComputeManagementClient.VirtualMachines
562-
.CreateOrUpdateWithHttpMessagesAsync(
563-
this.ResourceGroupName,
564-
vmRevertParameters.Name,
565-
vmRevertParameters).GetAwaiter().GetResult();
566-
}
567-
568519
}
569520
}

0 commit comments

Comments
 (0)