diff --git a/app.py b/app.py index 640ac4d..157ae00 100644 --- a/app.py +++ b/app.py @@ -16,13 +16,9 @@ config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), "config.py") app.config.from_pyfile(config) -user = 'ram' +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']) -#print(get_vms_for_user(user)) -#vmid = create_vm(proxmox, starrs, user, name) -#time.sleep(10) -#delete_vm(proxmox, starrs, vmid, name) @app.route("/") @@ -31,6 +27,7 @@ def get_vms(): 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', vms=vms) @@ -46,9 +43,26 @@ def get_create(): memory = request.form['memory'] disk = request.form['disk'] print(name, cores, memory, disk) - vmid = create_vm(proxmox, starrs, user, 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 vmid + + +@app.route("/delete", methods=['POST']) +def delete(): + vmid = request.form['delete'] + vmname = get_vm_config(proxmox, vmid)['name'] + return render_template('confirm_delete.html', vmid=vmid, vmname=vmname) + + +@app.route("/confirm_delete", methods=['POST']) +def confirm_delete(): + vmid = request.form['delete'] + vmname = get_vm_config(proxmox, vmid)['name'] + delete_vm(proxmox, starrs, vmid) + print(delete_starrs(starrs, vmname)) + return 'SUCCESS' if __name__ == "__main__": diff --git a/proxmox.py b/proxmox.py index 43e21b0..d683459 100644 --- a/proxmox.py +++ b/proxmox.py @@ -64,12 +64,10 @@ def create_vm(proxmox, starrs, user, name, cores, memory, disk): node.qemu.create(vmid=vmid, name=name, cores=cores, memory=memory, storage='ceph', virtio0='ceph:10', net0='virtio,bridge=vmbr0', pool=user) time.sleep(3) mac = get_vm_mac(proxmox, vmid) - register_starrs(starrs, name, user, mac, get_next_ip(starrs, '49net Public Fixed')[0][0]) - return vmid + return vmid, mac -def delete_vm(proxmox, starrs, vmid, name): +def delete_vm(proxmox, starrs, vmid): print(vmid) print(get_vm_node(proxmox, vmid)) node = proxmox.nodes(get_vm_node(proxmox, vmid)) node.qemu(vmid).delete() - delete_starrs(starrs, name) diff --git a/templates/confirm_delete.html b/templates/confirm_delete.html new file mode 100644 index 0000000..bb74cbd --- /dev/null +++ b/templates/confirm_delete.html @@ -0,0 +1,20 @@ + + +
+ + + + +Create VM + +