Code Monkey home page Code Monkey logo

Comments (3)

resmo avatar resmo commented on August 14, 2024

Good catch:

This would be my patch suggestion. I would add a condition for the vm['state'], (I am unsure if the state of a destroyed VM is destroyed or removed):

diff --git a/cloudstack_vm.py b/cloudstack_vm.py
index bcfee85..0ee4cda 100644
--- a/cloudstack_vm.py
+++ b/cloudstack_vm.py
@@ -445,11 +445,26 @@ def remove_vm(module, cs, result, vm):

 def expunge_vm(module, cs, result, vm):
     if vm:
-        if not module.check_mode:
-            res = cs.expungeVirtualMachine(id=vm['id'])
-            if 'errortext' in res:
-                module.fail_json(msg="Failed: '%s'" % res['errortext'])
-        result['changed'] = True
+        res = {}
+        # TODO: Is the state destroyed or removed?
+        if vm['state'] in [ 'destroying', 'destroyed']:
+            result['changed'] = True
+            if not module.check_mode:
+                res = cs.expungeVirtualMachine(id=vm['id'])
+
+        # TODO: Would we ever see a vm state expunged?
+        elif vm['state'] not in ['expunging', 'expunged' ]:
+            result['changed'] = True
+            if not module.check_mode:
+                res = cs.destroyVirtualMachine(id=vm['id'], expunge=True)
+
+        if res and 'errortext' in res:
+            module.fail_json(msg="Failed: '%s'" % res['errortext'])
+
+        poll_async = module.params.get('poll_async')
+        if poll_async:
+            vm = poll_job(cs, res, 'virtualmachine')
+
     return (result, vm)

from ansible-cloudstack.

xied75 avatar xied75 commented on August 14, 2024

Answer: Destroyed
Answer: Expunging, then null

from ansible-cloudstack.

resmo avatar resmo commented on August 14, 2024

implemented

from ansible-cloudstack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.