[pve-devel] r5954 - in pve-manager/pve2: lib/PVE www/new www/new/qemu

svn-commits at proxmox.com svn-commits at proxmox.com
Tue May 10 09:31:57 CEST 2011


Author: dietmar
Date: 2011-05-10 09:31:57 +0200 (Tue, 10 May 2011)
New Revision: 5954

Modified:
   pve-manager/pve2/lib/PVE/REST.pm
   pve-manager/pve2/www/new/PVEUtils.js
   pve-manager/pve2/www/new/qemu/CreateWizard.js
Log:
really creat VMs


Modified: pve-manager/pve2/lib/PVE/REST.pm
===================================================================
--- pve-manager/pve2/lib/PVE/REST.pm	2011-05-10 07:09:42 UTC (rev 5953)
+++ pve-manager/pve2/lib/PVE/REST.pm	2011-05-10 07:31:57 UTC (rev 5954)
@@ -135,6 +135,7 @@
 	if (is_error($res->{status})) {
 	    $success = 0;
 	    $new->{message} = $res->{message} || status_message($res->{status});
+	    $new->{status} = $res->{status} || HTTP_OK;
 	    $res->{message} = undef;
 	    $res->{status} = HTTP_OK;
 	}

Modified: pve-manager/pve2/www/new/PVEUtils.js
===================================================================
--- pve-manager/pve2/www/new/PVEUtils.js	2011-05-10 07:09:42 UTC (rev 5953)
+++ pve-manager/pve2/www/new/PVEUtils.js	2011-05-10 07:31:57 UTC (rev 5954)
@@ -53,6 +53,53 @@
 	return 21;
     },
 
+    // Ext.Ajax.request
+    API2Request: function(options) {
+	var callbackFn = options.callback;
+	var successFn = options.success;
+	var failureFn = options.failure;
+
+	options.url = '/api2/extjs' + options.url;
+
+	delete options.callback;
+
+	options.success = function(response, options) {
+	    var result = Ext.decode(response.responseText);
+	    if (!result.success) {
+		var msg = "Unknown error";
+		if (result.message) {
+		    msg = result.message;
+		    if (result.status)
+			msg += ' (' + result.status + ')';
+		}
+		if (Ext.isObject(result.errors)) {
+		    msg += "<br>";
+		    Ext.Object.each(result.errors, function(prop, desc) {
+			msg += "<br><b>" + Ext.htmlEncode(prop) + "</b>: " + 
+			    Ext.htmlEncode(desc);
+		    });
+		}	
+		response.htmlStatus = msg;
+		Ext.callback(callbackFn, options.scope, [options, false, response])
+		Ext.callback(failureFn, options.scope, [response, options])
+		return;
+	    }
+	    Ext.callback(callbackFn, options.scope, [options, true, response])
+	    Ext.callback(successFn, options.scope, [response, options])
+	};
+
+	options.failure = function(response, options) {
+	    var msg = "Connection error - server offline?";
+	    if (response.status && response.statusText)
+		msg = "Connection error " + response.status + ": " + response.statusText;
+	    response.htmlStatus = msg;
+	    Ext.callback(callbackFn, options.scope, [options, false, response])
+	    Ext.callback(failureFn, options.scope, [response, options])
+	};
+
+	Ext.Ajax.request(options);
+    },
+
     assemble_field_data: function(values, data) {
         if (Ext.isObject(data)) {
             Ext.iterate(data, function(name, val) {

Modified: pve-manager/pve2/www/new/qemu/CreateWizard.js
===================================================================
--- pve-manager/pve2/www/new/qemu/CreateWizard.js	2011-05-10 07:09:42 UTC (rev 5953)
+++ pve-manager/pve2/www/new/qemu/CreateWizard.js	2011-05-10 07:31:57 UTC (rev 5954)
@@ -321,7 +321,7 @@
 		    items: [
 			{
 			    xtype: 'numberfield',
-			    name: 'mem',
+			    name: 'memory',
 			    minValue: 32,
 			    maxValue: 128*1024,
 			    value: 512,
@@ -395,9 +395,27 @@
 			}
 		    },
 		    onSubmit: function() {
-			//var form = me.down('form').getForm();
 			var kv = me.getValues();
-			console.dir(kv);
+
+			var nodename = kv.nodename;
+			delete kv.nodename;
+
+			me.down('form').setLoading(true, true);
+			PVE.Utils.API2Request({
+			    url: '/nodes/' + nodename + '/qemu',
+			    method: 'POST',
+			    params: kv,
+			    callback: function() {
+				me.down('form').setLoading(false);
+			    },
+			    success: function(response){
+				me.close();
+			    },
+			    failure: function(response, opts) {
+				Ext.Msg.alert('Error', response.htmlStatus);
+			    }
+			});
+
 		    }
 		}
 	    ]




More information about the pve-devel mailing list