44 Списание редств со счёта пользователя

This commit is contained in:
Vyacheslav Anzhiganov 2016-05-26 03:32:59 +03:00
parent 54fccafe85
commit 43514e4652

27
cloud-cron-balance.py Normal file
View 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