Commit 399ca467 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Add shutdown_timeout to server commands

Add support for specifying a timeout when stopping, rebooting or
destroying a server.
parent d2c1d3ce
......@@ -683,12 +683,14 @@ def create_instance(vm, nics, flavor, image):
return client.CreateInstance(**kw)
def delete_instance(vm):
def delete_instance(vm, shutdown_timeout=None):
with pooled_rapi_client(vm) as client:
return client.DeleteInstance(vm.backend_vm_id, dry_run=settings.TEST)
return client.DeleteInstance(vm.backend_vm_id,
shutdown_timeout=shutdown_timeout,
dry_run=settings.TEST)
def reboot_instance(vm, reboot_type):
def reboot_instance(vm, reboot_type, shutdown_timeout=None):
assert reboot_type in ('soft', 'hard')
# Note that reboot type of Ganeti job must be always hard. The 'soft' and
# 'hard' type of OS API is different from the one in Ganeti, and maps to
......@@ -698,6 +700,8 @@ def reboot_instance(vm, reboot_type):
# 'shutdown_timeout' parameter is only support from snf-ganeti>=2.8.2 and
# Ganeti > 2.10. In other versions this parameter will be ignored and
# we will fallback to default timeout of Ganeti (120s).
if shutdown_timeout is not None:
kwargs["shutdown_timeout"] = shutdown_timeout
if reboot_type == "hard":
kwargs["shutdown_timeout"] = 0
if settings.TEST:
......@@ -711,9 +715,11 @@ def startup_instance(vm):
return client.StartupInstance(vm.backend_vm_id, dry_run=settings.TEST)
def shutdown_instance(vm):
def shutdown_instance(vm, shutdown_timeout=None):
with pooled_rapi_client(vm) as client:
return client.ShutdownInstance(vm.backend_vm_id, dry_run=settings.TEST)
return client.ShutdownInstance(vm.backend_vm_id,
timeout=shutdown_timeout,
dry_run=settings.TEST)
def resize_instance(vm, vcpus, memory):
......
......@@ -270,7 +270,7 @@ def create_server(vm, nics, flavor, image, personality, password):
@server_command("DESTROY")
def destroy(vm):
def destroy(vm, shutdown_timeout=None):
# XXX: Workaround for race where OP_INSTANCE_REMOVE starts executing on
# Ganeti before OP_INSTANCE_CREATE. This will be fixed when
# OP_INSTANCE_REMOVE supports the 'depends' request attribute.
......@@ -280,7 +280,7 @@ def destroy(vm):
not backend.vm_exists_in_backend(vm)):
raise faults.BuildInProgress("Server is being build")
log.info("Deleting VM %s", vm)
return backend.delete_instance(vm)
return backend.delete_instance(vm, shutdown_timeout=None)
@server_command("START")
......@@ -290,19 +290,20 @@ def start(vm):
@server_command("STOP")
def stop(vm):
def stop(vm, shutdown_timeout=None):
log.info("Stopping VM %s", vm)
return backend.shutdown_instance(vm)
return backend.shutdown_instance(vm, shutdown_timeout=None)
@server_command("REBOOT")
def reboot(vm, reboot_type):
def reboot(vm, reboot_type, shutdown_timeout=None):
if reboot_type not in ("SOFT", "HARD"):
raise faults.BadRequest("Malformed request. Invalid reboot"
" type %s" % reboot_type)
log.info("Rebooting VM %s. Type %s", vm, reboot_type)
return backend.reboot_instance(vm, reboot_type.lower())
return backend.reboot_instance(vm, reboot_type.lower(),
shutdown_timeout=shutdown_timeout)
def resize(vm, flavor):
......
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