update cloud-cron-balance & model func
This commit is contained in:
parent
76edfcec1a
commit
01fa4d0cfd
2 changed files with 15 additions and 4 deletions
|
@ -317,6 +317,12 @@ class Settings(PgSQLModel):
|
|||
key = TextField(unique=True, null=False)
|
||||
val = TextField(null=True)
|
||||
|
||||
@staticmethod
|
||||
def get_item(key):
|
||||
if Settings.select().where(Settings.key == key).count() == 0:
|
||||
return None
|
||||
return Settings.select(Settings.val).where(Settings.key == key).first().val
|
||||
|
||||
|
||||
class Admins(PgSQLModel):
|
||||
id = UUIDField(primary_key=True, unique=True)
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
|
||||
from SWSCloudCore import models
|
||||
|
||||
nb = models.Settings.get_item('NEGATIVE_BALANCE')
|
||||
|
||||
if int(models.Settings.select().where(models.Settings.key == 'SERVICE_VMS_ENABLE').get().val) == 1:
|
||||
if int(models.Settings.get_item('SERVICE_VMS_ENABLE')) == 1:
|
||||
print 'total vms:', models.Vms.select().count()
|
||||
for vm in models.Vms.select():
|
||||
# Высчитываем, сколько стоит виртуальная машина 15 минут
|
||||
|
@ -16,11 +17,15 @@ if int(models.Settings.select().where(models.Settings.key == 'SERVICE_VMS_ENABLE
|
|||
x = models.UsersBalance.update(
|
||||
balance=models.UsersBalance.balance - price_quarter
|
||||
).where(
|
||||
models.UsersBalance.user == vm.user.id
|
||||
)
|
||||
models.UsersBalance.user == vm.user.id)
|
||||
x.execute()
|
||||
|
||||
if int(models.Settings.select().where(models.Settings.key == 'SERVICE_CONTAINERS_ENABLE').get().val) == 1:
|
||||
# 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:
|
||||
print 'total containers:', models.Containers.select().count()
|
||||
for container in models.Containers.select():
|
||||
container_state = models.ContainersStatisticsState.select().where(
|
||||
|
|
Loading…
Add table
Reference in a new issue