Revision 578b725c
b/db/Charger.py | ||
---|---|---|
3 | 3 |
# |
4 | 4 |
# Executed hourly to charge vm usage for each user |
5 | 5 |
# |
6 |
# Copyright © 2010 Greek Research and Technology Network
|
|
6 |
# Copyright 2010 Greek Research and Technology Network |
|
7 | 7 |
# |
8 | 8 |
|
9 | 9 |
from db.models import * |
10 | 10 |
|
11 |
def charger(): |
|
11 |
import vocabs |
|
12 |
|
|
13 |
def stopVirtualMachine(vm): |
|
14 |
"""This method send message to ganeti in order to suspend a virtual machine""" |
|
12 | 15 |
return |
16 |
|
|
17 |
def charge(): |
|
18 |
"""This method scans all the virtual machines and charge each user""" |
|
19 |
all_vms = VirtualMachine.objects.all() |
|
20 |
|
|
21 |
if len(all_vms) == 0: |
|
22 |
print "No virtual machines found" |
|
13 | 23 |
|
14 |
charger() |
|
24 |
for vm in all_vms: |
|
25 |
cost = 0 |
|
26 |
|
|
27 |
# Running and Stopped is charged, else no cost |
|
28 |
if vm.state == 'PE_VM_RUNNING': |
|
29 |
cost = vm.flavor.cost_active |
|
30 |
elif vm.state == 'PE_PE_VM_STOPPED': |
|
31 |
cost = vm.flavor.cost_inactive |
|
32 |
|
|
33 |
user_credits = vm.user.chargeCredits(cost) |
|
34 |
|
|
35 |
if user_credits <= 0: |
|
36 |
stopVirtualMachine(vm) |
Also available in: Unified diff