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)
|
key = TextField(unique=True, null=False)
|
||||||
val = TextField(null=True)
|
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):
|
class Admins(PgSQLModel):
|
||||||
id = UUIDField(primary_key=True, unique=True)
|
id = UUIDField(primary_key=True, unique=True)
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
|
|
||||||
from SWSCloudCore import models
|
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()
|
print 'total vms:', models.Vms.select().count()
|
||||||
for vm in models.Vms.select():
|
for vm in models.Vms.select():
|
||||||
# Высчитываем, сколько стоит виртуальная машина 15 минут
|
# Высчитываем, сколько стоит виртуальная машина 15 минут
|
||||||
|
@ -16,11 +17,15 @@ if int(models.Settings.select().where(models.Settings.key == 'SERVICE_VMS_ENABLE
|
||||||
x = models.UsersBalance.update(
|
x = models.UsersBalance.update(
|
||||||
balance=models.UsersBalance.balance - price_quarter
|
balance=models.UsersBalance.balance - price_quarter
|
||||||
).where(
|
).where(
|
||||||
models.UsersBalance.user == vm.user.id
|
models.UsersBalance.user == vm.user.id)
|
||||||
)
|
|
||||||
x.execute()
|
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()
|
print 'total containers:', models.Containers.select().count()
|
||||||
for container in models.Containers.select():
|
for container in models.Containers.select():
|
||||||
container_state = models.ContainersStatisticsState.select().where(
|
container_state = models.ContainersStatisticsState.select().where(
|
||||||
|
|
Loading…
Add table
Reference in a new issue