[pve-devel] [PATCH 10/10] add hdmove panel

Alexandre Derumier aderumier at odiso.com
Tue Jan 22 10:14:12 CET 2013


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 www/manager/Makefile             |    1 +
 www/manager/qemu/HDMove.js       |  139 ++++++++++++++++++++++++++++++++++++++
 www/manager/qemu/HardwareView.js |   40 ++++++++++-
 3 files changed, 179 insertions(+), 1 deletion(-)
 create mode 100644 www/manager/qemu/HDMove.js

diff --git a/www/manager/Makefile b/www/manager/Makefile
index 7da2234..e086aa4 100644
--- a/www/manager/Makefile
+++ b/www/manager/Makefile
@@ -96,6 +96,7 @@ JSSRC= 				                 	\
 	qemu/CDEdit.js					\
 	qemu/HDEdit.js					\
 	qemu/HDResize.js				\
+	qemu/HDMove.js					\
 	qemu/DisplayEdit.js				\
 	qemu/KeyboardEdit.js				\
 	qemu/HardwareView.js				\
diff --git a/www/manager/qemu/HDMove.js b/www/manager/qemu/HDMove.js
new file mode 100644
index 0000000..837467a
--- /dev/null
+++ b/www/manager/qemu/HDMove.js
@@ -0,0 +1,139 @@
+Ext.define('PVE.window.HDMove', {
+    extend: 'Ext.window.Window',
+
+    resizable: false,
+
+
+    move_disk: function(disk, storage, format) {
+	var me = this;
+
+        params =  { disk: disk, storage: storage };
+
+        if (format) {
+            params.format = format;
+        }
+
+	PVE.Utils.API2Request({
+	    params: params,
+	    url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/move',
+	    waitMsgTarget: me,
+	    method: 'PUT',
+	    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: 'disk',
+                value: me.disk,
+                fieldLabel: 'Disk',
+                vtype: 'StorageId',
+                allowBlank: false
+            },
+
+        ];
+
+        me.hdstoragesel = Ext.create('PVE.form.StorageSelector', {
+                name: 'hdstorage',
+                nodename: me.nodename,
+                fieldLabel: 'Target Storage',
+                storageContent: 'images',
+                autoSelect: me.insideWizard,
+                allowBlank: true,
+                disabled: false,
+                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
+	});
+
+
+	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 = "Move disk";
+	submitBtn = Ext.create('Ext.Button', {
+	    text: gettext('Move'),
+	    handler: function() {
+		if (form.isValid()) {
+		    var values = form.getValues();
+		    me.move_disk(me.disk, values.hdstorage, values.diskformat);
+		}
+	    }
+	});
+
+	Ext.apply(me, {
+	    modal: true,
+	    width: 350,
+	    border: false,
+	    layout: 'fit',
+	    buttons: [ submitBtn ],
+	    items: [ me.formPanel ]
+	});
+
+
+	me.callParent();
+
+
+    }
+});
diff --git a/www/manager/qemu/HardwareView.js b/www/manager/qemu/HardwareView.js
index 7bf8263..91c7516 100644
--- a/www/manager/qemu/HardwareView.js
+++ b/www/manager/qemu/HardwareView.js
@@ -234,6 +234,28 @@ Ext.define('PVE.qemu.HardwareView', {
 	    win.on('destroy', reload);
 	};
 
+	var run_move = function() {
+	    var rec = sm.getSelection()[0];
+	    if (!rec) {
+		return;
+	    }
+
+	    var rowdef = rows[rec.data.key];
+	    if (!rowdef.editor) {
+		return;
+	    }
+
+	    var win = Ext.create('PVE.window.HDMove', {
+		disk: rec.data.key,
+		nodename: nodename,
+		vmid: vmid
+	    });
+
+	    win.show();
+
+	    win.on('destroy', reload);
+	};
+
 	var edit_btn = new PVE.button.Button({
 	    text: gettext('Edit'),
 	    selModel: sm,
@@ -262,6 +284,21 @@ Ext.define('PVE.qemu.HardwareView', {
 	    handler: run_resize
 	});
 
+
+	var move_btn = new PVE.button.Button({
+	    text: gettext('Move disk'),
+	    selModel: sm,
+	    disabled: true,
+	    enableFn: function(rec) {
+		if (!rec) {
+		    return false;
+		}
+		var rowdef = rows[rec.data.key];
+		return rowdef.tdCls == 'pve-itype-icon-storage' && !rec.data.value.match(/media=cdrom/)
+	    },
+	    handler: run_move
+	});
+
 	var remove_btn = new PVE.button.Button({
 	    text: gettext('Remove'),
 	    selModel: sm,
@@ -355,7 +392,8 @@ Ext.define('PVE.qemu.HardwareView', {
 		}, 
 		remove_btn,
 		edit_btn,
-		resize_btn
+		resize_btn,
+		move_btn
 	    ],
 	    rows: rows,
 	    sorterFn: sorterFn,
-- 
1.7.10.4




More information about the pve-devel mailing list