public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH storage v2 3/4] Storage/Plugin: add get/update_volume_comment and implement for dir
Date: Tue, 24 Nov 2020 10:09:32 +0100	[thread overview]
Message-ID: <20201124090936.21810-5-d.csapak@proxmox.com> (raw)
In-Reply-To: <20201124090936.21810-1-d.csapak@proxmox.com>

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 | 63 +++++++++++++++++++++++++++++++++++--
 PVE/Storage.pm              | 20 ++++++++++++
 PVE/Storage/DirPlugin.pm    | 30 ++++++++++++++++++
 PVE/Storage/Plugin.pm       | 12 +++++++
 4 files changed, 123 insertions(+), 2 deletions(-)

diff --git a/PVE/API2/Storage/Content.pm b/PVE/API2/Storage/Content.pm
index 7b81171..eac6343 100644
--- a/PVE/API2/Storage/Content.pm
+++ b/PVE/API2/Storage/Content.pm
@@ -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 ({
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 8d904d7..aded60e 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -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) = @_;
 
diff --git a/PVE/Storage/DirPlugin.pm b/PVE/Storage/DirPlugin.pm
index 3c81d24..b36eec5 100644
--- a/PVE/Storage/DirPlugin.pm
+++ b/PVE/Storage/DirPlugin.pm
@@ -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) = @_;
 
diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index 1c86666..57c58a9 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -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);
-- 
2.20.1





  parent reply	other threads:[~2020-11-24  9:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-24  9:09 [pve-devel] [PATCH proxmox-backup/pve-storage/pve-manager v2] show/edit backup comments Dominik Csapak
2020-11-24  9:09 ` [pve-devel] [PATCH proxmox-backup v2 1/1] client: add 'snapshot notes show/update' command Dominik Csapak
2020-11-24  9:52   ` Wolfgang Bumiller
2020-11-24 12:28   ` [pve-devel] applied: [pbs-devel] " Dietmar Maurer
2020-11-24  9:09 ` [pve-devel] [PATCH storage v2 1/4] rename comment to notes Dominik Csapak
2020-11-24  9:09 ` [pve-devel] [PATCH storage v2 2/4] api2/storage/content: change to volume_size_info and add return properties Dominik Csapak
2020-11-24  9:09 ` Dominik Csapak [this message]
2020-11-24  9:09 ` [pve-devel] [PATCH storage v2 4/4] Storage/PBSPlugin: implement get/update_volume_notes for pbs Dominik Csapak
2020-11-24  9:09 ` [pve-devel] [PATCH manager v2 1/3] ui: change comment column to notes Dominik Csapak
2020-11-24  9:09 ` [pve-devel] [PATCH manager v2 2/3] ui: add ability to show and edit comments for backups Dominik Csapak
2020-11-24  9:09 ` [pve-devel] [PATCH manager v2 3/3] ui: enable notesedit for pbs Dominik Csapak
2021-03-25  8:22   ` [pve-devel] applied: " Thomas Lamprecht
2020-11-24 13:11 ` [pve-devel] applied-partially: [PATCH proxmox-backup/pve-storage/pve-manager v2] show/edit backup comments Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201124090936.21810-5-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal