@@ -1110,11 +1110,7 @@ def _delete_not_used_disks(cls, module, rest_client, vm, changed, disk_key):
11101110 # If VM is running, shutdown VM and retry delete.
11111111 if ex .task_tag_state != "ERROR" :
11121112 raise
1113- # The particular "formattedMessage" is returned by HyperCore 9.2.17
1114- if (
1115- ex .task_tag ["formattedMessage" ]
1116- != "Unable to delete block device from VM '%@': Still in use"
1117- ):
1113+ if not cls ._disk_remove_failed_because_vm_running (ex .task_tag ):
11181114 raise
11191115 vm_fresh_data = rest_client .get_record (
11201116 f"/rest/v1/VirDomain/{ vm .uuid } " , must_exist = True
@@ -1133,6 +1129,25 @@ def _delete_not_used_disks(cls, module, rest_client, vm, changed, disk_key):
11331129 changed = True
11341130 return changed
11351131
1132+ @staticmethod
1133+ def _disk_remove_failed_because_vm_running (task_tag : Dict ):
1134+ # Look at task_tag dict returned by HyperCore to decide if disk remove failed
1135+ # because VM is running, and VM shutdown will allow us to remove the disk.
1136+ # What we search for in formattedMessage is HyperCore version dependent:
1137+ # 9.2.17 - "Unable to delete block device from VM '%@': Still in use"
1138+ # 9.1.14 - "Virt Exception, code: 84, domain 10: Operation not supported: This type of disk cannot be hot unplugged"
1139+
1140+ if (
1141+ task_tag ["formattedMessage" ]
1142+ == "Unable to delete block device from VM '%@': Still in use"
1143+ ):
1144+ return True
1145+ if task_tag ["formattedMessage" ].endswith (
1146+ "Operation not supported: This type of disk cannot be hot unplugged"
1147+ ):
1148+ return True
1149+ return False
1150+
11361151 @staticmethod
11371152 def _force_remove_all_disks (module , rest_client , vm , disks_before ):
11381153 # It's important to check if items is equal to empty list and empty list only (no None-s)
0 commit comments