mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
actually fail to other proxmox nodes, yapf everything
This commit is contained in:
parent
7aadd423e7
commit
227060dd77
3 changed files with 37 additions and 24 deletions
|
@ -96,10 +96,7 @@ def list_vms(user_view=None):
|
||||||
else:
|
else:
|
||||||
vms = 'INACTIVE'
|
vms = 'INACTIVE'
|
||||||
return render_template(
|
return render_template(
|
||||||
'list_vms.html',
|
'list_vms.html', user=user, rtp_view=rtp_view, vms=vms)
|
||||||
user=user,
|
|
||||||
rtp_view=rtp_view,
|
|
||||||
vms=vms)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/isos")
|
@app.route("/isos")
|
||||||
|
@ -127,7 +124,8 @@ def hostname(name):
|
||||||
def vm_details(vmid):
|
def vm_details(vmid):
|
||||||
user = build_user_dict(session, db)
|
user = build_user_dict(session, db)
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if user['rtp'] or int(vmid) in get_user_allowed_vms(proxmox, db, user['username']):
|
if user['rtp'] or int(vmid) in get_user_allowed_vms(
|
||||||
|
proxmox, db, user['username']):
|
||||||
vm = get_vm(proxmox, vmid)
|
vm = get_vm(proxmox, vmid)
|
||||||
vm['vmid'] = vmid
|
vm['vmid'] = vmid
|
||||||
vm['config'] = get_vm_config(proxmox, vmid)
|
vm['config'] = get_vm_config(proxmox, vmid)
|
||||||
|
@ -163,11 +161,13 @@ def vm_details(vmid):
|
||||||
def vm_power(vmid, action):
|
def vm_power(vmid, action):
|
||||||
user = build_user_dict(session, db)
|
user = build_user_dict(session, db)
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if user['rtp'] or int(vmid) in get_user_allowed_vms(proxmox, db, user['username']):
|
if user['rtp'] or int(vmid) in get_user_allowed_vms(
|
||||||
|
proxmox, db, user['username']):
|
||||||
if action == 'start':
|
if action == 'start':
|
||||||
config = get_vm_config(proxmox, vmid)
|
config = get_vm_config(proxmox, vmid)
|
||||||
usage_check = check_user_usage(proxmox, db, user['username'], config['cores'],
|
usage_check = check_user_usage(proxmox, db, user['username'],
|
||||||
config['memory'], 0)
|
config['cores'], config['memory'],
|
||||||
|
0)
|
||||||
if usage_check:
|
if usage_check:
|
||||||
return usage_check
|
return usage_check
|
||||||
change_vm_power(proxmox, vmid, action)
|
change_vm_power(proxmox, vmid, action)
|
||||||
|
@ -181,7 +181,8 @@ def vm_power(vmid, action):
|
||||||
def vm_console(vmid):
|
def vm_console(vmid):
|
||||||
user = build_user_dict(session, db)
|
user = build_user_dict(session, db)
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if user['rtp'] or int(vmid) in get_user_allowed_vms(proxmox, db, user['username']):
|
if user['rtp'] or int(vmid) in get_user_allowed_vms(
|
||||||
|
proxmox, db, user['username']):
|
||||||
port = str(5900 + int(vmid))
|
port = str(5900 + int(vmid))
|
||||||
token = add_vnc_target(port)
|
token = add_vnc_target(port)
|
||||||
node = "{}.csh.rit.edu".format(get_vm_node(proxmox, vmid))
|
node = "{}.csh.rit.edu".format(get_vm_node(proxmox, vmid))
|
||||||
|
@ -202,7 +203,8 @@ def vm_console(vmid):
|
||||||
def vm_cpu(vmid, cores):
|
def vm_cpu(vmid, cores):
|
||||||
user = build_user_dict(session, db)
|
user = build_user_dict(session, db)
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if user['rtp'] or int(vmid) in get_user_allowed_vms(proxmox, db, user['username']):
|
if user['rtp'] or int(vmid) in get_user_allowed_vms(
|
||||||
|
proxmox, db, user['username']):
|
||||||
cur_cores = get_vm_config(proxmox, vmid)['cores']
|
cur_cores = get_vm_config(proxmox, vmid)['cores']
|
||||||
if cores >= cur_cores:
|
if cores >= cur_cores:
|
||||||
status = get_vm(proxmox, vmid)['qmpstatus']
|
status = get_vm(proxmox, vmid)['qmpstatus']
|
||||||
|
@ -210,7 +212,8 @@ def vm_cpu(vmid, cores):
|
||||||
usage_check = check_user_usage(proxmox, db, user['username'],
|
usage_check = check_user_usage(proxmox, db, user['username'],
|
||||||
cores - cur_cores, 0, 0)
|
cores - cur_cores, 0, 0)
|
||||||
else:
|
else:
|
||||||
usage_check = check_user_usage(proxmox, db, user['username'], cores, 0, 0)
|
usage_check = check_user_usage(proxmox, db, user['username'],
|
||||||
|
cores, 0, 0)
|
||||||
if usage_check:
|
if usage_check:
|
||||||
return usage_check
|
return usage_check
|
||||||
change_vm_cpu(proxmox, vmid, cores)
|
change_vm_cpu(proxmox, vmid, cores)
|
||||||
|
@ -224,15 +227,17 @@ def vm_cpu(vmid, cores):
|
||||||
def vm_mem(vmid, mem):
|
def vm_mem(vmid, mem):
|
||||||
user = build_user_dict(session, db)
|
user = build_user_dict(session, db)
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if user['rtp'] or int(vmid) in get_user_allowed_vms(proxmox, db, user['username']):
|
if user['rtp'] or int(vmid) in get_user_allowed_vms(
|
||||||
|
proxmox, db, user['username']):
|
||||||
cur_mem = get_vm_config(proxmox, vmid)['memory'] // 1024
|
cur_mem = get_vm_config(proxmox, vmid)['memory'] // 1024
|
||||||
if mem >= cur_mem:
|
if mem >= cur_mem:
|
||||||
status = get_vm(proxmox, vmid)['qmpstatus']
|
status = get_vm(proxmox, vmid)['qmpstatus']
|
||||||
if status == 'running' or status == 'paused':
|
if status == 'running' or status == 'paused':
|
||||||
usage_check = check_user_usage(proxmox, db, user['username'], 0,
|
usage_check = check_user_usage(proxmox, db, user['username'],
|
||||||
mem - cur_mem, 0)
|
0, mem - cur_mem, 0)
|
||||||
else:
|
else:
|
||||||
usage_check = check_user_usage(proxmox, db, user['username'], 0, mem, 0)
|
usage_check = check_user_usage(proxmox, db, user['username'],
|
||||||
|
0, mem, 0)
|
||||||
if usage_check:
|
if usage_check:
|
||||||
return usage_check
|
return usage_check
|
||||||
change_vm_mem(proxmox, vmid, mem * 1024)
|
change_vm_mem(proxmox, vmid, mem * 1024)
|
||||||
|
@ -246,7 +251,8 @@ def vm_mem(vmid, mem):
|
||||||
def vm_renew(vmid):
|
def vm_renew(vmid):
|
||||||
user = build_user_dict(session, db)
|
user = build_user_dict(session, db)
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if user['rtp'] or int(vmid) in get_user_allowed_vms(proxmox, db, user['username']):
|
if user['rtp'] or int(vmid) in get_user_allowed_vms(
|
||||||
|
proxmox, db, user['username']):
|
||||||
renew_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS'])
|
renew_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS'])
|
||||||
for interface in get_vm_interfaces(proxmox, vmid):
|
for interface in get_vm_interfaces(proxmox, vmid):
|
||||||
renew_ip(starrs, get_ip_for_mac(starrs, interface[1]))
|
renew_ip(starrs, get_ip_for_mac(starrs, interface[1]))
|
||||||
|
@ -272,7 +278,8 @@ def iso_eject(vmid):
|
||||||
def iso_mount(vmid, iso):
|
def iso_mount(vmid, iso):
|
||||||
user = build_user_dict(session, db)
|
user = build_user_dict(session, db)
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if user['rtp'] or int(vmid) in get_user_allowed_vms(proxmox, db, user['username']):
|
if user['rtp'] or int(vmid) in get_user_allowed_vms(
|
||||||
|
proxmox, db, user['username']):
|
||||||
iso = "{}:iso/{}".format(app.config['PROXMOX_ISO_STORAGE'], iso)
|
iso = "{}:iso/{}".format(app.config['PROXMOX_ISO_STORAGE'], iso)
|
||||||
mount_vm_iso(proxmox, vmid, iso)
|
mount_vm_iso(proxmox, vmid, iso)
|
||||||
return '', 200
|
return '', 200
|
||||||
|
@ -286,7 +293,8 @@ def delete(vmid):
|
||||||
user = build_user_dict(session, db)
|
user = build_user_dict(session, db)
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if user['rtp'] or int(vmid) in get_user_allowed_vms(
|
if user['rtp'] or int(vmid) in get_user_allowed_vms(
|
||||||
proxmox, db, user['username']) or 'rtp' in session['userinfo']['groups']:
|
proxmox, db,
|
||||||
|
user['username']) or 'rtp' in session['userinfo']['groups']:
|
||||||
q.enqueue(delete_vm_task, vmid)
|
q.enqueue(delete_vm_task, vmid)
|
||||||
return '', 200
|
return '', 200
|
||||||
else:
|
else:
|
||||||
|
@ -302,7 +310,8 @@ def create():
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
usage = get_user_usage(proxmox, db, user['username'])
|
usage = get_user_usage(proxmox, db, user['username'])
|
||||||
limits = get_user_usage_limits(db, user['username'])
|
limits = get_user_usage_limits(db, user['username'])
|
||||||
percents = get_user_usage_percent(proxmox, user['username'], usage, limits)
|
percents = get_user_usage_percent(proxmox, user['username'], usage,
|
||||||
|
limits)
|
||||||
isos = get_isos(proxmox, app.config['PROXMOX_ISO_STORAGE'])
|
isos = get_isos(proxmox, app.config['PROXMOX_ISO_STORAGE'])
|
||||||
pools = get_pools(proxmox, db)
|
pools = get_pools(proxmox, db)
|
||||||
templates = get_templates(db)
|
templates = get_templates(db)
|
||||||
|
@ -326,7 +335,8 @@ def create():
|
||||||
iso = "{}:iso/{}".format(app.config['PROXMOX_ISO_STORAGE'],
|
iso = "{}:iso/{}".format(app.config['PROXMOX_ISO_STORAGE'],
|
||||||
iso)
|
iso)
|
||||||
if not user['rtp']:
|
if not user['rtp']:
|
||||||
usage_check = check_user_usage(proxmox, db, user['username'], 0, 0, disk)
|
usage_check = check_user_usage(proxmox, db, user['username'],
|
||||||
|
0, 0, disk)
|
||||||
else:
|
else:
|
||||||
usage_check = None
|
usage_check = None
|
||||||
user['username'] = request.form['user']
|
user['username'] = request.form['user']
|
||||||
|
|
|
@ -15,9 +15,10 @@ def connect_proxmox():
|
||||||
version = proxmox.version.get()
|
version = proxmox.version.get()
|
||||||
return proxmox
|
return proxmox
|
||||||
except:
|
except:
|
||||||
pass
|
if app.config['PROXMOX_HOSTS'].index(host) == (
|
||||||
print("Unable to connect to Proxmox!")
|
len(app.config['PROXMOX_HOSTS']) - 1):
|
||||||
raise
|
print('Unable to connect to any of the given Proxmox servers!')
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
def create_user(proxmox, user):
|
def create_user(proxmox, user):
|
||||||
|
|
|
@ -14,6 +14,8 @@ def gen_password(
|
||||||
def build_user_dict(session, db):
|
def build_user_dict(session, db):
|
||||||
user_dict = dict()
|
user_dict = dict()
|
||||||
user_dict['username'] = session['userinfo']['preferred_username']
|
user_dict['username'] = session['userinfo']['preferred_username']
|
||||||
user_dict['active'] = 'active' in session['userinfo']['groups'] or user_dict['username'] in get_allowed_users(db)
|
user_dict[
|
||||||
|
'active'] = 'active' in session['userinfo']['groups'] or user_dict['username'] in get_allowed_users(
|
||||||
|
db)
|
||||||
user_dict['rtp'] = 'rtp' in session['userinfo']['groups']
|
user_dict['rtp'] = 'rtp' in session['userinfo']['groups']
|
||||||
return user_dict
|
return user_dict
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue