]> git.proxmox.com Git - pve-storage.git/commitdiff
Storage/Plugin: add get/update_volume_comment and implement for dir
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 24 Nov 2020 09:09:32 +0000 (10:09 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 24 Nov 2020 09:23:25 +0000 (10:23 +0100)
and add the appropriate api call to set and get the comment
we need to bump APIVER for this and can bump APIAGE, since
we only use it at this new call that can work with the default
implementation

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/API2/Storage/Content.pm
PVE/Storage.pm
PVE/Storage/DirPlugin.pm
PVE/Storage/Plugin.pm

index 7b811715f9007873798cb8e5c1590d3f12b8c334..eac6343e86159ef884ba45ae0e57839174ddbf46 100644 (file)
@@ -285,6 +285,11 @@ __PACKAGE__->register_method ({
                description => "Format identifier ('raw', 'qcow2', 'subvol', 'iso', 'tgz' ...)",
                type => 'string',
            },
+           notes => {
+               description => "Optional notes.",
+               optional => 1,
+               type => 'string',
+           }
        },
     },
     code => sub {
@@ -303,13 +308,67 @@ __PACKAGE__->register_method ({
        my ($size, $format, $used, $parent) =  PVE::Storage::volume_size_info($cfg, $volid);
        die "volume_size_info on '$volid' failed\n" if !($format && $size);
 
-       # fixme: return more attributes?
-       return {
+       my $entry = {
            path => $path,
            size => $size,
             used => $used,
            format => $format,
        };
+
+       # not all storages/types support notes, so ignore errors here
+       eval {
+           my $notes = PVE::Storage::get_volume_notes($cfg, $volid);
+           $entry->{notes} = $notes if defined($notes);
+       };
+
+       return $entry;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'updateattributes',
+    path => '{volume}',
+    method => 'PUT',
+    description => "Update volume attributes",
+    permissions => {
+       description => "You need read access for the volume.",
+       user => 'all',
+    },
+    protected => 1,
+    proxyto => 'node',
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+           storage => get_standard_option('pve-storage-id', { optional => 1 }),
+           volume => {
+               description => "Volume identifier",
+               type => 'string',
+           },
+           notes => {
+               description => "The new notes.",
+               type => 'string',
+               optional => 1,
+           },
+       },
+    },
+    returns => { type => 'null' },
+    code => sub {
+       my ($param) = @_;
+
+       my $rpcenv = PVE::RPCEnvironment::get();
+       my $authuser = $rpcenv->get_user();
+
+       my ($volid, $storeid) = &$real_volume_id($param->{storage}, $param->{volume});
+
+       my $cfg = PVE::Storage::config();
+
+       PVE::Storage::check_volume_access($rpcenv, $authuser, $cfg, undef, $volid);
+
+       if (my $notes = $param->{notes}) {
+           PVE::Storage::update_volume_notes($cfg, $volid, $notes);
+       }
+
+       return undef;
     }});
 
 __PACKAGE__->register_method ({
index 8d904d74903e8af2d3780d24e6949c8b63e2ccf9..aded60e3747ae56c3c8eab6752568ea65ecb4ecc 100755 (executable)
@@ -217,6 +217,26 @@ sub file_size_info {
     return PVE::Storage::Plugin::file_size_info($filename, $timeout);
 }
 
+sub get_volume_notes {
+    my ($cfg, $volid, $timeout) = @_;
+
+    my ($storeid, $volname) = parse_volume_id($volid);
+    my $scfg = storage_config($cfg, $storeid);
+    my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+
+    return $plugin->get_volume_notes($scfg, $storeid, $volname, $timeout);
+}
+
+sub update_volume_notes {
+    my ($cfg, $volid, $notes, $timeout) = @_;
+
+    my ($storeid, $volname) = parse_volume_id($volid);
+    my $scfg = storage_config($cfg, $storeid);
+    my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+
+    $plugin->update_volume_notes($scfg, $storeid, $volname, $notes, $timeout);
+}
+
 sub volume_size_info {
     my ($cfg, $volid, $timeout) = @_;
 
index 3c81d24a98ca7cd2bb4f2e29b5768af5eb758147..b36eec5fc60605edffaf053fbb370cf466e4965c 100644 (file)
@@ -87,6 +87,36 @@ sub parse_is_mountpoint {
     return $is_mp; # contains a path
 }
 
+sub get_volume_notes {
+    my ($class, $scfg, $storeid, $volname, $timeout) = @_;
+    my $path = $class->filesystem_path($scfg, $volname);
+    $path .= $class->SUPER::NOTES_EXT;
+
+    my $notes = "";
+
+    if (-f $path) {
+       $notes = PVE::Tools::file_get_contents($path);
+    }
+
+    return $notes;
+}
+
+sub update_volume_notes {
+    my ($class, $scfg, $storeid, $volname, $notes, $timeout) = @_;
+    my $path = $class->filesystem_path($scfg, $volname);
+    my ($vtype, undef, undef, undef, undef, undef, undef) = $class->parse_volname($volname);
+
+    if ($vtype ne 'backup') {
+       die "only backups can have notes\n";
+    }
+
+    $path .= $class->SUPER::NOTES_EXT;
+
+    PVE::Tools::file_set_contents($path, $notes);
+
+    return undef;
+}
+
 sub status {
     my ($class, $storeid, $scfg, $cache) = @_;
 
index 1c8666661fc66e7f35f694522e4fad72e4f6f640..57c58a9de470c371eb87cc65be78323201e2654f 100644 (file)
@@ -826,6 +826,18 @@ sub file_size_info {
     return wantarray ? ($size, $format, $used, $parent, $st->ctime) : $size;
 }
 
+sub get_volume_notes {
+    my ($class, $scfg, $storeid, $volname, $timeout) = @_;
+
+    die "volume notes are not supported for $class";
+}
+
+sub update_volume_notes {
+    my ($class, $scfg, $storeid, $volname, $notes, $timeout) = @_;
+
+    die "volume notes are not supported for $class";
+}
+
 sub volume_size_info {
     my ($class, $scfg, $storeid, $volname, $timeout) = @_;
     my $path = $class->filesystem_path($scfg, $volname);