[pve-devel] [PATCH 8/9] add clone panel form

Alexandre Derumier aderumier at odiso.com
Tue Jan 8 15:46:45 CET 2013


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 www/manager/Makefile      |    1 +
 www/manager/qemu/Clone.js |  231 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 232 insertions(+)
 create mode 100644 www/manager/qemu/Clone.js

diff --git a/www/manager/Makefile b/www/manager/Makefile
index a4feb40..9e84ef1 100644
--- a/www/manager/Makefile
+++ b/www/manager/Makefile
@@ -102,6 +102,7 @@ JSSRC= 				                 	\
 	qemu/ScsiHwEdit.js				\
 	qemu/Options.js					\
 	qemu/Snapshot.js				\
+	qemu/Clone.js					\
 	qemu/SnapshotTree.js				\
 	qemu/Config.js					\
 	qemu/CreateWizard.js				\
diff --git a/www/manager/qemu/Clone.js b/www/manager/qemu/Clone.js
new file mode 100644
index 0000000..026c3cb
--- /dev/null
+++ b/www/manager/qemu/Clone.js
@@ -0,0 +1,231 @@
+Ext.define('PVE.window.Clone', {
+    extend: 'Ext.window.Window',
+
+    resizable: false,
+
+
+    create_clone: function(snapname, name, newvmid, clonemode, storage, format, diskarray) {
+	var me = this;
+
+        params =  { name: name, clonefrom: me.vmid, vmid: newvmid, clonemode: clonemode };
+
+
+        if (snapname && snapname !== 'current') {
+            params.snapname = snapname;
+        }
+
+	if (clonemode === 'copy' && storage){
+
+	    Ext.Array.each(diskarray, function(disk) {
+		var myformat = format ? format : '';
+		params[disk] = storage + ':' + myformat;
+	    });
+	}
+
+
+
+	PVE.Utils.API2Request({
+	    params: params,
+	    url: '/nodes/' + me.nodename + '/qemu',
+	    waitMsgTarget: me,
+	    method: 'POST',
+	    failure: function(response, opts) {
+		Ext.Msg.alert('Error', response.htmlStatus);
+	    },
+	    success: function(response, options) {
+		me.close();
+	    }
+	});
+
+    },
+
+    initComponent : function() {
+	var me = this;
+
+	var diskarray = [];
+
+	if (!me.nodename) {
+	    throw "no node name specified";
+	}
+
+	if (!me.vmid) {
+	    throw "no VM ID specified";
+	}
+
+	var items = [
+	    {
+		xtype: 'displayfield',
+		name: 'snapname',
+		value: me.snapname,
+		fieldLabel: 'Template Name',
+		vtype: 'StorageId',
+		allowBlank: false
+	    },
+	    {
+                xtype: 'pveVMIDSelector',
+                name: 'newvmid',
+                value: '',
+                loadNextFreeVMID: true,
+                validateExists: false
+            },
+
+	];
+
+
+	items.push({
+	    xtype: 'textfield',
+	    name: 'name',
+	    allowBlank: false,
+	    fieldLabel: 'Name',
+	});
+
+        me.hdstoragesel = Ext.create('PVE.form.StorageSelector', {
+                name: 'hdstorage',
+                nodename: me.nodename,
+                fieldLabel: 'Target Storage',
+                storageContent: 'images',
+                autoSelect: me.insideWizard,
+                allowBlank: true,
+                disabled: true,
+                hidden: false,
+                listeners: {
+                    change: function(f, value) {
+                        var rec = f.store.getById(value);
+			if (rec.data.type === 'iscsi') {
+                            me.formatsel.setValue('raw');
+                            me.formatsel.setDisabled(true);
+                        } else if (rec.data.type === 'lvm' ||
+                                   rec.data.type === 'rbd' ||
+                                   rec.data.type === 'sheepdog' ||
+                                   rec.data.type === 'nexenta'
+                        ) {
+                            me.formatsel.setValue('raw');
+                            me.formatsel.setDisabled(true);
+                        } else {
+                            me.formatsel.setDisabled(false);
+                        }
+
+                    }
+                }
+
+	});
+
+	me.formatsel = Ext.create('PVE.form.DiskFormatSelector', {
+		name: 'diskformat',
+		fieldLabel: gettext('Format'),
+		value: 'raw',
+                disabled: true,
+                hidden: false,
+		allowBlank: false
+	});
+
+
+	me.clonemode = Ext.create('PVE.form.CloneModeSelector', {
+	    name: 'clonemode',
+	    nodename: me.nodename,
+	    vmid: me.vmid,
+	    snapname: me.snapname,
+	    clonefeature: me.clonefeature,
+	    fieldLabel: gettext('Clone mode'),
+	    allowBlank: false,
+	    listeners: {
+                    change: function(f, value) {
+                        if (value === 'copy') {
+                            me.hdstoragesel.setDisabled(false);
+                        }else{
+                            me.hdstoragesel.setDisabled(true);
+                            me.formatsel.setDisabled(true);
+
+			}
+                    }
+          }
+
+	});
+
+	if(me.clonefeature){
+	    me.clonemode.setValue('clone');
+	}
+	else{
+	    me.clonemode.setValue('copy');
+	}
+
+	items.push(me.clonemode);
+	items.push(me.hdstoragesel);
+	items.push(me.formatsel);
+
+	me.formPanel = Ext.create('Ext.form.Panel', {
+	    bodyPadding: 10,
+	    border: false,
+	    fieldDefaults: {
+		labelWidth: 100,
+		anchor: '100%'
+	    },
+	    items: items
+	});
+
+	var form = me.formPanel.getForm();
+
+	var submitBtn;
+
+	me.title = "Clone Template '" + me.snapname + " of VM " + me.vmid;
+	submitBtn = Ext.create('Ext.Button', {
+	    text: gettext('Clone'),
+	    handler: function() {
+		if (form.isValid()) {
+		    var values = form.getValues();
+		    me.create_clone(me.snapname, values.name, values.newvmid, values.clonemode, values.hdstorage, values.diskformat, diskarray);
+		}
+	    }
+	});
+
+
+	Ext.apply(me, {
+	    modal: true,
+	    width: 350,
+	    height: 250,
+	    border: false,
+	    layout: 'fit',
+	    buttons: [ submitBtn ],
+	    items: [ me.formPanel ]
+	});
+
+
+	me.callParent();
+
+	if (!me.snapname) {
+	    return;
+	}
+
+        var url;
+
+        if (me.snapsname) {
+	    url = '/nodes/' + me.nodename + '/qemu/' + me.vmid + "/snapshot/" + me.snapname + '/config';
+        } else {
+	    url = '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/config';
+        }
+
+
+	PVE.Utils.API2Request({
+	    url: url,
+	    waitMsgTarget: me,
+	    method: 'GET',
+	    failure: function(response, opts) {
+		Ext.Msg.alert('Error', response.htmlStatus);
+		me.close();
+	    },
+	    success: function(response, options) {
+		var data = response.result.data;
+		Ext.Object.each(data, function(key, value) {
+
+		    var drive = PVE.Parser.parseQemuDrive(key, value);
+		    if (drive) {
+			var match = drive.file.match(/^([^:]+):/);
+			if (match) {
+			diskarray.push(key);
+			}
+		    }
+		});
+	    }
+	});
+    }
+});
-- 
1.7.10.4




More information about the pve-devel mailing list