-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmanage.py
executable file
·48 lines (39 loc) · 1.36 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
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
import datetime
import click
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='running').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
@app.cli.command()
@click.option('--username', default=None, help='github username to add')
def make_admin(username):
'''Command to make a user as an admin of softserve'''
app.config['ADMINS'].append(username)
user = User.query.filter(username == username).first()
user.admin = True
db.session.add(user)
db.session.commit()
if __name__ == '__main__':
app.run()