forked from 3wordchant/capsul-flask
started working on cron job task
This commit is contained in:
@ -91,7 +91,7 @@ def create():
|
||||
vm_sizes = get_model().vm_sizes_dict()
|
||||
operating_systems = get_model().operating_systems_dict()
|
||||
ssh_public_keys = get_model().list_ssh_public_keys_for_account(session["account"])
|
||||
account_balance = get_account_balance()
|
||||
account_balance = get_account_balance(get_vms(), get_payments(), datetime.utcnow())
|
||||
capacity_avaliable = current_app.config["VIRTUALIZATION_MODEL"].capacity_avaliable(512*1024*1024)
|
||||
errors = list()
|
||||
created_os = None
|
||||
@ -246,15 +246,15 @@ def get_payments():
|
||||
|
||||
average_number_of_days_in_a_month = 30.44
|
||||
|
||||
def get_account_balance():
|
||||
def get_account_balance(vms, payments, as_of):
|
||||
|
||||
vm_cost_dollars = 0.0
|
||||
for vm in get_vms():
|
||||
end_datetime = vm["deleted"] if vm["deleted"] else datetime.utcnow()
|
||||
for vm in vms:
|
||||
end_datetime = vm["deleted"] if vm["deleted"] else as_of
|
||||
vm_months = ( end_datetime - vm["created"] ).days / average_number_of_days_in_a_month
|
||||
vm_cost_dollars += vm_months * float(vm["dollars_per_month"])
|
||||
|
||||
payment_dollars_total = float( sum(map(lambda x: 0 if x["invalidated"] else x["dollars"], get_payments())) )
|
||||
payment_dollars_total = float( sum(map(lambda x: 0 if x["invalidated"] else x["dollars"], payments)) )
|
||||
|
||||
return payment_dollars_total - vm_cost_dollars
|
||||
|
||||
@ -262,7 +262,7 @@ def get_account_balance():
|
||||
@account_required
|
||||
def account_balance():
|
||||
payments = get_payments()
|
||||
account_balance = get_account_balance()
|
||||
account_balance = get_account_balance(get_vms(), payments, datetime.utcnow())
|
||||
|
||||
vms_billed = list()
|
||||
|
||||
|
Reference in New Issue
Block a user