use PVE::Tools;
use PVE::INotify;
use PVE::Cluster;
+use PVE::RRD;
use PVE::Storage;
use PVE::API2::Storage::Content;
use PVE::RESTHandler;
use base qw(PVE::RESTHandler);
__PACKAGE__->register_method ({
- subclass => "PVE::API2::Storage::Content",
+ subclass => "PVE::API2::Storage::Content",
# set fragment delimiter (no subdirs) - we need that, because volume
- # IDs may contain a slash '/'
- fragmentDelimiter => '',
+ # IDs may contain a slash '/'
+ fragmentDelimiter => '',
path => '{storage}/content',
});
__PACKAGE__->register_method ({
- name => 'index',
+ name => 'index',
path => '',
method => 'GET',
description => "Get status for all datastores.",
- permissions => {
+ permissions => {
description => "Only list entries where you have 'Datastore.Audit' or 'Datastore.AllocateSpace' permissions on '/storage/<storage>'",
user => 'all',
},
optional => 1,
completion => \&PVE::Storage::complete_storage_enabled,
}),
- content => {
+ content => {
description => "Only list stores which support this content type.",
type => 'string', format => 'pve-storage-content-list',
optional => 1,
__PACKAGE__->register_method ({
name => 'diridx',
- path => '{storage}',
+ path => '{storage}',
method => 'GET',
description => "",
- permissions => {
+ permissions => {
check => ['perm', '/storage/{storage}', ['Datastore.Audit', 'Datastore.AllocateSpace'], any => 1],
},
parameters => {
{ subdir => 'upload' },
{ subdir => 'rrd' },
{ subdir => 'rrddata' },
- ];
-
+ ];
+
return $res;
}});
__PACKAGE__->register_method ({
name => 'read_status',
- path => '{storage}/status',
+ path => '{storage}/status',
method => 'GET',
description => "Read storage status.",
- permissions => {
+ permissions => {
check => ['perm', '/storage/{storage}', ['Datastore.Audit', 'Datastore.AllocateSpace'], any => 1],
},
protected => 1,
raise_param_exc({ storage => "No such storage." })
if !defined($data);
-
+
return $data;
}});
__PACKAGE__->register_method ({
name => 'rrd',
- path => '{storage}/rrd',
+ path => '{storage}/rrd',
method => 'GET',
description => "Read storage RRD statistics (returns PNG).",
- permissions => {
+ permissions => {
check => ['perm', '/storage/{storage}', ['Datastore.Audit', 'Datastore.AllocateSpace'], any => 1],
},
protected => 1,
code => sub {
my ($param) = @_;
- return PVE::Cluster::create_rrd_graph(
- "pve2-storage/$param->{node}/$param->{storage}",
+ return PVE::RRD::create_rrd_graph(
+ "pve2-storage/$param->{node}/$param->{storage}",
$param->{timeframe}, $param->{ds}, $param->{cf});
-
}});
__PACKAGE__->register_method ({
name => 'rrddata',
- path => '{storage}/rrddata',
+ path => '{storage}/rrddata',
method => 'GET',
description => "Read storage RRD statistics.",
- permissions => {
+ permissions => {
check => ['perm', '/storage/{storage}', ['Datastore.Audit', 'Datastore.AllocateSpace'], any => 1],
},
protected => 1,
code => sub {
my ($param) = @_;
- return PVE::Cluster::create_rrd_data(
- "pve2-storage/$param->{node}/$param->{storage}",
- $param->{timeframe}, $param->{cf});
+ return PVE::RRD::create_rrd_data(
+ "pve2-storage/$param->{node}/$param->{storage}",
+ $param->{timeframe}, $param->{cf});
}});
-# makes no sense for big images and backup files (because it
+# makes no sense for big images and backup files (because it
# create a copy of the file).
__PACKAGE__->register_method ({
name => 'upload',
- path => '{storage}/upload',
+ path => '{storage}/upload',
method => 'POST',
description => "Upload templates and ISO images.",
- permissions => {
+ permissions => {
check => ['perm', '/storage/{storage}', ['Datastore.AllocateTemplate']],
},
protected => 1,
properties => {
node => get_standard_option('pve-node'),
storage => get_standard_option('pve-storage-id'),
- content => {
+ content => {
description => "Content type.",
type => 'string', format => 'pve-storage-content',
},
- filename => {
+ filename => {
description => "The name of the file to create.",
type => 'string',
},
- tmpfilename => {
+ tmpfilename => {
description => "The source file name. This parameter is usually set by the REST handler. You can only overwrite it when connecting to the trusted port on localhost.",
type => 'string',
optional => 1,
die "missing temporary file name\n" if !$tmpfilename;
my $size = -s $tmpfilename;
- die "temporary file '$tmpfilename' does not exists\n" if !defined($size);
+ die "temporary file '$tmpfilename' does not exist\n" if !defined($size);
my $filename = $param->{filename};
my $path;
if ($content eq 'iso') {
- if ($filename !~ m![^/]+\.[Ii][Ss][Oo]$!) {
- raise_param_exc({ filename => "missing '.iso' extension" });
+ if ($filename !~ m![^/]+$PVE::Storage::iso_extension_re$!) {
+ raise_param_exc({ filename => "missing '.iso' or '.img' extension" });
}
$path = PVE::Storage::get_iso_dir($cfg, $param->{storage});
} elsif ($content eq 'vztmpl') {
# best effort to match apl_download behaviour
chmod 0644, $tmpfilename;
- # we simply overwrite when destination file already exists
+ # we simply overwrite the destination file if it already exists
my $cmd;
if ($node ne 'localhost' && $node ne PVE::INotify::nodename()) {
my @remcmd = ('/usr/bin/ssh', @ssh_options, $remip, '--');
- eval {
+ eval {
# activate remote storage
- PVE::Tools::run_command([@remcmd, '/usr/sbin/pvesm', 'status',
- '--storage', $param->{storage}]);
+ PVE::Tools::run_command([@remcmd, '/usr/sbin/pvesm', 'status',
+ '--storage', $param->{storage}]);
};
die "can't activate storage '$param->{storage}' on node '$node': $@\n" if $@;
$cmd = ['cp', '--', $tmpfilename, $dest];
}
- my $worker = sub {
+ my $worker = sub {
my $upid = shift;
-
+
print "starting file import from: $tmpfilename\n";
print "target node: $node\n";
print "target file: $dest\n";
return $upid;
}});
-
+
1;