Revision 452d2391 db/charger.py
b/db/charger.py | ||
---|---|---|
8 | 8 |
|
9 | 9 |
from db.models import * |
10 | 10 |
|
11 |
from datetime import datetime |
|
12 | 11 |
|
13 |
def stop_virtual_machine(vm): |
|
14 |
"""Send message to stop a virtual machine instance""" |
|
15 |
|
|
16 |
# send the message to ganeti |
|
17 |
|
|
18 |
return |
|
19 |
|
|
20 |
def charge(): |
|
12 |
def periodically_charge(): |
|
21 | 13 |
"""Scan all virtual machines and charge each user""" |
22 | 14 |
all_vms = VirtualMachine.objects.all() |
23 | 15 |
|
24 | 16 |
if len(all_vms) == 0: |
25 | 17 |
print "No virtual machines found" |
18 |
return |
|
26 | 19 |
|
27 | 20 |
for vm in all_vms: |
28 |
cost = 0 |
|
29 |
|
|
30 | 21 |
# Running and Stopped is charged, else the cost is zero |
31 |
|
|
32 |
|
|
33 |
start = vm.charged |
|
34 |
end = datetime.now() |
|
35 |
user_credits = vm.owner.charge_credits(cost, start, end) |
|
36 |
vm.charged = end |
|
37 |
|
|
38 |
# update the values in the database |
|
39 |
vm.save() |
|
40 |
vm.owner.save() |
|
41 |
|
|
42 |
if user_credits <= 0: |
|
43 |
stop_virtual_machine(vm) |
|
22 |
# FIXME: not implemented! |
|
23 |
vm.charge() |
|
44 | 24 |
|
45 | 25 |
# vim: set ts=4 sts=4 sw=4 et ai : |
Also available in: Unified diff