[pve-devel] r5508 - in pve-manager/pve2: lib/PVE lib/PVE/API2 www/manager www/manager/data www/manager/form

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Feb 11 10:39:54 CET 2011


Author: dietmar
Date: 2011-02-11 10:39:54 +0100 (Fri, 11 Feb 2011)
New Revision: 5508

Modified:
   pve-manager/pve2/lib/PVE/API2.pm
   pve-manager/pve2/lib/PVE/API2/Cluster.pm
   pve-manager/pve2/lib/PVE/API2/Nodes.pm
   pve-manager/pve2/lib/PVE/REST.pm
   pve-manager/pve2/www/manager/PVECache.js
   pve-manager/pve2/www/manager/StorageBrowser.js
   pve-manager/pve2/www/manager/data/ObjectReader.js
   pve-manager/pve2/www/manager/form/ModifyDirStorage.js
Log:
fix object hierarchy


Modified: pve-manager/pve2/lib/PVE/API2/Cluster.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Cluster.pm	2011-02-11 09:37:26 UTC (rev 5507)
+++ pve-manager/pve2/lib/PVE/API2/Cluster.pm	2011-02-11 09:39:54 UTC (rev 5508)
@@ -5,6 +5,7 @@
 
 use PVE::SafeSyslog;
 use PVE::Cluster;
+use PVE::Storage;
 use JSON;
 
 use Data::Dumper; # fixme: remove
@@ -38,6 +39,7 @@
     
 	my $result = [
 	    { name => 'log' },
+	    { name => 'storage' },
 	    ];
 
 	return $result;
@@ -82,4 +84,59 @@
 	return $list;
     }});
 
+__PACKAGE__->register_method ({
+    name => 'storage', 
+    path => 'storage', 
+    method => 'GET',
+    description => "Cluster wide storage status.",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {},
+    },
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => {},
+	},
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $nodes = PVE::Cluster::get_nodelist();
+
+	my $cfg = PVE::Storage::config();
+
+	my @sids =  PVE::Storage::storage_ids ($cfg);
+
+	# fixme: add storage status ('disk', 'maxdisk')
+ 
+	my $res = [];
+	foreach my $storeid (@sids) {
+	    my $scfg =  PVE::Storage::storage_config ($cfg, $storeid);
+	    if ($scfg->{shared}) {
+		push @$res,{ 
+		    name => $storeid, 
+		    storage => $storeid, 
+		    type => $scfg->{type}, 
+		    shared => 1
+		}; 
+	    } else {
+		# we create a entry for each node
+		foreach my $nd (@$nodes) {
+		    my $node = $nd->{node};
+		    push @$res, { 
+			name => "$storeid ($node)", 
+			storage => $storeid, 
+			node => $node, 
+			type => $scfg->{type}, 
+			shared => 0
+		    }; 
+		}
+	    }
+	}
+
+	return $res;
+    }});
+
 1;

Modified: pve-manager/pve2/lib/PVE/API2/Nodes.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-02-11 09:37:26 UTC (rev 5507)
+++ pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-02-11 09:39:54 UTC (rev 5508)
@@ -12,6 +12,8 @@
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::AccessControl;
 use PVE::API2::Services;
+use PVE::API2::Storage::Scan;
+use PVE::API2::Storage::Status;
 use JSON;
 
 use base qw(PVE::RESTHandler);
@@ -22,6 +24,16 @@
 });
 
 __PACKAGE__->register_method ({
+    subclass => "PVE::API2::Storage::Scan",  
+    path => 'scan',
+});
+
+__PACKAGE__->register_method ({
+    subclass => "PVE::API2::Storage::Status",  
+    path => 'storage',
+});
+
+__PACKAGE__->register_method ({
     name => 'index', 
     path => '', 
     method => 'GET',
@@ -46,7 +58,12 @@
 	my $result = [
 	    { name => 'syslog' },
 	    { name => 'vncshell' },
+	    { name => 'time' },
+	    { name => 'dns' },
 	    { name => 'services' },
+	    { name => 'scan' },
+	    { name => 'storage' },
+	    { name => 'upload' },
 	    ];
 
 	return $result;
@@ -342,6 +359,75 @@
 	return undef;
     }});
 
+__PACKAGE__->register_method ({
+    name => 'upload', 
+    path => 'upload',
+    method => 'POST',
+    description => "Upload content.",
+    parameters => {
+    	additionalProperties => 0,
+	properties => { 
+	    node => get_standard_option('pve-node'),
+	    storage => get_standard_option('pve-storage-id'),
+	    filename => { 
+		description => "The name of the file to create/upload.",
+		type => 'string',
+	    },
+	    vmid => get_standard_option
+		('pve-vmid', { 
+		    description => "Specify owner VM",
+		    optional => 1,
+		 }),
+	},
+    },
+    returns => {
+	description => "Volume identifier",
+	type => 'string',
+    },
+    code => sub {
+	my ($param) = @_;
+
+	# todo: can we proxy file uploads to remote nodes?
+	if ($param->{node} ne PVE::INotify::nodename()) {
+	    raise_param_exc({ node => "can't upload content to remote node" });
+	}
+
+	my $node = $param->{node};
+	my $storeid = $param->{storage};
+	my $name = $param->{filename};
+
+	my $fh = CGI::upload('filename') || die "unable to get file handle\n";
+
+	syslog ('info', "UPLOAD $name to $node $storeid");
+	
+	# fixme:
+	die "upload not implemented\n";
+
+	my $buffer = "";
+	my $tmpname = "/tmp/proxmox_upload-$$.bin";
+
+	eval {
+	    open FILE, ">$tmpname" || die "can't open temporary file '$tmpname' - $!\n";
+	    while (read($fh, $buffer, 32768)) {
+		die "write failed - $!" unless print FILE $buffer;
+	    }
+	    close FILE || die " can't close temporary file '$tmpname' - $!\n";
+	};
+	my $err = $@;
+
+	if ($err) {
+	    unlink $tmpname;
+	    die $err;
+	}
+
+	unlink $tmpname; # fixme: proxy to local host import
+
+	# fixme: return volid
+
+	return undef;
+
+    }});
+
 package PVE::API2::Nodes;
 
 use strict;

Modified: pve-manager/pve2/lib/PVE/API2.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2.pm	2011-02-11 09:37:26 UTC (rev 5507)
+++ pve-manager/pve2/lib/PVE/API2.pm	2011-02-11 09:39:54 UTC (rev 5508)
@@ -12,8 +12,8 @@
 use PVE::API2::VM;
 use PVE::API2::Cluster;
 use PVE::API2::Nodes;
-use PVE::API2::Storage;
 use PVE::API2::AccessControl;
+use PVE::API2::Storage::Config;
 
 __PACKAGE__->register_method ({
     subclass => "PVE::API2::VM",  
@@ -31,7 +31,7 @@
 });
 
 __PACKAGE__->register_method ({
-    subclass => "PVE::API2::Storage",  
+    subclass => "PVE::API2::Storage::Config",  
     path => 'storage',
 });
 

Modified: pve-manager/pve2/lib/PVE/REST.pm
===================================================================
--- pve-manager/pve2/lib/PVE/REST.pm	2011-02-11 09:37:26 UTC (rev 5507)
+++ pve-manager/pve2/lib/PVE/REST.pm	2011-02-11 09:39:54 UTC (rev 5508)
@@ -129,7 +129,7 @@
     } elsif ($format eq 'htmljs') {
 	# we use this for extjs file upload forms
 	$ct = 'text/html';
-	$raw =  encode_entities(to_json($data, {utf8 => 1, allow_nonref => 1}));
+	$raw = encode_entities(to_json($data, {utf8 => 1, allow_nonref => 1}));
     } else {
 	$ct = 'text/plain';
 	$raw = to_json($data, {utf8 => 1, allow_nonref => 1, pretty => 1});

Modified: pve-manager/pve2/www/manager/PVECache.js
===================================================================
--- pve-manager/pve2/www/manager/PVECache.js	2011-02-11 09:37:26 UTC (rev 5507)
+++ pve-manager/pve2/www/manager/PVECache.js	2011-02-11 09:39:54 UTC (rev 5508)
@@ -53,7 +53,7 @@
 		itype: 'storage',
 		idProperty: 'name',
 		autoDestroy: false,
-		url: '/api2/json/storage/index',
+		url: '/api2/json/cluster/storage',
 		fields: fields
 	    });
 

Modified: pve-manager/pve2/www/manager/StorageBrowser.js
===================================================================
--- pve-manager/pve2/www/manager/StorageBrowser.js	2011-02-11 09:37:26 UTC (rev 5507)
+++ pve-manager/pve2/www/manager/StorageBrowser.js	2011-02-11 09:39:54 UTC (rev 5508)
@@ -15,30 +15,32 @@
 	var params = ct ? { content: ct } : null;
 
 	var store = new Ext.data.JsonStore({
-	    url: "/api2/json/storage/content/" + node + "/" + storeid,
+	    url: "/api2/json/nodes/" + node + "/storage/" + storeid,
 	    autoDestory: true,
 	    autoLoad: true,
 	    root: 'data',
 	    restful: true, // use GET, not POST
 	    baseParams: params,
-	    fields: [ 'format', 'size', 'volname' ]
+	    fields: [ 'format', 'size', 'volid' ]
 	});
 
 	Ext.apply(self, {
 	    stateful: false,
 	    store: store,
+	    autoExpandColumn: 'volid',
 	    tbar: [
 		'->',
 		{
 		    xtype: 'form',
-		    url: '/api2/htmljs/storage/content/' + node + '/' + storeid,
+		    url: "/api2/htmljs/nodes/" + node + "/upload",
+		    baseParams:	{ storage: storeid },
 		    fileUpload: true,
 		    height: 22,
 		    border: false,
 		    baseCls: 'plain', 
 		    items: {
 			xtype: 'fileuploadfield',
-			name: 'upload',
+			name: 'filename',
 			buttonOnly: true,
 			buttonText: 'Upload',
 			listeners: {
@@ -67,26 +69,24 @@
  		    }
 		}
 	    ],	    
-	    colModel: new Ext.grid.ColumnModel({
-		columns: [
-		    {
-			header: 'Name',
-			width: 300,
-			dataIndex: 'volname'
-		    },
-		    {
-			header: 'Format',
-			width: 100,
-			dataIndex: 'format'
-		    },
-		    {
-			header: 'Size',
-			width: 100,
-			dataIndex: 'size'
-		    }
-		]
-	    }),
-	    viewConfig: { forceFit: true },	    
+	    columns: [
+		{
+		    id: 'volid',
+		    header: 'Name',
+		    dataIndex: 'volid'
+		},
+		{
+		    header: 'Format',
+		    width: 100,
+		    dataIndex: 'format'
+		},
+		{
+		    header: 'Size',
+		    width: 100,
+		    renderer: PVE.Utils.format_size,
+		    dataIndex: 'size'
+		}
+	    ],
 
 	    sm: new Ext.grid.RowSelectionModel({singleSelect:true})
 
@@ -109,23 +109,19 @@
 	if (!storeid)
 	    throw "no storage id specified";
 
-	var smid = Ext.util.base64.encode("storage.status." + node + '.' + storeid);  
-	var store = Ext.StoreMgr.lookup(smid);
+	var store = new PVE.data.ObjectStore({
+	    url: "/api2/json/nodes/" + node + "/storage/",
+	    baseParams: { storage: storeid },
+	    method: 'GET',
+	    restful: true, // use GET, not POST
+	    autoDestroy: true,
+	    rows: {
+		total: { header: 'Capacity' },
+		used: { header: 'Used' },
+		free: { header: 'Free' }
+	    }
+	});
 
-	if (!store) {
-	    store = new PVE.data.ObjectStore({
-		url: "/api2/json/storage/status/" + node + "/" + storeid,
-		method: 'GET',
-		id: smid,
-		simpleSelect: true,
-		rows: {
-		    total: { header: 'Capacity' },
-		    used: { header: 'Used' },
-		    free: { header: 'Free' }
-		}
-	    });
-	}
-
 	store.load();
 
 	Ext.apply(self, {
@@ -291,7 +287,7 @@
 	
 	if (!store) {
 	    store = new PVE.data.ObjectStore({
-		url: "/api2/json/storage/config/" + storeid,
+		url: "/api2/json/storage/" + storeid,
 		method: 'GET',
 		id: smid,
 		rows: {
@@ -299,7 +295,6 @@
 		    path: { header: 'Path' },
 		    shared: { header: 'Shared', renderer: PVE.Utils.format_boolean },
 		    disable: { header: 'Disabled', renderer: PVE.Utils.format_boolean },
-		    time: { header: 'TIME' },
 		    content: { header: 'Content', renderer: PVE.Utils.format_content_types }
 		}
 	    });

Modified: pve-manager/pve2/www/manager/data/ObjectReader.js
===================================================================
--- pve-manager/pve2/www/manager/data/ObjectReader.js	2011-02-11 09:37:26 UTC (rev 5507)
+++ pve-manager/pve2/www/manager/data/ObjectReader.js	2011-02-11 09:39:54 UTC (rev 5508)
@@ -1,7 +1,12 @@
 Ext.ns("PVE.data");
 
-// a reader to store a single JSON Object (hash) into a storage
-
+/* A reader to store a single JSON Object (hash) into a storage.
+ * Also accepts an array containing a single hash. 
+ * So it can read:
+ *
+ * example1: { data: "xyz" }
+ * example2: [ {  data: "xyz" } ]
+ */
 PVE.data.ObjectReader = Ext.extend(Ext.data.JsonReader, {
 
     constructor: function(config){
@@ -21,6 +26,13 @@
        if (returnRecords !== true)
 	    throw "not implemented";
 
+	if (Ext.isArray(root)) {
+	    if (root.length == 1)
+		root = root[0];
+	    else
+		root = {};
+	}
+
         var Record = this.recordType;
  	var rs = [];
 	var rows = this.rows;

Modified: pve-manager/pve2/www/manager/form/ModifyDirStorage.js
===================================================================
--- pve-manager/pve2/www/manager/form/ModifyDirStorage.js	2011-02-11 09:37:26 UTC (rev 5507)
+++ pve-manager/pve2/www/manager/form/ModifyDirStorage.js	2011-02-11 09:39:54 UTC (rev 5508)
@@ -68,7 +68,7 @@
 	// NOTE: If subclassing FormPanel, any configuration options for 
 	// the BasicForm must be applied to initialConfig
 	Ext.apply(self, Ext.apply(self.initialConfig, {
-	    url: "/api2/extjs/storage/config/" + storeid,
+	    url: "/api2/extjs/storage/" + storeid,
 	    method: 'PUT',
 
 	    items: {
@@ -98,7 +98,7 @@
 	var form = self.getForm();
 
 	form.load({
-	    url: "/api2/extjs/storage/config/" + storeid,
+	    url: "/api2/extjs/storage/" + storeid,
 	    method: 'GET'
 	});
 




More information about the pve-devel mailing list