Skip to content

Commit

Permalink
azure: vm: disks: destroy disks with snapshots safely; prevent --conf…
Browse files Browse the repository at this point in the history
…irm from wiping backups
  • Loading branch information
Phreedom committed Mar 23, 2016
1 parent 6f1ed13 commit 7a52fdf
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion nixops/backends/azure_vm.py
Expand Up @@ -261,7 +261,24 @@ def _delete_volume(self, media_link, disk_name = None, delete_vhd = None):
raise Exception("storage {0} provided in the deployment specification "
"doesn't match the storage of BLOB {1}"
.format(self.storage, media_link))
self.bs().delete_blob(blob["container"], blob["name"])
try:
self.bs().delete_blob(blob["container"], blob["name"])
except azure.common.AzureConflictHttpError as e:
if "<Error><Code>SnapshotsPresent</Code><Message>" in e.message:
if not self.depl.logger.confirm(
"the BLOB of Azure disk {0}({1}) has snapshots(backups); "
"deleting the disk BLOB also deletes snapshots; "
"keep the disk contents(BLOB)?"
.format(disk_name, media_link)):
self.log("destroying Azure disk BLOB {0} and its snapshots..."
.format(media_link))
self.bs().delete_blob(blob["container"], blob["name"],
x_ms_delete_snapshots = 'include')
else:
self.log("keeping the Azure disk BLOB {0}..."
.format(media_link))
else:
raise e
else:
self.log("keeping the Azure disk BLOB {0}...".format(media_link))

Expand Down

0 comments on commit 7a52fdf

Please sign in to comment.