27 from common
import log
28 from common.states
import vm_states
30 from cm.utils.decorators
import ci_log
31 from cm.utils.exception
import CMException
32 from cm.utils.threads.vm
import VMThread
33 from cm.models.vm
import VM
34 from cm.models.node
import Node
48 Node.objects.get(address=remote_ip)
50 raise CMException(
'node_not_found')
53 vm_id = int(vm_name.split(
'-')[1])
54 user_id = int(vm_name.split(
'-')[2])
56 log.debug(0,
"Unknown vm from hook: %s" % vm_name)
57 raise CMException(
'vm_not_found')
59 if action !=
"stopped":
60 log.debug(user_id,
"Not updating vm state: action is %s" % str(action))
73 vm = VM.objects.get(id=vm_id)
75 log.error(user_id,
'Cannot find vm in database!')
76 raise CMException(
'vm_not_found')
78 if not vm.state
in [vm_states[
'running ctx'], vm_states[
'running']]:
79 log.error(user_id,
'VM is not running!')
80 raise CMException(
'vm_not_running')
82 if vm.state == vm_states[
'restart']:
83 raise CMException(
'vm_restart')
85 thread = VMThread(vm,
'delete')