Skip to content

Commit 31fc75f

Browse files
committed
fixup! Shutdown VM if disk cannot be removed from running VM
1 parent 8e92668 commit 31fc75f

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

plugins/module_utils/errors.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ def __init__(self, data: Union[str, Exception]):
115115

116116

117117
class TaskTagError(ScaleComputingError):
118-
def __init__(self, task_tag: Dict[Any, Any]):
119-
# task_tag is dict as returned from HyperCore API
118+
def __init__(self, task_status: Dict[Any, Any]):
119+
# task_status is dict returned by GET /rest/v1/TaskTag
120120
message = "There was a problem during this task execution."
121-
message += f" Task details: {json.dumps(task_tag)}"
121+
message += f" Task details: {json.dumps(task_status)}"
122122
self.message = message
123-
self.task_tag_state = task_tag["state"]
124-
self.task_tag = task_tag
123+
self.task_status_state = task_status["state"]
124+
self.task_status = task_status
125125
super().__init__(self.message)

plugins/module_utils/vm.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,9 +1108,9 @@ def _delete_not_used_disks(cls, module, rest_client, vm, changed, disk_key):
11081108
except errors.TaskTagError as ex:
11091109
# Delete failed, maybe because VM was running and disk was in use.
11101110
# If VM is running, shutdown VM and retry delete.
1111-
if ex.task_tag_state != "ERROR":
1111+
if ex.task_status_state != "ERROR":
11121112
raise
1113-
if not cls._disk_remove_failed_because_vm_running(ex.task_tag):
1113+
if not cls._disk_remove_failed_because_vm_running(ex.task_status):
11141114
raise
11151115
vm_fresh_data = rest_client.get_record(
11161116
f"/rest/v1/VirDomain/{vm.uuid}", must_exist=True
@@ -1130,19 +1130,19 @@ def _delete_not_used_disks(cls, module, rest_client, vm, changed, disk_key):
11301130
return changed
11311131

11321132
@staticmethod
1133-
def _disk_remove_failed_because_vm_running(task_tag: Dict):
1133+
def _disk_remove_failed_because_vm_running(task_status: Dict):
11341134
# Look at task_tag dict returned by HyperCore to decide if disk remove failed
11351135
# because VM is running, and VM shutdown will allow us to remove the disk.
11361136
# What we search for in formattedMessage is HyperCore version dependent:
11371137
# 9.2.17 - "Unable to delete block device from VM '%@': Still in use"
11381138
# 9.1.14 - "Virt Exception, code: 84, domain 10: Operation not supported: This type of disk cannot be hot unplugged"
11391139

11401140
if (
1141-
task_tag["formattedMessage"]
1141+
task_status["formattedMessage"]
11421142
== "Unable to delete block device from VM '%@': Still in use"
11431143
):
11441144
return True
1145-
if task_tag["formattedMessage"].endswith(
1145+
if task_status["formattedMessage"].endswith(
11461146
"Operation not supported: This type of disk cannot be hot unplugged"
11471147
):
11481148
return True

0 commit comments

Comments
 (0)