Shutting down a VM
From Xen
Jump to navigationJump to search
This page shows how to use the XenAPI to shut down a VM. The examples are written in python (feel free to add translations to other languages) and will use the API via the local Unix domain socket.
To request a clean shutdown of a VM with a given uuid: (Note this will block for up to 20 minutes while the VM is shutting down)
#!/usr/bin/env python import XenAPI, sys if len(sys.argv) <> 2: print "Usage:" print sys.argv[0], "<VM uuid>" sys.exit(1) uuid = sys.argv[1] session = XenAPI.xapi_local() session.xenapi.login_with_password("root", "") try: vm = xenapi.VM.get_by_uuid(uuid) xenapi.VM.clean_shutdown(vm) finally: session.xenapi.session.logout()