yapf everything, retrieve all disks and interfaces and display them, and make delete button pretty

This commit is contained in:
Jordan Rodgers 2017-11-30 19:41:55 -05:00
parent ee8e439260
commit 598d4688db
4 changed files with 86 additions and 26 deletions

39
app.py
View file

@ -5,26 +5,24 @@ import subprocess
from starrs import *
from proxmox import *
from proxmoxer import ProxmoxAPI
from flask import Flask, render_template, request, redirect
from flask import Flask, render_template, request, redirect, send_from_directory
app = Flask(__name__)
config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), "config.py")
app.config.from_pyfile(config)
app.config["GIT_REVISION"] = subprocess.check_output(['git',
'rev-parse',
'--short',
'HEAD']).decode('utf-8').rstrip()
app.config["GIT_REVISION"] = subprocess.check_output(
['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').rstrip()
user = 'proxstar'
proxmox = connect_proxmox(app.config['PROXMOX_HOST'], app.config['PROXMOX_USER'], app.config['PROXMOX_PASS'])
starrs = connect_starrs(app.config['STARRS_DB_NAME'], app.config['STARRS_DB_USER'], app.config['STARRS_DB_HOST'], app.config['STARRS_DB_PASS'])
proxmox = connect_proxmox(app.config['PROXMOX_HOST'],
app.config['PROXMOX_USER'],
app.config['PROXMOX_PASS'])
starrs = connect_starrs(
app.config['STARRS_DB_NAME'], app.config['STARRS_DB_USER'],
app.config['STARRS_DB_HOST'], app.config['STARRS_DB_PASS'])
@app.route("/")
@ -35,7 +33,8 @@ def list_vms():
vms.remove(vm)
else:
vm['config'] = get_vm_config(proxmox, vm['vmid'])
vm['disk_size'] = get_vm_disk_size(proxmox, vm['vmid'], config=vm['config'])
vm['disk_size'] = get_vm_disk_size(
proxmox, vm['vmid'], config=vm['config'])
vms = sorted(vms, key=lambda k: k['name'])
return render_template('list_vms.html', username='com6056', vms=vms)
@ -45,7 +44,9 @@ def vm_details(vmid):
vm = get_vm(proxmox, vmid)
vm['vmid'] = vmid
vm['config'] = get_vm_config(proxmox, vmid)
vm['disk_size'] = get_vm_disk_size(proxmox, vmid, config=vm['config'])
vm['disks'] = get_vm_disks(proxmox, vmid, config=vm['config'])
vm['interfaces'] = get_vm_interfaces(
proxmox, vm['vmid'], config=vm['config'])
return render_template('vm_details.html', username='com6056', vm=vm)
@ -61,7 +62,9 @@ def get_create():
memory = request.form['memory']
disk = request.form['disk']
vmid, mac = create_vm(proxmox, starrs, user, name, cores, memory, disk)
print(register_starrs(starrs, name, user, mac, get_next_ip(starrs, '49net Public Fixed')[0][0]))
print(
register_starrs(starrs, name, user, mac,
get_next_ip(starrs, '49net Public Fixed')[0][0]))
return redirect("/proxstar/vm/{}".format(vmid))
@ -70,7 +73,8 @@ def delete():
vmid = request.form['delete']
print(vmid)
vmname = get_vm_config(proxmox, vmid)['name']
return render_template('confirm_delete.html', username='com6056', vmid=vmid, vmname=vmname)
return render_template(
'confirm_delete.html', username='com6056', vmid=vmid, vmname=vmname)
@app.route("/confirm_delete", methods=['POST'])
@ -83,5 +87,10 @@ def confirm_delete():
return redirect("/proxstar")
@app.route('/novnc/<path:path>')
def send_novnc(path):
return send_from_directory('static/novnc-pve/novnc', path)
if __name__ == "__main__":
app.run()