@@ -216,29 +216,18 @@ func (c *client) GetOrCreateVMInstance(
216
216
217
217
}
218
218
219
- // DestroyVMInstance Destroy a VM instance. Assumes machine has been fetched prior and has an instance ID.
219
+ // DestroyVMInstance Destroys a VM instance. Assumes machine has been fetched prior and has an instance ID.
220
220
func (c * client ) DestroyVMInstance (csMachine * infrav1.CloudStackMachine ) error {
221
221
222
- if err := c .ResolveVMInstanceDetails (csMachine ); err == nil && csMachine .Status .InstanceState != "Running" {
223
- if csMachine .Status .InstanceState == "Stopping" ||
224
- csMachine .Status .InstanceState == "Stopped" {
225
- return errors .New ("VM deletion in progress" )
226
- } else if csMachine .Status .InstanceState == "Expunging" ||
227
- csMachine .Status .InstanceState == "Expunged" {
228
- // VM is stopped and getting expunged. So the desired state is getting satisfied. Let's move on.
229
- return nil
230
- }
231
- } else if err != nil && strings .Contains (strings .ToLower (err .Error ()), "no match found" ) {
232
- // VM doesn't exist. So the desired state is in effect. Our work is done here.
233
- return nil
234
- }
235
-
222
+ // Attempt deletion regardless of machine state.
236
223
p := c .cs .VirtualMachine .NewDestroyVirtualMachineParams (* csMachine .Spec .InstanceID )
237
224
p .SetExpunge (true )
238
- _ , err := c .csAsync .VirtualMachine .DestroyVirtualMachine (p )
239
- if err != nil && strings .Contains (err .Error (), "unable to find UUID for id" ) {
240
- // VM doesn't exist. So the desired state is in effect. Our work is done here .
225
+ if _ , err := c .csAsync .VirtualMachine .DestroyVirtualMachine (p ); err != nil &&
226
+ strings .Contains (strings . ToLower ( err .Error ()) , "unable to find uuid for id" ) {
227
+ // VM doesn't exist. Success.. .
241
228
return nil
229
+ } else if err != nil {
230
+ return err
242
231
}
243
232
return errors .New ("VM deletion in progress" )
244
233
}
0 commit comments