Revision 29e3919d snf-cyclades-app/synnefo/quotas/enforce.py
b/snf-cyclades-app/synnefo/quotas/enforce.py | ||
---|---|---|
187 | 187 |
} |
188 | 188 |
|
189 | 189 |
|
190 |
def apply_to_vm(action, vm_id): |
|
190 |
def apply_to_vm(action, vm_id, shutdown_timeout):
|
|
191 | 191 |
try: |
192 | 192 |
vm = VirtualMachine.objects.select_for_update().get(id=vm_id) |
193 |
VM_ACTION[action](vm) |
|
193 |
VM_ACTION[action](vm, shutdown_timeout=shutdown_timeout)
|
|
194 | 194 |
return True |
195 | 195 |
except BaseException: |
196 | 196 |
return False |
... | ... | |
206 | 206 |
return True |
207 | 207 |
|
208 | 208 |
|
209 |
def perform_vm_actions(actions, opcount, maxops=None, fix=False): |
|
209 |
def perform_vm_actions(actions, opcount, maxops=None, fix=False, options={}):
|
|
210 | 210 |
log = [] |
211 | 211 |
for vm_id, (viol_id, state, backend_id, vm_action) in actions.iteritems(): |
212 | 212 |
if not allow_operation(backend_id, opcount, maxops): |
213 | 213 |
continue |
214 | 214 |
data = ("vm", vm_id, state, backend_id, vm_action, viol_id) |
215 | 215 |
if fix: |
216 |
r = apply_to_vm(vm_action, vm_id) |
|
216 |
r = apply_to_vm(vm_action, vm_id, options.get("shutdown_timeout"))
|
|
217 | 217 |
data += ("DONE" if r else "FAILED",) |
218 | 218 |
log.append(data) |
219 | 219 |
return log |
... | ... | |
247 | 247 |
return False |
248 | 248 |
|
249 | 249 |
|
250 |
def perform_floating_ip_actions(actions, opcount, maxops=None, fix=False): |
|
250 |
def perform_floating_ip_actions(actions, opcount, maxops=None, fix=False, |
|
251 |
options={}): |
|
251 | 252 |
log = [] |
252 | 253 |
for ip_id, (viol_id, state, backend_id, ip_action) in actions.iteritems(): |
253 | 254 |
if not allow_operation(backend_id, opcount, maxops): |
... | ... | |
261 | 262 |
return log |
262 | 263 |
|
263 | 264 |
|
264 |
def perform_actions(actions, maxops=None, fix=False): |
|
265 |
def perform_actions(actions, maxops=None, fix=False, options={}):
|
|
265 | 266 |
ACTION_HANDLING = [ |
266 | 267 |
("floating_ip", perform_floating_ip_actions), |
267 | 268 |
("vm", perform_vm_actions), |
... | ... | |
271 | 272 |
logs = [] |
272 | 273 |
for resource_type, handler in ACTION_HANDLING: |
273 | 274 |
t_actions = actions.get(resource_type, {}) |
274 |
log = handler(t_actions, opcount, maxops=maxops, fix=fix) |
|
275 |
log = handler(t_actions, opcount, maxops=maxops, fix=fix, |
|
276 |
options=options) |
|
275 | 277 |
logs += log |
276 | 278 |
return logs |
277 | 279 |
|
Also available in: Unified diff