[pve-devel] [PATCH pve-manager 4/5] add resize LXC Mountpoint at the GUI

Wolfgang Link w.link at proxmox.com
Wed Oct 28 09:44:30 CET 2015


---
 www/manager/Makefile         |   1 +
 www/manager/lxc/MPResize.js  | 104 +++++++++++++++++++++++++++++++++++++++++++
 www/manager/lxc/Resources.js |  51 ++++++++++++++++++++-
 3 files changed, 154 insertions(+), 2 deletions(-)
 create mode 100644 www/manager/lxc/MPResize.js

diff --git a/www/manager/Makefile b/www/manager/Makefile
index ea2e0b1..55a7ef5 100644
--- a/www/manager/Makefile
+++ b/www/manager/Makefile
@@ -150,6 +150,7 @@ JSSRC= 				                 	\
 	lxc/SnapshotTree.js				\
 	lxc/Snapshot.js					\
 	lxc/ResourceEdit.js				\
+	lxc/MPResize.js					\
 	pool/StatusView.js				\
 	pool/Summary.js					\
 	pool/Config.js					\
diff --git a/www/manager/lxc/MPResize.js b/www/manager/lxc/MPResize.js
new file mode 100644
index 0000000..ee193df
--- /dev/null
+++ b/www/manager/lxc/MPResize.js
@@ -0,0 +1,104 @@
+Ext.define('PVE.window.MPResize', {
+    extend: 'Ext.window.Window',
+
+    resizable: false,
+
+    resize_disk: function(disk, size) {
+	var me = this;
+        var params =  { disk: disk, size: '+' + size + 'G' };
+
+	PVE.Utils.API2Request({
+	    params: params,
+	    url: '/nodes/' + me.nodename + '/lxc/' + me.vmid + '/resize',
+	    waitMsgTarget: me,
+	    method: 'PUT',
+	    failure: function(response, opts) {
+		Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+	    },
+	    success: function(response, opts) {
+		var upid = response.result.data;
+		var win = Ext.create('PVE.window.TaskViewer', { upid: upid });
+		win.show();
+		me.close();
+	    }
+	});
+    },
+
+    initComponent : function() {
+	var me = this;
+
+	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: gettext('Disk'),
+		vtype: 'StorageId',
+		allowBlank: false
+	    }
+	];
+
+	me.hdsizesel = Ext.createWidget('numberfield', {
+	    name: 'size',
+	    minValue: 0,
+	    maxValue: 128*1024,
+	    decimalPrecision: 3,
+	    value: '0',
+	    fieldLabel: gettext('Size Increment') + ' (GB)',
+	    allowBlank: false
+	});
+
+	items.push(me.hdsizesel);
+
+	me.formPanel = Ext.create('Ext.form.Panel', {
+	    bodyPadding: 10,
+	    border: false,
+	    fieldDefaults: {
+		labelWidth: 120,
+		anchor: '100%'
+	    },
+	    items: items
+	});
+
+	var form = me.formPanel.getForm();
+
+	var submitBtn;
+
+	me.title = gettext('Resize disk');
+	submitBtn = Ext.create('Ext.Button', {
+	    text: gettext('Resize disk'),
+	    handler: function() {
+		if (form.isValid()) {
+		    var values = form.getValues();
+		    me.resize_disk(me.disk, values.size);
+		}
+	    }
+	});
+
+	Ext.apply(me, {
+	    modal: true,
+	    width: 250,
+	    height: 150,
+	    border: false,
+	    layout: 'fit',
+	    buttons: [ submitBtn ],
+	    items: [ me.formPanel ]
+	});
+
+
+	me.callParent();
+
+	if (!me.disk) {
+	    return;
+	}
+
+    }
+});
diff --git a/www/manager/lxc/Resources.js b/www/manager/lxc/Resources.js
index 78b64e5..f99d62b 100644
--- a/www/manager/lxc/Resources.js
+++ b/www/manager/lxc/Resources.js
@@ -112,6 +112,23 @@ Ext.define('PVE.lxc.RessourceView', {
 	    win.on('destroy', reload);
 	};
 
+	var run_resize = function() {
+	    var rec = sm.getSelection()[0];
+	    if (!rec) {
+		return;
+	    }
+
+	    var win = Ext.create('PVE.window.MPResize', {
+		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,
@@ -126,15 +143,45 @@ Ext.define('PVE.lxc.RessourceView', {
 	    handler: run_editor
 	});
 
+	var resize_btn = new PVE.button.Button({
+	    text: gettext('Resize disk'),
+	    selModel: sm,
+	    disabled: true,
+	    handler: run_resize
+	});
+
+	var set_button_status = function() {
+	    var sm = me.getSelectionModel();
+	    var rec = sm.getSelection()[0];
+
+	    if (!rec) {
+		edit_btn.disable();
+		resize_btn.disable();
+		return;
+	    }
+	    var key = rec.data.key;
+	    var value = rec.data.value;
+	    var rowdef = rows[key];
+
+	    var isDisk = (rowdef.tdCls == 'pve-itype-icon-storage');
+
+	    edit_btn.setDisabled(rec.data['delete'] || !rowdef.editor);
+
+	    resize_btn.setDisabled(!isDisk);
+
+	};
+	
 	Ext.applyIf(me, {
 	    url: '/api2/json/' + baseurl,
 	    selModel: sm,
 	    cwidth1: 170,
-	    tbar: [ edit_btn ],
+	    tbar: [ edit_btn,
+		    resize_btn],
 	    rows: rows,
 	    listeners: {
 		show: reload,
-		itemdblclick: run_editor
+		itemdblclick: run_editor,
+		selectionchange: set_button_status
 	    }
 	});
 
-- 
2.1.4





More information about the pve-devel mailing list