[pve-devel] [PATCH 7/9] snapshot tree : add create_template, delete_template, clone_template

Alexandre Derumier aderumier at odiso.com
Tue Jan 15 10:01:07 CET 2013


fixme : disable rollback button is current is a template

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 www/manager/qemu/SnapshotTree.js |  157 +++++++++++++++++++++++++++++++++++---
 1 file changed, 148 insertions(+), 9 deletions(-)

diff --git a/www/manager/qemu/SnapshotTree.js b/www/manager/qemu/SnapshotTree.js
index f98c849..64ffdc5 100644
--- a/www/manager/qemu/SnapshotTree.js
+++ b/www/manager/qemu/SnapshotTree.js
@@ -22,6 +22,7 @@ Ext.define('PVE.qemu.SnapshotTree', {
 
     reload: function(repeat) {
         var me = this;
+	var currentistemplate;
 
 	PVE.Utils.API2Request({
 	    url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/snapshot',
@@ -38,15 +39,18 @@ Ext.define('PVE.qemu.SnapshotTree', {
 		Ext.Array.each(response.result.data, function(item) {
 		    item.leaf = true;
 		    item.children = [];
+
+		    var running = item.running ? '-running' : '';
+		    var template = item.template ? '-template' : '';
+
 		    if (item.name === 'current') {
 			digest = item.digest + item.running;
-			if (item.running) {
-			    item.iconCls = 'x-tree-node-computer-running';
-			} else {
-			    item.iconCls = 'x-tree-node-computer';
+	                item.iconCls = 'x-tree-node-computer' + running + template;
+			if(item.template){
+			   currentistemplate = 1;
 			}
 		    } else {
-			item.iconCls = 'x-tree-node-snapshot';
+                        item.iconCls = 'x-tree-node-snapshot' + template;
 		    }
 		    idhash[item.name] = item;
 		});
@@ -78,8 +82,10 @@ Ext.define('PVE.qemu.SnapshotTree', {
             method: 'GET',
             success: function(response, options) {
                 var res = response.result.data;
-		if (res === 1) {
+		if (res === 1 && !currentistemplate) {
 		   Ext.getCmp('snapshotBtn').enable();
+		}else{
+		   Ext.getCmp('snapshotBtn').disable();
 		}
             }
         });
@@ -109,11 +115,28 @@ Ext.define('PVE.qemu.SnapshotTree', {
 		record.data.name !== 'current';
 	};
 
+	var valid_snapshot_delete = function(record) {
+	    return record && record.data && record.data.name &&
+		record.data.name !== 'current' && !record.data.template;
+	};
+
 	var valid_snapshot_rollback = function(record) {
 	    return record && record.data && record.data.name &&
 		record.data.name !== 'current' && !record.data.snapstate;
 	};
 
+	var valid_template = function(record) {
+	    if(record && record.data && record.data.template){
+	        return true;
+	    }else{
+		return false;
+	    }
+	};
+
+	var valid_not_template = function(record) {
+	    return record && record.data && !record.data.template && !record.data.snapstate;
+	};
+
 	var run_editor = function() {
 	    var rec = sm.getSelection()[0];
 	    if (valid_snapshot(rec)) {
@@ -127,6 +150,42 @@ Ext.define('PVE.qemu.SnapshotTree', {
 	    }
 	};
 
+	var run_clone = function() {
+	    var rec = sm.getSelection()[0];
+	    if (valid_template(rec)) {
+
+		var snapname = rec.data.name;
+		var params = { feature: 'clone' };
+		if (snapname && snapname !== 'current') {
+		    params.snapname = snapname;
+		}
+
+		PVE.Utils.API2Request({
+		    waitMsgTarget: me,
+		    url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/feature',
+		    params: params,
+		    method: 'GET',
+		    success: function(response, options) {
+			var res = response.result.data;
+			var clonefeature;
+
+			if (res === 1) {
+			    clonefeature = 1;
+			}
+
+			var win = Ext.create('PVE.window.Clone', {
+			    snapname: snapname,
+			    nodename: me.nodename,
+			    vmid: me.vmid,
+			    clonefeature: clonefeature
+			});
+			win.show();
+			me.mon(win, 'close', me.reload, me);
+		    }
+		});
+	    }
+	};
+
 	var editBtn = new PVE.button.Button({
 	    text: gettext('Edit'),
 	    disabled: true,
@@ -180,7 +239,7 @@ Ext.define('PVE.qemu.SnapshotTree', {
 					    "'" + rec.data.name + "'");
 		return msg;
 	    },
-	    enableFn: valid_snapshot,
+	    enableFn: valid_snapshot_delete,
 	    handler: function(btn, event) {
 		var rec = sm.getSelection()[0];
 		if (!rec) {
@@ -220,15 +279,95 @@ Ext.define('PVE.qemu.SnapshotTree', {
 	    }
 	});
 
+
+	var templateBtn = new PVE.button.Button({
+	    text: gettext('Create Template'),
+	    enableFn: valid_not_template,
+	    disabled: true,
+	    selModel: sm,
+            handler: function(btn, event) {
+                var rec = sm.getSelection()[0];
+                if (!rec) {
+                    return;
+                }
+		var params = {};
+
+                if (rec.data.name && rec.data.name !== 'current') {
+                    params.snapname = rec.data.name;
+                }
+
+                PVE.Utils.API2Request({
+                    url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/template',
+                    params: params,
+                    method: 'POST',
+                    waitMsgTarget: me,
+                    callback: function() {
+                        me.reload();
+                    },
+                    failure: function (response, opts) {
+                        Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+                    },
+                    success: function(response, options) {
+                        //win.show();
+                    }
+                });
+            }
+
+	});
+
+	var templatedeleteBtn = new PVE.button.Button({
+	    text: gettext('Delete Template'),
+	    disabled: true,
+	    selModel: sm,
+	    enableFn: valid_template,
+            handler: function(btn, event) {
+                var rec = sm.getSelection()[0];
+                if (!rec) {
+                    return;
+                }
+		var params = { delete:1 };
+
+                if (rec.data.name && rec.data.name !== 'current') {
+                    params.snapname = rec.data.name;
+                }
+
+                PVE.Utils.API2Request({
+                    url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/template',
+                    params: params,
+                    method: 'POST',
+                    waitMsgTarget: me,
+                    callback: function() {
+                        me.reload();
+                    },
+                    failure: function (response, opts) {
+                        Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+                    },
+                    success: function(response, options) {
+                        //win.show();
+                    }
+                });
+            }
+
+	});
+
+	var cloneBtn = new PVE.button.Button({
+	    text: gettext('Clone Template'),
+	    disabled: true,
+	    selModel: sm,
+	    enableFn: valid_template,
+	    handler: run_clone
+	});
+
+
 	Ext.apply(me, {
 	    layout: 'fit',
 	    rootVisible: false,
 	    animate: false,
 	    sortableColumns: false,
 	    selModel: sm,
-	    tbar: [ snapshotBtn, rollbackBtn, removeBtn, editBtn ],
+	    tbar: [ snapshotBtn, rollbackBtn, removeBtn, editBtn, templateBtn, templatedeleteBtn, cloneBtn ],
 	    fields: [ 
-		'name', 'description', 'snapstate', 'vmstate', 'running',
+		'name', 'description', 'snapstate', 'vmstate', 'running', 'template',
 		{ name: 'snaptime', type: 'date', dateFormat: 'timestamp' }
 	    ],
 	    columns: [
-- 
1.7.10.4




More information about the pve-devel mailing list