27 lines
834 B
Python
27 lines
834 B
Python
#!/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
|