Commit f3b29b98 authored by Vangelis Koukis's avatar Vangelis Koukis
Browse files

Improve handling of server deletions

Improve handling of server deletions.
 * Have the API return a server's state as DELETED when
   the deleted flag has been set in the VirtualMachine model.
   This makes the server immediately invisible, instead of waiting
   for an indefinite amount of time for the Ganeti backend to remove
   the VM.
 * Set the deleted flag in the VirtualMachine model when Ganeti reports
   successful removal of an instance. This catches instance deletions
   initiated by the admin at the Ganeti backend.
parent 071bc070
......@@ -27,7 +27,11 @@ def process_backend_msg(vm, jobid, opcode, status, logmsg):
# Notifications of success change the operating state
if status == 'success':
utils.update_state(vm, VirtualMachine.OPER_STATE_FROM_OPCODE[opcode])
# Special cases OP_INSTANCE_CREATE fails --> ERROR
# Set the deleted flag explicitly, to cater for admin-initiated removals
if opcode == 'OP_INSTANCE_REMOVE':
vm.deleted = True
# Special case: if OP_INSTANCE_CREATE fails --> ERROR
if status in ('canceled', 'error') and opcode == 'OP_INSTANCE_CREATE':
utils.update_state(vm, 'ERROR')
# Any other notification of failure leaves the operating state unchanged
......
......@@ -32,6 +32,9 @@ def get_rsapi_state(vm):
r = VirtualMachine.RSAPI_STATE_FROM_OPER_STATE[vm.operstate]
except KeyError:
return "UNKNOWN"
# A machine is DELETED if the deleted flag has been set
if vm.deleted:
return "DELETED"
# A machine is in REBOOT if an OP_INSTANCE_REBOOT request is in progress
if r == 'ACTIVE' and vm.backendopcode == 'OP_INSTANCE_REBOOT' and \
vm.backendjobstatus in ('queued', 'waiting', 'running'):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment