[pve-devel] r5051 - in pve-storage/pve2: . PVE/API2 PVE/API2/Storage
svn-commits at proxmox.com
svn-commits at proxmox.com
Wed Aug 25 14:02:59 CEST 2010
Author: dietmar
Date: 2010-08-25 12:02:59 +0000 (Wed, 25 Aug 2010)
New Revision: 5051
Modified:
pve-storage/pve2/ChangeLog
pve-storage/pve2/PVE/API2/Storage.pm
pve-storage/pve2/PVE/API2/Storage/Content.pm
pve-storage/pve2/Storage.pm
Log:
* PVE/API2/Storage.pm: create extra upload method, because this
have different 'proxy' requirements that normal 'create'
Modified: pve-storage/pve2/ChangeLog
===================================================================
--- pve-storage/pve2/ChangeLog 2010-08-25 11:57:23 UTC (rev 5050)
+++ pve-storage/pve2/ChangeLog 2010-08-25 12:02:59 UTC (rev 5051)
@@ -1,3 +1,8 @@
+2010-08-25 Proxmox Support Team <support at proxmox.com>
+
+ * PVE/API2/Storage.pm: create extra upload method, because this
+ have different 'proxy' requirements that normal 'create'
+
2010-08-24 Proxmox Support Team <support at proxmox.com>
* pvesm: use new PVE::RPCEnvironment
Modified: pve-storage/pve2/PVE/API2/Storage/Content.pm
===================================================================
--- pve-storage/pve2/PVE/API2/Storage/Content.pm 2010-08-25 11:57:23 UTC (rev 5050)
+++ pve-storage/pve2/PVE/API2/Storage/Content.pm 2010-08-25 12:02:59 UTC (rev 5051)
@@ -69,11 +69,11 @@
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');
+ $data = PVE::Storage::template_list ($cfg, $storeid, 'iso') if !$param->{vmid};
} elsif ($ct eq 'vztmpl') {
- $data = PVE::Storage::template_list ($cfg, $storeid, 'vztmpl');
+ $data = PVE::Storage::template_list ($cfg, $storeid, 'vztmpl') if !$param->{vmid};
} elsif ($ct eq 'backup') {
- $data = PVE::Storage::template_list ($cfg, $storeid, 'backup');
+ $data = PVE::Storage::template_list ($cfg, $storeid, 'backup') if !$param->{vmid};
}
next if !$data || !$data->{$storeid};
@@ -104,15 +104,12 @@
description => "Specify owner VM",
type => 'string', format => 'pve-vmid',
requires => 'size',
- optional => 1,
},
# fixme: size in bytes or KBytes?
size => {
description => "Size in kilobyte (1024 bytes). Optional suffixes 'M' (megabyte, 1024K) and 'G' (gigabyte, 1024M)",
type => 'string',
pattern => '\d+[MG]?',
- requires => 'vmid',
- optional => 1,
},
'format' => {
type => 'string',
@@ -137,73 +134,36 @@
my $node = $param->{node};
my $storeid = $param->{storage};
my $name = $param->{filename};
+ my $sizestr = $param->{size};
- if (defined($param->{size})) { # allocate
+ my $size;
+ if ($sizestr =~ m/^\d+$/) {
+ $size = $sizestr;
+ } elsif ($sizestr =~ m/^(\d+)M$/) {
+ $size = $1 * 1024;
+ } elsif ($sizestr =~ m/^(\d+)G$/) {
+ $size = $1 * 1024 * 1024;
+ } else {
+ raise_param_exc({ size => "unable to parse size '$sizestr'" });
+ }
- my $sizestr = $param->{size};
+ # extract FORMAT from name
+ if ($name =~ m/\.(raw|qcow2)$/) {
+ my $fmt = $1;
- my $size;
- if ($sizestr =~ m/^\d+$/) {
- $size = $sizestr;
- } elsif ($sizestr =~ m/^(\d+)M$/) {
- $size = $1 * 1024;
- } elsif ($sizestr =~ m/^(\d+)G$/) {
- $size = $1 * 1024 * 1024;
- } else {
- raise_param_exc({ size => "unable to parse size '$sizestr'" });
- }
+ raise_param_exc({ format => "different storage formats ($param->{format} != $fmt)" })
+ if $param->{format} && $param->{format} ne $fmt;
- # extract FORMAT from name
- if ($name =~ m/\.(raw|qcow2)$/) {
- my $fmt = $1;
+ $param->{format} = $fmt;
+ }
- raise_param_exc({ format => "different storage formats ($param->{format} != $fmt)" })
- if $param->{format} && $param->{format} ne $fmt;
-
- $param->{format} = $fmt;
- }
-
- my $cfg = read_file('storagecfg');
+ my $cfg = read_file('storagecfg');
- my $volid = PVE::Storage::vdisk_alloc ($cfg, $storeid, $param->{vmid},
- $param->{format},
- $name, $size);
+ my $volid = PVE::Storage::vdisk_alloc ($cfg, $storeid, $param->{vmid},
+ $param->{format},
+ $name, $size);
- return $volid;
- }
-
- # else we want to upload something
-
- 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;
-
+ return $volid;
}});
# we allow to pass volume names (without storage prefix) if the storage
Modified: pve-storage/pve2/PVE/API2/Storage.pm
===================================================================
--- pve-storage/pve2/PVE/API2/Storage.pm 2010-08-25 11:57:23 UTC (rev 5050)
+++ pve-storage/pve2/PVE/API2/Storage.pm 2010-08-25 12:02:59 UTC (rev 5051)
@@ -8,6 +8,7 @@
use PVE::Storage;
use HTTP::Status qw(:constants);
use Storable qw(dclone);
+use CGI;
use PVE::API2::Storage::Config;
use PVE::API2::Storage::Scan;
@@ -70,6 +71,7 @@
{ subdir => 'status' },
{ subdir => 'content' },
{ subdir => 'index' },
+ { subdir => 'upload' },
{ subdir => 'scan' },
];
return $res;
@@ -123,4 +125,69 @@
return $res;
}});
+__PACKAGE__->register_method ({
+ name => 'upload',
+ path => 'upload',
+ method => 'POST',
+ description => "Upload content.",
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => { type => 'string', format => 'pve-node' },
+ storage => { type => 'string', format => '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;
Modified: pve-storage/pve2/Storage.pm
===================================================================
--- pve-storage/pve2/Storage.pm 2010-08-25 11:57:23 UTC (rev 5050)
+++ pve-storage/pve2/Storage.pm 2010-08-25 12:02:59 UTC (rev 5051)
@@ -1264,6 +1264,7 @@
return int($vmid);
}
+PVE::JSONSchema::register_format('pve-volume-id', \&parse_volume_id);
sub parse_volume_id {
my ($volid, $noerr) = @_;
More information about the pve-devel
mailing list