diff --git a/app.py b/app.py index 1adfc78..6cf67ed 100644 --- a/app.py +++ b/app.py @@ -16,6 +16,8 @@ from functions.fvm import * from functions.fvnc import * from functions.fbackup import * from functions.fpool import * +from functions.fedit import * +from functions.fscreen import * app = Flask(__name__,static_url_path='',static_folder='static',template_folder='templates') @@ -281,6 +283,39 @@ def deluser(): return redirect('param') +############################ +## EDIT ## +############################ + +@app.route('/editvm',methods=['POST']) +@login_required +def edit(): + vm_name = request.form['edit'] + state, maxmem, mem, cpus, cput = get_info_vm(vm_name) +#Memory in MB + return render_template('edit.html', vm_name=vm_name, max_Mermory=conn.getInfo()[1],max_vCPU= conn.getMaxVcpus(None),actual_vCPU=cpus, actual_ram=int(mem/1024),screen_64=get_screenshot(vm_name).decode('ASCII')) + + +@app.route('/editressources',methods=['POST']) +@login_required +def editressources(): + vm_name = request.form['vm_name'] + new_ram = int(request.form['new_mem']) + new_cpu = int(request.form['new_cpu']) + print("vm:"+vm_name) + print("ram:"+str(new_ram)) + print("vcpu:"+str(new_cpu)) + + try: + set_memory(vm_name,int(new_ram*1024)) + except Exception as e: + flash('Error editing '+vm_name+': '+str(e), category='danger') + try: + set_vcpu(vm_name,new_cpu) + except Exception as e: + flash('Error editing '+vm_name+': '+str(e), category='danger') + return redirect(url_for('state')) + ############################ ## ISO ## ############################ @@ -397,7 +432,6 @@ def restsnap_lxc(): flash('Error restoring '+item+':'+str(e), category='danger') return redirect(url_for('backup')) -###LAPIN @app.route('/snapvm', methods = ['POST']) @login_required def snapvm(): @@ -420,20 +454,18 @@ def delsnapvm(): except Exception as e: flash('Error on deleting '+item+':'+str(e), category='danger') return redirect(url_for('backup')) -""" + @app.route('/rest_snap_vm', methods = ['POST']) @login_required -def restsnap_lxc(): +def restsnap_vm(): vm_name=request.form['lxc_name'] item=request.form['item'] try: - rest_snap_lxc(lxc_name,item) + rest_snap_vm(vm_name,item) flash('Restore '+item+' done', category='success') except Exception as e: flash('Error restoring '+item+':'+str(e), category='danger') return redirect(url_for('backup')) -""" -##PINE LA ############################ ## BUILD ## diff --git a/functions/fscreen.py b/functions/fscreen.py new file mode 100644 index 0000000..49e063b --- /dev/null +++ b/functions/fscreen.py @@ -0,0 +1,20 @@ +from config import * +import base64 + +def get_screenshot(vm_name): + dom = conn.lookupByName(vm_name) + stream = conn.newStream() + imageType = dom.screenshot(stream,0) + file = "tmp_screen_" + dom.name() + fileHandler = open(file, 'wb') + streamBytes = stream.recv(262120) + while streamBytes != b'': + fileHandler.write(streamBytes) + streamBytes = stream.recv(262120) + fileHandler.close() + print('Screenshot saved as type: ' + imageType) + stream.finish() + with open(file, "rb") as f: + data = base64.b64encode(f.read()) + os.remove(file) + return data diff --git a/templates/edit.html b/templates/edit.html new file mode 100644 index 0000000..29b5fc7 --- /dev/null +++ b/templates/edit.html @@ -0,0 +1,33 @@ +{% extends 'layout.html' %} +{% block content %} +{% include 'menu.html' %} +
@@ -93,7 +97,8 @@ | - + | + |
{% if inact_vm[1] == 1 %}
|
---|