[pve-devel] r6246 - in pve-manager/pve2: . www/manager www/manager/qemu www/manager/window

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Jul 6 13:00:20 CEST 2011


Author: dietmar
Date: 2011-07-06 13:00:20 +0200 (Wed, 06 Jul 2011)
New Revision: 6246

Modified:
   pve-manager/pve2/ChangeLog
   pve-manager/pve2/www/manager/Parser.js
   pve-manager/pve2/www/manager/qemu/HardwareView.js
   pve-manager/pve2/www/manager/window/Edit.js
Log:
	* www/manager/qemu/HardwareView.js: impl. PVE.qemu.NetworkEdit

	* www/manager/window/Edit.js: enable submit if me.create is true.



Modified: pve-manager/pve2/ChangeLog
===================================================================
--- pve-manager/pve2/ChangeLog	2011-07-06 08:19:07 UTC (rev 6245)
+++ pve-manager/pve2/ChangeLog	2011-07-06 11:00:20 UTC (rev 6246)
@@ -1,5 +1,9 @@
 2011-07-06  Proxmox Support Team  <support at proxmox.com>
 
+	* www/manager/qemu/HardwareView.js: impl. PVE.qemu.NetworkEdit
+
+	* www/manager/window/Edit.js: enable submit if me.create is true.
+
 	* www/manager/qemu/HardwareView.js: add 'Deletion Confirmation',
 	ability to re-add unused disks.
 

Modified: pve-manager/pve2/www/manager/Parser.js
===================================================================
--- pve-manager/pve2/www/manager/Parser.js	2011-07-06 08:19:07 UTC (rev 6245)
+++ pve-manager/pve2/www/manager/Parser.js	2011-07-06 11:00:20 UTC (rev 6246)
@@ -5,6 +5,51 @@
 
     // this class only contains static functions
 
+    parseQemuNetwork: function(key, value) {
+	if (!(key && value))
+	    return;
+
+	var res = {};
+
+	var errors = false;
+	Ext.Array.each(value.split(','), function(p) {
+	    if (!p || p.match(/^\s*$/))
+		return; // continue
+	    var match_res;
+
+	    if (match_res = p.match(/^(ne2k_pci|e1000|rtl8139|pcnet|virtio|ne2k_isa|i82551|i82557b|i82559er)(=([0-9a-f]{2}(:[0-9a-f]{2}){5}))?$/i)) {
+		res.model = match_res[1].toLowerCase();
+		if (match_res[3])
+		    res.macaddr = match_res[3];
+	    } else if (match_res = p.match(/^bridge=(\S+)$/)) {
+		res.bridge = match_res[1];
+	    } else if (match_res = p.match(/^rate=(\d+(\.\d+)?)$/)) {
+		res.rate = match_res[1];
+	    } else {
+		errors = true;
+		return false; // break
+	    }
+	});
+
+	if (errors || !res.model)
+	    return;
+
+	return res;
+    },
+
+    printQemuNetwork: function(net) {
+
+	var netstr = net.model;
+	if (net.macaddr)
+	    netstr += "=" + net.macaddr;
+	if (net.bridge)
+	    netstr += ",bridge=" + net.bridge;
+	if (net.rate)
+	    netstr += ",rate=" + net.rate;
+
+	return netstr;
+    },
+
     parseQemuDrive: function(key, value) {
 	if (!(key && value))
 	    return;
@@ -48,7 +93,7 @@
 	    res[k] = v;
 	});
 
-	if (errors)
+	if (errors || !res.file)
 	    return;
 	
 	return res;

Modified: pve-manager/pve2/www/manager/qemu/HardwareView.js
===================================================================
--- pve-manager/pve2/www/manager/qemu/HardwareView.js	2011-07-06 08:19:07 UTC (rev 6245)
+++ pve-manager/pve2/www/manager/qemu/HardwareView.js	2011-07-06 11:00:20 UTC (rev 6246)
@@ -124,6 +124,128 @@
     }
 });
 
+Ext.define('PVE.qemu.NetworkEdit', {
+    extend: 'PVE.window.Edit',
+
+    getParams: function(values) {
+	var me = this;
+
+	me.network.model = values.model;
+	if (values.mode === 'bridge') {
+	    me.network.bridge = values.bridge;
+	} else {
+	    me.network.bridge = undefined;
+	}
+	me.network.macaddr = values.macaddr;
+
+	var params = {};
+
+	params[me.confid] = PVE.Parser.printQemuNetwork(me.network);
+
+	return params;
+    },
+
+    initComponent : function() {
+	var me = this;
+
+	var nodename = me.pveSelNode.data.node;
+	if (!nodename) 
+	    throw "no node name specified";	    
+
+	me.create = me.confid ? false : true;
+
+	Ext.applyIf(me, {
+	    title: me.create ? "Add network device" : 
+		"Edit network device settings"
+ 	});
+
+	me.column1 = [
+	    {
+		xtype: 'radiofield',
+		name: 'mode',
+		height: 22, // hack: set same height as text fields
+		inputValue: 'bridge',
+		boxLabel: 'Bridged mode',
+		checked: true,
+		listeners: {
+		    change: function(f, value) {
+			if (!me.rendered)
+			    return;
+			me.down('field[name=bridge]').setDisabled(!value);
+			me.down('field[name=bridge]').validate();
+		    }
+		}
+	    },
+	    {
+		xtype: 'textfield',
+		name: 'bridge',
+		value: 'vmbr0',
+		fieldLabel: 'Bridge',
+		labelAlign: 'right',
+		allowBlank: false
+	    },
+	    {
+		xtype: 'radiofield',
+		name: 'mode',
+		height: 22, // hack: set same height as text fields
+		inputValue: 'nat',
+		boxLabel: 'NAT mode'
+	    }
+	];
+
+	me.column2 = [
+	    {
+		xtype: 'PVE.form.NetworkCardSelector',
+		name: 'model',
+		fieldLabel: 'Network card',
+		value: 'rtl8139',
+		allowBlank: false
+	    },
+	    {
+		xtype: 'textfield',
+		name: 'macaddr',
+		fieldLabel: 'MAC address',
+		allowBlank: true,
+		emptyText: 'auto'
+	    }
+	];
+
+	me.callParent();
+
+	me.load({
+	    success: function(form, action) {
+		var i, confid;
+		me.vmconfig = action.result.data;
+		if (!me.create) {
+		    var value = me.vmconfig[me.confid];
+		    me.network = PVE.Parser.parseQemuNetwork(me.confid, value);
+		    if (!me.network) {
+			Ext.Msg.alert('Error', 'Unable to parse network options');
+			me.close();
+			return;
+		    }
+		    var values = me.network;
+		    values.mode = values.bridge ? 'bridge' : 'nat';
+		    form.setValues(values);
+		    // hack: fix ExtJS bug
+		    Ext.Array.each(me.query('radiofield'), function(f) {
+			f.resetOriginalValue();
+		    });
+		} else {
+		    me.network = {};
+		    for (i = 0; i < 100; i++) {
+			confid = 'net' + i;
+			if (!Ext.isDefined(me.vmconfig[confid])) {
+			    me.confid = confid;
+			    break;
+			}
+		    }
+		}
+	    }
+	});
+    }
+});
+
 Ext.define('PVE.qemu.HDEdit', {
     extend: 'PVE.window.Edit',
 
@@ -745,6 +867,7 @@
 	    confid = "net" + i;
 	    rows[confid] = {
 		tdCls: 'pve-itype-icon-network',
+		editor: 'PVE.qemu.NetworkEdit',
 		header: 'Network Adapter '+ '(' + confid +')'
 	    };
 	}
@@ -889,6 +1012,12 @@
 				text: 'Network Device',
 				iconCls: 'pve-itype-icon-network',
 				handler: function() {
+				    var win = Ext.create('PVE.qemu.NetworkEdit', {
+					url: '/api2/extjs/' + baseurl,
+					pveSelNode: me.pveSelNode
+				    });
+				    win.on('destroy', reload);
+				    win.show();
 				}
 			    }
 			]

Modified: pve-manager/pve2/www/manager/window/Edit.js
===================================================================
--- pve-manager/pve2/www/manager/window/Edit.js	2011-07-06 08:19:07 UTC (rev 6245)
+++ pve-manager/pve2/www/manager/window/Edit.js	2011-07-06 11:00:20 UTC (rev 6246)
@@ -116,7 +116,7 @@
 
 	var submitBtn = Ext.create('Ext.Button', {
 	    text: me.create ? 'Create' : 'OK',
-	    disabled: true,
+	    disabled: !me.create,
 	    handler: function() {
 		me.submit(formpanel);
 	    }
@@ -133,7 +133,7 @@
 	var set_button_status = function() {
 	    var valid = form.isValid();
 	    var dirty = form.isDirty();
-	    submitBtn.setDisabled(!(valid && dirty));
+	    submitBtn.setDisabled(!valid || !(dirty || me.create));
 	    resetBtn.setDisabled(!dirty);
 	};
 




More information about the pve-devel mailing list