Commit 390cf69b authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

cyclades: Set shutdown timeout when enforcing quota

Provide option `--shutdown-timeout' in management command to force a VM
parent 15f5c03e
......@@ -1304,6 +1304,10 @@ of operations per backend. For example,
will apply only the first 10 listed actions per backend. One can repeat the
operation, until nothing is left to be done.
To control load a timeout can also be set for shutting down VMs (using
option ``--shutdown-timeout <sec>``). This may be needed to avoid
expensive operations triggered by shutdown, such as Windows updates.
Cyclades advanced operations
......@@ -187,10 +187,10 @@ VM_ACTION = {
def apply_to_vm(action, vm_id):
def apply_to_vm(action, vm_id, shutdown_timeout):
vm = VirtualMachine.objects.select_for_update().get(id=vm_id)
VM_ACTION[action](vm, shutdown_timeout=shutdown_timeout)
return True
except BaseException:
return False
......@@ -206,14 +206,14 @@ def allow_operation(backend_id, opcount, maxops):
return True
def perform_vm_actions(actions, opcount, maxops=None, fix=False):
def perform_vm_actions(actions, opcount, maxops=None, fix=False, options={}):
log = []
for vm_id, (viol_id, state, backend_id, vm_action) in actions.iteritems():
if not allow_operation(backend_id, opcount, maxops):
data = ("vm", vm_id, state, backend_id, vm_action, viol_id)
if fix:
r = apply_to_vm(vm_action, vm_id)
r = apply_to_vm(vm_action, vm_id, options.get("shutdown_timeout"))
data += ("DONE" if r else "FAILED",)
return log
......@@ -247,7 +247,8 @@ def remove_ip(ip_id):
return False
def perform_floating_ip_actions(actions, opcount, maxops=None, fix=False):
def perform_floating_ip_actions(actions, opcount, maxops=None, fix=False,
log = []
for ip_id, (viol_id, state, backend_id, ip_action) in actions.iteritems():
if not allow_operation(backend_id, opcount, maxops):
......@@ -261,7 +262,7 @@ def perform_floating_ip_actions(actions, opcount, maxops=None, fix=False):
return log
def perform_actions(actions, maxops=None, fix=False):
def perform_actions(actions, maxops=None, fix=False, options={}):
("floating_ip", perform_floating_ip_actions),
("vm", perform_vm_actions),
......@@ -271,7 +272,8 @@ def perform_actions(actions, maxops=None, fix=False):
logs = []
for resource_type, handler in ACTION_HANDLING:
t_actions = actions.get(resource_type, {})
log = handler(t_actions, opcount, maxops=maxops, fix=fix)
log = handler(t_actions, opcount, maxops=maxops, fix=fix,
logs += log
return logs
......@@ -72,6 +72,8 @@ class Command(SynnefoCommand):
help=("Confirm actions that may permanently "
"remove a vm")),
help="Force vm shutdown after given seconds."),
def confirm(self):
......@@ -113,6 +115,14 @@ class Command(SynnefoCommand):
m = "Expected integer max operations."
raise CommandError(m)
shutdown_timeout = options["shutdown_timeout"]
if shutdown_timeout is not None:
shutdown_timeout = int(shutdown_timeout)
except ValueError:
m = "Expected integer shutdown timeout."
raise CommandError(m)
users = options['users']
if users is not None:
users = users.split(',')
......@@ -130,6 +140,7 @@ class Command(SynnefoCommand):
resources = set(h[0] for h in handlers)
dangerous = bool(resources.difference(DEFAULT_RESOURCES))
opts = {"shutdown_timeout": shutdown_timeout}
actions = {}
overlimit = []
viol_id = 0
......@@ -181,7 +192,8 @@ class Command(SynnefoCommand):
write("Applying actions. Please wait...\n")
title = "Applied Actions" if fix else "Suggested Actions"
log = enforce.perform_actions(actions, maxops=maxops, fix=fix)
log = enforce.perform_actions(actions, maxops=maxops, fix=fix,
headers = ("Type", "ID", "State", "Backend", "Action", "Violation")
if fix:
headers += ("Result",)
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