Skip to content

Backup encryption settings and restore on failure #3824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 23 commits into from
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
95c4766
Merge branch 'vmbackup_stgaccts_fix' into dev
Oct 20, 2016
c9d5a62
Merge branch 'ade_query_fix' into dev
Oct 22, 2016
f841fcc
Merge remote-tracking branch 'upstream/dev' into dev
Oct 26, 2016
00f1639
Merge remote-tracking branch 'upstream/dev' into dev
Oct 28, 2016
2535c73
Use test extension for ADE on Linux
Oct 31, 2016
c0475a3
Merge remote-tracking branch 'upstream/dev' into dev
Nov 23, 2016
69a63bd
Merge remote-tracking branch 'upstream/dev' into dev
Dec 2, 2016
42116bc
Merge remote-tracking branch 'upstream/dev' into dev
Dec 6, 2016
0a5d947
Merge remote-tracking branch 'upstream/dev' into dev
Dec 20, 2016
17ba06e
Merge remote-tracking branch 'upstream/dev' into dev
Jan 4, 2017
b412001
Merge remote-tracking branch 'upstream/dev' into dev
Jan 11, 2017
a837bc7
Merge remote-tracking branch 'upstream/dev' into dev
Jan 18, 2017
26a829a
Merge remote-tracking branch 'upstream/dev' into dev
Jan 24, 2017
52e69bc
Merge remote-tracking branch 'upstream/dev' into dev
Feb 10, 2017
41afc63
Merge remote-tracking branch 'upstream/dev' into dev
Feb 15, 2017
cd3cc5e
Merge remote-tracking branch 'upstream/dev' into dev
Mar 1, 2017
176f549
Merge remote-tracking branch 'upstream/dev' into dev
Mar 27, 2017
1ded6b0
Merge remote-tracking branch 'upstream/dev' into dev
Apr 13, 2017
4b39169
Revert "Use test extension for ADE on Linux"
Apr 13, 2017
a394559
Do not update VM encryption settings if extension install fails
Apr 13, 2017
d30bec1
Restore encryption settings if updateVm call fails
Apr 13, 2017
8ef12eb
Report HTTP response contents in the exception
Apr 13, 2017
b1180c1
Use non-null settings for reverting encryption
Apr 19, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ private AzureOperationResponse<VirtualMachine> UpdateVmEncryptionSettings()
null));
}

DiskEncryptionSettings encryptionSettingsBackup = vmParameters.StorageProfile.OsDisk.EncryptionSettings;

if (encryptionSettingsBackup == null)
{
encryptionSettingsBackup = new DiskEncryptionSettings();
encryptionSettingsBackup.Enabled = false;
}

DiskEncryptionSettings encryptionSettings = new DiskEncryptionSettings();
encryptionSettings.Enabled = true;
encryptionSettings.DiskEncryptionKey = new KeyVaultSecretReference();
Expand All @@ -306,10 +314,25 @@ private AzureOperationResponse<VirtualMachine> UpdateVmEncryptionSettings()
Location = vmParameters.Location,
Tags = vmParameters.Tags
};
return this.ComputeClient.ComputeManagementClient.VirtualMachines.CreateOrUpdateWithHttpMessagesAsync(

AzureOperationResponse<VirtualMachine> updateResult = this.ComputeClient.ComputeManagementClient.VirtualMachines.CreateOrUpdateWithHttpMessagesAsync(
this.ResourceGroupName,
vmParameters.Name,
parameters).GetAwaiter().GetResult();

if(!updateResult.Response.IsSuccessStatusCode)
{
vmParameters = (this.ComputeClient.ComputeManagementClient.VirtualMachines.Get(
this.ResourceGroupName, this.VMName));
vmParameters.StorageProfile.OsDisk.EncryptionSettings = encryptionSettingsBackup;

this.ComputeClient.ComputeManagementClient.VirtualMachines.CreateOrUpdateWithHttpMessagesAsync(
this.ResourceGroupName,
vmParameters.Name,
parameters).GetAwaiter().GetResult();
}

return updateResult;
}

private Hashtable GetExtensionPublicSettings()
Expand Down Expand Up @@ -444,12 +467,23 @@ public override void ExecuteCmdlet()

VirtualMachineExtension parameters = GetVmExtensionParameters(virtualMachineResponse);

this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
AzureOperationResponse<VirtualMachineExtension> extensionPushResult = this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
this.ResourceGroupName,
this.VMName,
this.Name,
parameters).GetAwaiter().GetResult();

if (!extensionPushResult.Response.IsSuccessStatusCode)
{
ThrowTerminatingError(new ErrorRecord(new ApplicationException(string.Format(CultureInfo.CurrentUICulture,
"Installation failed for extension {0} with error {1}",
parameters.VirtualMachineExtensionType,
extensionPushResult.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult())),
"InvalidResult",
ErrorCategory.InvalidResult,
null));
}

var op = UpdateVmEncryptionSettings();
var result = Mapper.Map<PSAzureOperationResponse>(op);
WriteObject(result);
Expand Down