Skip to content
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

Don't remove attached volumes #25

Merged
Merged
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions resalloc_ibm_cloud/ibm_cloud_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,23 +277,30 @@ def delete_instance_attempt(service, instance_name, opts):
assert resp.status_code == 204
log.debug("Delete IP request delivered")

# Query all volumes only after already potentionaly deleting an instance.
# The volumes might have been deleted automatically
# Query all volumes only after already potentially deleting an instance.
# The volumes should already be deleted automatically.
volume_ids = []
volumes = service.list_volumes(limit=LIMIT).result["volumes"]
for volume in volumes:
if not volume["name"].startswith(instance_name):
continue

if volume.get('attachment_state') == 'attached':
# Error 409 - can't remove attached volumes
continue

# Otherwise Error: Delete volume failed. Volume can be deleted
# only when its status is available or failed., Code: 409
if not volume["status"] in ["available", "failed"]:
continue

log.info("Volume '%s' (%s) is %s, removing manually", volume["name"],
volume["id"], volume["status"])
volume_ids.append(volume["id"])

if volume_ids:
for volume_id in volume_ids:
log.info("Deleting volume %s (%s)", volume_id)
resp = service.delete_volume(volume_id)
assert resp.status_code == 204
log.debug("Delete volume request delivered")
Expand Down