2016-05-26 03:32:59 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# coding: utf-8
|
|
|
|
|
|
|
|
from SWSCloudCore import models
|
|
|
|
|
2016-10-27 10:47:16 +03:00
|
|
|
nb = models.Settings.get_item('NEGATIVE_BALANCE')
|
2016-05-26 03:32:59 +03:00
|
|
|
|
2016-10-27 10:47:16 +03:00
|
|
|
if int(models.Settings.get_item('SERVICE_VMS_ENABLE')) == 1:
|
2016-05-26 04:04:04 +03:00
|
|
|
print 'total vms:', models.Vms.select().count()
|
|
|
|
for vm in models.Vms.select():
|
|
|
|
# Высчитываем, сколько стоит виртуальная машина 15 минут
|
|
|
|
price_quarter = vm.plan.price / 30 / 24 / 4
|
2016-05-26 03:32:59 +03:00
|
|
|
|
2016-05-26 04:04:04 +03:00
|
|
|
print dict(id=vm.id, user=vm.user.id, plan=vm.plan.id, cost_mo=vm.plan.price, cost_quarter=price_quarter)
|
2016-05-26 03:32:59 +03:00
|
|
|
|
2016-05-26 04:04:04 +03:00
|
|
|
# Списание средств
|
|
|
|
x = models.UsersBalance.update(
|
|
|
|
balance=models.UsersBalance.balance - price_quarter
|
|
|
|
).where(
|
2016-10-27 10:47:16 +03:00
|
|
|
models.UsersBalance.user == vm.user.id)
|
2016-05-26 04:04:04 +03:00
|
|
|
x.execute()
|
2016-05-26 03:32:59 +03:00
|
|
|
|
2016-10-27 10:47:16 +03:00
|
|
|
# Shutting down all VMs by users who doesn't have money
|
|
|
|
if nb < 500:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
if int(models.Settings.get_item('SERVICE_CONTAINERS_ENABLE')) == 1:
|
2016-05-26 04:04:04 +03:00
|
|
|
print 'total containers:', models.Containers.select().count()
|
|
|
|
for container in models.Containers.select():
|
|
|
|
container_state = models.ContainersStatisticsState.select().where(
|
|
|
|
models.ContainersStatisticsState.container == container.id
|
|
|
|
).get()
|
2016-05-27 08:59:42 +03:00
|
|
|
min_price = 100 #+ (container_state.size * )
|
2016-05-26 03:32:59 +03:00
|
|
|
|
2016-05-26 04:04:04 +03:00
|
|
|
# # Высчитываем, сколько стоит виртуальная машина 15 минут
|
2016-05-27 08:59:42 +03:00
|
|
|
price_quarter = min_price / 30 / 24 / 4
|
2016-05-26 04:04:04 +03:00
|
|
|
#
|
|
|
|
# print dict(id=vm.id, user=vm.user.id, plan=vm.plan.id, cost_mo=vm.plan.price, cost_quarter=price_quarter)
|
|
|
|
#
|
2016-05-27 08:59:42 +03:00
|
|
|
# Списание средств
|
|
|
|
x = models.UsersBalance.update(
|
|
|
|
balance=models.UsersBalance.balance - price_quarter
|
|
|
|
).where(
|
|
|
|
models.UsersBalance.user == container.user.id
|
|
|
|
)
|
|
|
|
x.execute()
|
2016-05-26 04:04:04 +03:00
|
|
|
# Post operations
|
|
|
|
# Check user balance
|
|
|
|
# If user balance less that allowable limit
|
|
|
|
# then power off all virtual machines and containers
|