Revision 04a6d900 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):
12 14
    """Stop a virtual machine instance"""
15
    
16
    # send the message to ganeti
17
    
13 18
    return
14 19

  
15 20
def charge():
......
22 27
    for vm in all_vms:
23 28
        cost = 0
24 29
        
25
        # Running and Stopped is charged, else no cost
30
        # Running and Stopped is charged, else the cost is zero
26 31
        if vm.state == 'PE_VM_RUNNING':
27 32
            cost = vm.flavor.cost_active
28
        elif vm.state == 'PE_PE_VM_STOPPED':
33
        elif vm.state == 'PE_VM_STOPPED':
29 34
            cost = vm.flavor.cost_inactive
30 35
          
31
        user_credits = vm.user.charge_credits(cost)
32
        vm.user.save()
36
        user_credits = vm.owner.charge_credits(cost)        
37
        vm.charged = datetime.now()
38
        
39
        # update the values in the database
40
        vm.save()
41
        vm.owner.save()
33 42
        
34 43
        if user_credits <= 0:
35 44
            stop_virtual_machine(vm)

Also available in: Unified diff