diff --git a/.gitmodules b/.gitmodules index b86de93..1d1e71e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "static/css/csh-material-bootstrap"] path = static/css/csh-material-bootstrap url = https://github.com/ComputerScienceHouse/csh-material-bootstrap/ +[submodule "static/noVNC"] + path = static/noVNC + url = https://github.com/novnc/noVNC diff --git a/app.py b/app.py index ce21429..c7986d0 100644 --- a/app.py +++ b/app.py @@ -5,7 +5,7 @@ import subprocess from starrs import * from proxmox import * from proxmoxer import ProxmoxAPI -from flask import Flask, render_template, request +from flask import Flask, render_template, request, redirect app = Flask(__name__) @@ -28,13 +28,25 @@ starrs = connect_starrs(app.config['STARRS_DB_NAME'], app.config['STARRS_DB_USER @app.route("/") -def get_vms(): +def list_vms(): vms = get_vms_for_user(proxmox, user) for vm in vms: - vm['config'] = get_vm_config(proxmox, vm['vmid']) - vm['disk_size'] = get_vm_disk_size(proxmox, vm['vmid'], config=vm['config']) - print(vm) - return render_template('get_vms.html', username='com6056', vms=vms) + if 'name' not in vm: + 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']) + vms = sorted(vms, key=lambda k: k['name']) + return render_template('list_vms.html', username='com6056', vms=vms) + + +@app.route("/vm/") +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']) + return render_template('vm_details.html', username='com6056', vm=vm) @app.route("/create") @@ -48,16 +60,15 @@ def get_create(): cores = request.form['cores'] memory = request.form['memory'] disk = request.form['disk'] - print(name, cores, memory, 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(vmid) - return vmid + return redirect("/proxstar/vm/{}".format(vmid)) @app.route("/delete", methods=['POST']) 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) @@ -68,7 +79,8 @@ def confirm_delete(): vmname = get_vm_config(proxmox, vmid)['name'] delete_vm(proxmox, starrs, vmid) print(delete_starrs(starrs, vmname)) - return 'SUCCESS' + time.sleep(3) + return redirect("/proxstar") if __name__ == "__main__": diff --git a/proxmox.py b/proxmox.py index d683459..7820716 100644 --- a/proxmox.py +++ b/proxmox.py @@ -31,6 +31,11 @@ def get_vm_node(proxmox, vmid): return vm['node'] +def get_vm(proxmox, vmid): + node = proxmox.nodes(get_vm_node(proxmox, vmid)) + return node.qemu(vmid).status.current.get() + + def get_vm_config(proxmox, vmid): node = proxmox.nodes(get_vm_node(proxmox, vmid)) return node.qemu(vmid).config.get() diff --git a/static/css/styles.css b/static/css/styles.css index a01890e..a0d6887 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -1,6 +1,46 @@ body { - margin-top: 60px; + padding-top: 100px; } + +footer { + text-align: center; + margin: 20px 0; +} + table, th, td { border: 1px solid black; } + +.panel { + text-align: center; +} + +.panel-body { + padding: 25px 15px 15px 15px; +} + +.panel p { + line-height: 1.4; + margin: 5px 0 0 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.panel p a { + font-weight: 500; +} + +.form-control { + width: 100%; +} + +.dl-horizontal dt { + float: left; + width: 160px; + text-align: right; +} + +.dl-horizontal dd { + margin-left: 180px; +} diff --git a/static/noVNC b/static/noVNC new file mode 160000 index 0000000..7f39868 --- /dev/null +++ b/static/noVNC @@ -0,0 +1 @@ +Subproject commit 7f3986815879421432ba6f4ea4b16c15925daccd diff --git a/templates/base.html b/templates/base.html index db5a36f..6797f74 100644 --- a/templates/base.html +++ b/templates/base.html @@ -35,7 +35,7 @@
  • - + Create VM
  • diff --git a/templates/create.html b/templates/create.html index 946f465..acdbe51 100644 --- a/templates/create.html +++ b/templates/create.html @@ -1,24 +1,55 @@ {% extends "base.html" %} {% block body %} -
    - - - - - - - - - -
    +
    +
    +
    +
    +
    +

    Create VM

    +
    +
    +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    + +
    +
    +
    +
    +
    +
    +
    +

    Help

    +
    +
    +

    Some help text.

    +
    +
    +
    +
    +
    {% endblock %} diff --git a/templates/get_vms.html b/templates/get_vms.html deleted file mode 100644 index 8c4d35e..0000000 --- a/templates/get_vms.html +++ /dev/null @@ -1,32 +0,0 @@ -{% extends "base.html" %} -{% block body %} - - - - - - - - - - -{% for vm in vms %} - - - - - - - - -{% endfor %} -
    Name Status Cores Memory Disk Size Delete
    {{ vm['name'] }} {{ vm['status'] }} {{ vm['config']['cores'] * vm['config'].get(sockets, 1) }} {{ vm['config']['memory'] }} MB {{ vm['disk_size'] }} -
    - -
    -
    - -
    - -{{ vms }} -{% endblock %} diff --git a/templates/list_vms.html b/templates/list_vms.html new file mode 100644 index 0000000..2483c3c --- /dev/null +++ b/templates/list_vms.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} +{% block body %} + +
    +
    + {% for vm in vms %} +
    +
    +
    + +

    {{ vm['name'] }}

    +
    +

    Status: {{ vm['status'] }}

    +
    +
    +
    + {% endfor %} +
    +
    + +{% endblock %} diff --git a/templates/vm_details.html b/templates/vm_details.html new file mode 100644 index 0000000..435fe7a --- /dev/null +++ b/templates/vm_details.html @@ -0,0 +1,56 @@ +{% extends "base.html" %} +{% block body %} + +
    +
    +
    +
    +
    +

    Actions

    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    +

    Resources

    +
    +
    + +
    +
    +
    +
    +
    +
    +

    VM Details

    +
    +
    +
    +
    Name
    +
    {{ vm['name'] }}
    +
    ID
    +
    {{ vm['vmid'] }}
    +
    Status
    +
    {{ vm['status'] }}
    +
    Cores
    +
    {{ vm['config']['cores'] * vm['config'].get(sockets, 1) }}
    +
    Memory
    +
    {{ vm['config']['memory'] }} MB
    +
    +
    +
    +
    +
    +
    + +{% endblock %}