44 Списание редств со счёта пользователя
This commit is contained in:
parent
54fccafe85
commit
43514e4652
1 changed files with 27 additions and 0 deletions
27
cloud-cron-balance.py
Normal file
27
cloud-cron-balance.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from SWSCloudCore import models
|
||||
|
||||
|
||||
print 'total vms:', models.Vms.select().count()
|
||||
for vm in models.Vms.select():
|
||||
# Высчитываем, сколько стоит виртуальная машина 15 минут
|
||||
price_quarter = vm.plan.price / 30 / 24 / 4
|
||||
|
||||
print dict(id=vm.id, user=vm.user.id, plan=vm.plan.id, cost_mo=vm.plan.price, cost_quarter=price_quarter)
|
||||
|
||||
# Списание средств
|
||||
x = models.UsersBalance.update(
|
||||
balance=models.UsersBalance.balance - price_quarter
|
||||
).where(
|
||||
models.UsersBalance.user == vm.user.id
|
||||
)
|
||||
x.execute()
|
||||
|
||||
print 'total containers:', models.Containers.select().count()
|
||||
|
||||
# Post operations
|
||||
# Check user balance
|
||||
# If user balance less that allowable limit
|
||||
# then power off all virtual machines and containers
|
Loading…
Add table
Reference in a new issue