forked from gluster/softserve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
executable file
·36 lines (29 loc) · 1 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
import datetime
from softserve import app, db
from softserve.model import User, NodeRequest, Vm
from softserve.lib import delete_node
@app.shell_context_processor
def make_shell_context():
return dict(db=db, User=User, NodeRequest=NodeRequest, Vm=Vm)
@app.cli.command()
def shutdown_check():
'''Command to shut down the VM when exceeding the time limit'''
vms = Vm.query.filter_by(state='ACTIVE').all()
if vms == []:
pass
else:
for vm in vms:
start_time = vm.created_at
current_time = datetime.datetime.now()
diff = current_time-start_time
overall_seconds = diff.total_seconds()
overall_hours = (overall_seconds) / 3600
node = NodeRequest.query.filter(vm.details_id == NodeRequest.id) \
.join(Vm).first()
if overall_hours >= node.hours:
delete_node.delay(vm.vm_name)
else:
pass
if __name__ == '__main__':
app.run()