[pve-devel] r5505 - in pve-storage/pve2: . PVE/API2 PVE/API2/Storage
svn-commits at proxmox.com
svn-commits at proxmox.com
Fri Feb 11 08:14:52 CET 2011
Author: dietmar
Date: 2011-02-11 08:14:51 +0100 (Fri, 11 Feb 2011)
New Revision: 5505
Removed:
pve-storage/pve2/PVE/API2/Storage.pm
Modified:
pve-storage/pve2/ChangeLog
pve-storage/pve2/PVE/API2/Makefile
pve-storage/pve2/PVE/API2/Storage/Content.pm
pve-storage/pve2/PVE/API2/Storage/Scan.pm
pve-storage/pve2/PVE/API2/Storage/Status.pm
Log:
cleanup API Object hierarchiy
Modified: pve-storage/pve2/ChangeLog
===================================================================
--- pve-storage/pve2/ChangeLog 2011-02-11 05:19:00 UTC (rev 5504)
+++ pve-storage/pve2/ChangeLog 2011-02-11 07:14:51 UTC (rev 5505)
@@ -1,3 +1,9 @@
+2011-02-11 Proxmox Support Team <support at proxmox.com>
+
+ * PVE/API2/*: cleanup API Object hierarchiy
+
+ * PVE/API2/Storage.pm: removed (no longer needed)
+
2011-01-25 Proxmox Support Team <support at proxmox.com>
* PVE/Storage.pm: use new cfs_read_file/cfs_write_file everywhere
Modified: pve-storage/pve2/PVE/API2/Makefile
===================================================================
--- pve-storage/pve2/PVE/API2/Makefile 2011-02-11 05:19:00 UTC (rev 5504)
+++ pve-storage/pve2/PVE/API2/Makefile 2011-02-11 07:14:51 UTC (rev 5505)
@@ -2,5 +2,4 @@
.PHONY: install
install:
- install -D -m 0644 Storage.pm ${DESTDIR}${PERLDIR}/PVE/API2/Storage.pm
make -C Storage install
\ No newline at end of file
Modified: pve-storage/pve2/PVE/API2/Storage/Content.pm
===================================================================
--- pve-storage/pve2/PVE/API2/Storage/Content.pm 2011-02-11 05:19:00 UTC (rev 5504)
+++ pve-storage/pve2/PVE/API2/Storage/Content.pm 2011-02-11 07:14:51 UTC (rev 5505)
@@ -6,6 +6,7 @@
use PVE::SafeSyslog;
use PVE::Cluster qw(cfs_read_file);
use PVE::Storage;
+use PVE::INotify;
use PVE::Exception qw(raise_param_exc);
use PVE::RPCEnvironment;
use PVE::RESTHandler;
@@ -17,10 +18,11 @@
__PACKAGE__->register_method ({
name => 'index',
- protected => 1,
path => '',
method => 'GET',
description => "List storage content.",
+ protected => 1,
+ proxyto => 'node',
parameters => {
additionalProperties => 0,
properties => {
@@ -55,11 +57,8 @@
my $cts = $param->{content} ? [ $param->{content} ] : [ @ctypes ];
- my $node = $param->{node};
my $storeid = $param->{storage};
- # fixme: verify $node
-
my $cfg = cfs_read_file("storage.cfg");
my $scfg = PVE::Storage::storage_config ($cfg, $storeid);
@@ -70,11 +69,14 @@
if ($ct eq 'images') {
$data = PVE::Storage::vdisk_list ($cfg, $storeid, $param->{vmid});
} elsif ($ct eq 'iso') {
- $data = PVE::Storage::template_list ($cfg, $storeid, 'iso') if !$param->{vmid};
+ $data = PVE::Storage::template_list ($cfg, $storeid, 'iso')
+ if !$param->{vmid};
} elsif ($ct eq 'vztmpl') {
- $data = PVE::Storage::template_list ($cfg, $storeid, 'vztmpl') if !$param->{vmid};
+ $data = PVE::Storage::template_list ($cfg, $storeid, 'vztmpl')
+ if !$param->{vmid};
} elsif ($ct eq 'backup') {
- $data = PVE::Storage::template_list ($cfg, $storeid, 'backup') if !$param->{vmid};
+ $data = PVE::Storage::template_list ($cfg, $storeid, 'backup')
+ if !$param->{vmid};
}
next if !$data || !$data->{$storeid};
@@ -91,7 +93,9 @@
name => 'create',
path => '',
method => 'POST',
- description => "Allocate or upload content.",
+ description => "Allocate disk images.",
+ protected => 1,
+ proxyto => 'node',
parameters => {
additionalProperties => 0,
properties => {
@@ -106,7 +110,6 @@
type => 'string', format => 'pve-vmid',
requires => 'size',
},
- # fixme: size in bytes or KBytes?
size => {
description => "Size in kilobyte (1024 bytes). Optional suffixes 'M' (megabyte, 1024K) and 'G' (gigabyte, 1024M)",
type => 'string',
@@ -127,12 +130,6 @@
code => sub {
my ($param) = @_;
- # fixme: connect to node
- # fixme: can we proxy file uploads at all?
-
- my $cts = $param->{content} ? [ $param->{content} ] : [ @ctypes ];
-
- my $node = $param->{node};
my $storeid = $param->{storage};
my $name = $param->{filename};
my $sizestr = $param->{size};
@@ -195,10 +192,11 @@
__PACKAGE__->register_method ({
name => 'info',
- protected => 1,
path => '{volume}',
method => 'GET',
description => "Get volume attributes",
+ protected => 1,
+ proxyto => 'node',
parameters => {
additionalProperties => 0,
properties => {
@@ -214,8 +212,6 @@
code => sub {
my ($param) = @_;
- # fixme: connect to node
-
my $volid = &$real_volume_id($param->{storage}, $param->{volume});
my $cfg = cfs_read_file('storage.cfg');
@@ -233,10 +229,11 @@
__PACKAGE__->register_method ({
name => 'delete',
- protected => 1,
path => '{volume}',
method => 'DELETE',
description => "Delete volume",
+ protected => 1,
+ proxyto => 'node',
parameters => {
additionalProperties => 0,
properties => {
@@ -252,8 +249,6 @@
code => sub {
my ($param) = @_;
- # fixme: connect to node
-
my $volid = &$real_volume_id($param->{storage}, $param->{volume});
my $cfg = cfs_read_file('storage.cfg');
@@ -263,154 +258,4 @@
return undef;
}});
-# fixme: the following method can be use to implement copy/move/migrate/convert
-__PACKAGE__->register_method ({
- name => 'copy',
- protected => 1,
- path => '{volume}',
- method => 'POST',
- description => "Create copy of existing volume",
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- sourceNode => get_standard_option('pve-node', { optional => 1}),
- storage => get_standard_option('pve-storage-id', { optional => 1}),
- volume => {
- description => "Volume identifier",
- type => 'string',
- },
- source => {
- description => "Volume identifier",
- type => 'string',
- },
- move => {
- description => "Delete source after copy",
- type => 'boolean',
- }
- },
- },
- returns => { type => 'string' },
- code => sub {
- my ($param) = @_;
-
- # fixme: connect to node
-
- $param->{sourceNode} = $param->{node} if !$param->{sourceNode};
-
- my $volid = &$real_volume_id($param->{storage}, $param->{volume});
-
- eval { PVE::Storage::parse_volume_id ($param->{source}); };
- raise_param_exc({ source => $@}) if $@;
-
- my $cfg = cfs_read_file('storage.cfg');
-
- # fixme: execute in background
- print "COPY $param->{source} from node $param->{sourceNode} to $volid\n";
-
- # fixme: return taskID ?
- return "implement me";
- }});
-
-package PVE::API2::Storage::ContentIDList;
-
-use strict;
-use warnings;
-
-use PVE::SafeSyslog;
-use PVE::Cluster qw(cfs_read_file);
-use PVE::Storage;
-use PVE::JSONSchema qw(get_standard_option);
-
-use PVE::RESTHandler;
-
-use PVE::API2::Storage::Content;
-
-use base qw(PVE::RESTHandler);
-
-__PACKAGE__->register_method ({
- subclass => "PVE::API2::Storage::Content",
- # set fragment delimiter (no subdirs) - we need that, because volume
- # IDs may contain a slash '/'
- fragmentDelimiter => '',
- path => '{storage}',
-});
-
-__PACKAGE__->register_method ({
- name => 'index',
- path => '',
- method => 'GET',
- description => "List storage IDs.",
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => { storage => { type => 'string' } },
- },
- links => [ { rel => 'child', href => "{storage}" } ],
- },
- code => sub {
- my ($param) = @_;
-
- my $cfg = cfs_read_file("storage.cfg");
-
- my $node = $param->{node};
-
- # fixme: verify node (node exists)?
-
- my @sids = PVE::Storage::storage_ids ($cfg);
-
- my $res = [];
- foreach my $storeid (@sids) {
- # fixme: check if storeage exists on node ?
- push @$res, { storage => $storeid };
- }
-
- return $res;
- }});
-
-package PVE::API2::Storage::ContentNodeList;
-
-use strict;
-use warnings;
-
-use PVE::RESTHandler;
-use PVE::Cluster;
-
-use base qw(PVE::RESTHandler);
-
-__PACKAGE__->register_method ({
- subclass => "PVE::API2::Storage::ContentIDList",
- path => '{node}',
-});
-
-__PACKAGE__->register_method ({
- name => 'index',
- path => '',
- method => 'GET',
- description => "List cluster nodes.",
- parameters => {
- additionalProperties => 0,
- properties => {},
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => { node => { type => 'string' } },
- },
- links => [ { rel => 'child', href => "{node}" } ],
- },
- code => sub {
- my ($param) = @_;
-
- return PVE::Cluster::get_nodelist();
- }});
-
1;
Modified: pve-storage/pve2/PVE/API2/Storage/Scan.pm
===================================================================
--- pve-storage/pve2/PVE/API2/Storage/Scan.pm 2011-02-11 05:19:00 UTC (rev 5504)
+++ pve-storage/pve2/PVE/API2/Storage/Scan.pm 2011-02-11 07:14:51 UTC (rev 5505)
@@ -19,7 +19,9 @@
description => "Index of available scan methods",
parameters => {
additionalProperties => 0,
- properties => {},
+ properties => {
+ node => get_standard_option('pve-node'),
+ },
},
returns => {
type => 'array',
@@ -47,23 +49,23 @@
path => '{method:(lvm|iscsi|nfs)}',
method => 'GET',
description => "Scan remote storage server.",
+ protected => 1,
+ proxyto => "node",
parameters => {
additionalProperties => 0,
properties => {
+ node => get_standard_option('pve-node'),
method => {
type => 'string',
enum => [ 'lvm', 'nfs', 'iscsi' ],
},
server => { type => 'string', format => 'pve-storage-server' },
- node => get_standard_option('pve-node', { optional => 1 }),
},
},
returns => {},
code => sub {
my ($param) = @_;
- # fixme: proxy to node if requested
-
my $server = $param->{server};
my $method = $param->{method};
Modified: pve-storage/pve2/PVE/API2/Storage/Status.pm
===================================================================
--- pve-storage/pve2/PVE/API2/Storage/Status.pm 2011-02-11 05:19:00 UTC (rev 5504)
+++ pve-storage/pve2/PVE/API2/Storage/Status.pm 2011-02-11 07:14:51 UTC (rev 5505)
@@ -5,6 +5,7 @@
use PVE::Cluster qw(cfs_read_file);
use PVE::Storage;
+use PVE::API2::Storage::Content;
use PVE::RESTHandler;
use PVE::RPCEnvironment;
use PVE::JSONSchema qw(get_standard_option);
@@ -12,11 +13,20 @@
use base qw(PVE::RESTHandler);
__PACKAGE__->register_method ({
+ subclass => "PVE::API2::Storage::Content",
+ # set fragment delimiter (no subdirs) - we need that, because volume
+ # IDs may contain a slash '/'
+ fragmentDelimiter => '',
+ path => '{storage}',
+});
+
+__PACKAGE__->register_method ({
name => 'index',
- protected => 1,
path => '',
method => 'GET',
description => "Get status for all datastores.",
+ protected => 1,
+ proxyto => 'node',
parameters => {
additionalProperties => 0,
properties => {
@@ -34,86 +44,11 @@
code => sub {
my ($param) = @_;
- my $node = $param->{node};
-
- # fixme: verify $node
-
my $cfg = cfs_read_file("storage.cfg");
- # fixme: connect to correct node
-
my $info = PVE::Storage::storage_info ($cfg);
return PVE::RESTHandler::hash_to_array($info, 'storage');
}});
-__PACKAGE__->register_method ({
- name => 'status',
- protected => 1,
- path => '{storage}',
- method => 'GET',
- description => "Get status for specific datastore.",
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- storage => get_standard_option('pve-storage-id'),
- },
- },
- returns => {},
- code => sub {
- my ($param) = @_;
-
- my $node = $param->{node};
- my $storeid = $param->{storage};
-
- # fixme: verify $node
-
- my $cfg = cfs_read_file("storage.cfg");
-
- # fixme: connect to correct node
-
- my $info = PVE::Storage::storage_info ($cfg);
-
- return $info->{$storeid};
- }});
-
-package PVE::API2::Storage::StatusNodeList;
-
-use strict;
-use warnings;
-
-use PVE::RESTHandler;
-use PVE::Cluster;
-
-use base qw(PVE::RESTHandler);
-
-__PACKAGE__->register_method ({
- subclass => "PVE::API2::Storage::Status",
- path => '{node}',
-});
-
-__PACKAGE__->register_method ({
- name => 'index',
- path => '',
- method => 'GET',
- description => "List cluster nodes.",
- parameters => {
- additionalProperties => 0,
- properties => {},
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => { node => { type => 'string' } },
- },
- links => [ { rel => 'child', href => "{node}" } ],
- },
- code => sub {
- my ($param) = @_;
-
- return PVE::Cluster::get_nodelist();
- }});
-
1;
Deleted: pve-storage/pve2/PVE/API2/Storage.pm
===================================================================
--- pve-storage/pve2/PVE/API2/Storage.pm 2011-02-11 05:19:00 UTC (rev 5504)
+++ pve-storage/pve2/PVE/API2/Storage.pm 2011-02-11 07:14:51 UTC (rev 5505)
@@ -1,194 +0,0 @@
-package PVE::API2::Storage;
-
-use strict;
-use warnings;
-
-use PVE::SafeSyslog;
-use PVE::JSONSchema qw(get_standard_option);
-use PVE::Cluster;
-use PVE::Storage;
-use HTTP::Status qw(:constants);
-use Storable qw(dclone);
-use CGI;
-
-use PVE::API2::Storage::Config;
-use PVE::API2::Storage::Scan;
-use PVE::API2::Storage::Content;
-use PVE::API2::Storage::Status;
-
-use Data::Dumper; # fixme: remove
-
-use PVE::RESTHandler;
-
-use base qw(PVE::RESTHandler);
-
-my @ctypes = qw(images vztmpl iso backup);
-
-my $storage_type_enum = ['dir', 'nfs', 'lvm', 'iscsi'];
-
-__PACKAGE__->register_method ({
- subclass => "PVE::API2::Storage::Config",
- path => 'config',
-});
-
-__PACKAGE__->register_method ({
- subclass => "PVE::API2::Storage::Scan",
- path => 'scan',
-});
-
-__PACKAGE__->register_method ({
- subclass => "PVE::API2::Storage::ContentNodeList",
- path => 'content',
-});
-
-__PACKAGE__->register_method ({
- subclass => "PVE::API2::Storage::StatusNodeList",
- path => 'status',
-});
-
-# fixme: use subclass to generate index
-__PACKAGE__->register_method ({
- name => 'index',
- path => '',
- method => 'GET',
- description => "Storage index.",
- parameters => {
- additionalProperties => 0,
- properties => {},
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => { subdir => { type => 'string'} },
- },
- links => [ { rel => 'child', href => "{subdir}" } ],
- },
- code => sub {
- my ($param) = @_;
-
- my $res = [
- { subdir => 'config' },
- { subdir => 'status' },
- { subdir => 'content' },
- { subdir => 'index' },
- { subdir => 'upload' },
- { subdir => 'scan' },
- ];
- return $res;
- }});
-
-# fixme: choose a better name/path ?
-__PACKAGE__->register_method ({
- name => 'cluster_index',
- path => 'index',
- 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);
-
- my $res = [];
- foreach my $storeid (@sids) {
- my $scfg = PVE::Storage::storage_config ($cfg, $storeid);
- if ($scfg->{shared}) {
- my $data = { name => $storeid, storage => $storeid, type => $scfg->{type}, shared => 1};
- push @$res, $data;
- } else {
- # we create a entry for each node
- foreach my $nd (@$nodes) {
- my $node = $nd->{node};
- my $data = { name => "$storeid ($node)", storage => $storeid, node => $node,
- type => $scfg->{type}, shared => 0};
- push @$res, $data;
- }
- }
- }
-
- # $resp->{digest} = $cfg->{digest}; # fixme: how do we handle that
-
- return $res;
- }});
-
-__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 => {
- description => "Specify owner VM",
- type => 'string', format => 'pve-vmid',
- },
- },
- },
- returns => {
- description => "Volume identifier",
- type => 'string',
- },
- code => sub {
- my ($param) = @_;
-
- # fixme: move content to correct 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;
-
- }});
-
-1;
More information about the pve-devel
mailing list