From 617a6481e99d87fe2bbfd3f7c7652542c15ceac8 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 29 Feb 2024 16:12:31 +0100 Subject: [PATCH] VM snapshot add/delete --- app.py | 38 +++++++++++++++++++++++++++++++++++++- functions/fbackup.py | 5 +++++ templates/backup.html | 4 +++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 59bb2be..69dc529 100644 --- a/app.py +++ b/app.py @@ -376,6 +376,43 @@ 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(): + vm_name=request.form['snap'] + try: + create_snap_vm(vm_name) + flash('Snapshot '+vm_name+' done', category='success') + except Exception as e: + flash('Error on snapshoting '+vm_name+':'+str(e), category='danger') + return redirect(url_for('backup')) + +@app.route('/del_snap_vm', methods = ['POST']) +@login_required +def delsnapvm(): + vm_name=request.form['vm_name'] + item=request.form['item'] + try: + del_snap_vm(vm_name,item) + flash(item+' deleted', category='success') + 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(): + vm_name=request.form['lxc_name'] + item=request.form['item'] + try: + rest_snap_lxc(lxc_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 ## @@ -417,7 +454,6 @@ def create_VM(): #################################### ## WINDOWS ## #################################### - if ose.startswith('win'): try: cmd = "qemu-img create -f qcow2 "+str(virtuo_path)+str(nom)+".qcow2 "+str(disk)+"G" diff --git a/functions/fbackup.py b/functions/fbackup.py index 5bf4d8c..efb1a0d 100644 --- a/functions/fbackup.py +++ b/functions/fbackup.py @@ -50,3 +50,8 @@ def get_snap_list_vm(vm_name): for snap in list_snap_vm: out.append(snap) return out + +def del_snap_vm(vm_name,item): + dom=conn.lookupByName(vm_name) + snap_del=dom.snapshotLookupByName(item) + snap_del.delete() diff --git a/templates/backup.html b/templates/backup.html index c6aabc2..43da47d 100644 --- a/templates/backup.html +++ b/templates/backup.html @@ -26,7 +26,9 @@ {{ snap_vm }} - +
+ +
{% endfor %}