From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager 3/7] status/plugin: extend with add/update/delete hooks
Date: Wed, 2 Dec 2020 10:21:08 +0100 [thread overview]
Message-ID: <20201202092113.15911-6-d.csapak@proxmox.com> (raw)
In-Reply-To: <20201202092113.15911-1-d.csapak@proxmox.com>
like we do in it for the storage section configs
we will need this to store the token for influxdbs http api
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
PVE/API2/Cluster/MetricServer.pm | 39 +++++++++++++++++++++++++++-----
PVE/Status/Plugin.pm | 24 ++++++++++++++++++++
2 files changed, 57 insertions(+), 6 deletions(-)
diff --git a/PVE/API2/Cluster/MetricServer.pm b/PVE/API2/Cluster/MetricServer.pm
index ec3c7b75..a6b99d4f 100644
--- a/PVE/API2/Cluster/MetricServer.pm
+++ b/PVE/API2/Cluster/MetricServer.pm
@@ -3,7 +3,7 @@ package PVE::API2::Cluster::MetricServer;
use warnings;
use strict;
-use PVE::Tools qw(extract_param);
+use PVE::Tools qw(extract_param extract_sensitive_params);
use PVE::Exception qw(raise_perm_exc raise_param_exc);
use PVE::JSONSchema qw(get_standard_option);
use PVE::RPCEnvironment;
@@ -152,6 +152,8 @@ __PACKAGE__->register_method ({
my $plugin = PVE::Status::Plugin->lookup($type);
my $id = extract_param($param, 'id');
+ my $sensitive_params = extract_sensitive_params($param, ['token'], []);
+
PVE::Cluster::cfs_lock_file('status.cfg', undef, sub {
my $cfg = PVE::Cluster::cfs_read_file('status.cfg');
@@ -160,10 +162,20 @@ __PACKAGE__->register_method ({
my $opts = $plugin->check_config($id, $param, 1, 1);
- $plugin->test_connection($opts);
-
$cfg->{ids}->{$id} = $opts;
+ $plugin->on_add_hook($id, $opts, $sensitive_params);
+
+ eval {
+ $plugin->test_connection($opts, $id);
+ };
+
+ if (my $err = $@) {
+ eval { $plugin->on_delete_hook($id, $opts) };
+ warn "$@\n" if $@;
+ die $err;
+ }
+
PVE::Cluster::cfs_write_file('status.cfg', $cfg);
});
die $@ if $@;
@@ -190,6 +202,12 @@ __PACKAGE__->register_method ({
my $digest = extract_param($param, 'digest');
my $delete = extract_param($param, 'delete');
+ if ($delete) {
+ $delete = [PVE::Tools::split_list($delete)];
+ }
+
+ my $sensitive_params = extract_sensitive_params($param, ['token'], $delete);
+
PVE::Cluster::cfs_lock_file('status.cfg', undef, sub {
my $cfg = PVE::Cluster::cfs_read_file('status.cfg');
@@ -201,15 +219,13 @@ __PACKAGE__->register_method ({
my $plugin = PVE::Status::Plugin->lookup($data->{type});
my $opts = $plugin->check_config($id, $param, 0, 1);
- $plugin->test_connection($opts);
-
for my $k (keys %$opts) {
$data->{$k} = $opts->{$k};
}
if ($delete) {
my $options = $plugin->private()->{options}->{$data->{type}};
- for my $k (PVE::Tools::split_list($delete)) {
+ for my $k (@$delete) {
my $d = $options->{$k} || die "no such option '$k'\n";
die "unable to delete required option '$k'\n" if !$d->{optional};
die "unable to delete fixed option '$k'\n" if $d->{fixed};
@@ -220,6 +236,10 @@ __PACKAGE__->register_method ({
}
}
+ $plugin->on_update_hook($id, $data, $sensitive_params);
+
+ $plugin->test_connection($opts, $id);
+
PVE::Cluster::cfs_write_file('status.cfg', $cfg);
});
die $@ if $@;
@@ -253,6 +273,13 @@ __PACKAGE__->register_method ({
my $cfg = PVE::Cluster::cfs_read_file('status.cfg');
my $id = $param->{id};
+
+ my $plugin_cfg = $cfg->{ids}->{$id};
+
+ my $plugin = PVE::Status::Plugin->lookup($plugin_cfg->{type});
+
+ $plugin->on_delete_hook($id, $plugin_cfg);
+
delete $cfg->{ids}->{$id};
PVE::Cluster::cfs_write_file('status.cfg', $cfg);
});
diff --git a/PVE/Status/Plugin.pm b/PVE/Status/Plugin.pm
index 2fa223ca..fae7a0f0 100644
--- a/PVE/Status/Plugin.pm
+++ b/PVE/Status/Plugin.pm
@@ -153,4 +153,28 @@ sub update_storage_status {
die "please implement inside plugin";
}
+sub on_add_hook {
+ my ($class, $id, $opts, $sensitive_opts) = @_;
+
+ # implement in subclass
+
+ return undef;
+}
+
+sub on_update_hook {
+ my ($class, $id, $opts, $sensitive_opts) = @_;
+
+ # implement in subclass
+
+ return undef;
+}
+
+sub on_delete_hook {
+ my ($class, $id, $opts) = @_;
+
+ # implement in subclass
+
+ return undef;
+}
+
1;
--
2.20.1
next prev parent reply other threads:[~2020-12-02 9:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-02 9:21 [pve-devel] [PATCH common/storage/manager/docs] implement http api for influxdb status plugin Dominik Csapak
2020-12-02 9:21 ` [pve-devel] [PATCH common 1/1] tools: add extract_sensitive_params Dominik Csapak
2020-12-03 8:47 ` Thomas Lamprecht
2020-12-03 9:16 ` Wolfgang Bumiller
2020-12-03 9:35 ` Thomas Lamprecht
2020-12-03 15:52 ` [pve-devel] applied: " Thomas Lamprecht
2020-12-02 9:21 ` [pve-devel] [PATCH storage 1/1] api: storage/config: use extract_sensitive_params from tools Dominik Csapak
2021-01-28 16:31 ` [pve-devel] applied: " Thomas Lamprecht
2020-12-02 9:21 ` [pve-devel] [PATCH manager 1/7] api: cluster/metricserver: prevent simultaneosly setting and deleting of property Dominik Csapak
2020-12-03 9:05 ` Thomas Lamprecht
2020-12-04 11:30 ` Dominik Csapak
2020-12-04 11:57 ` Thomas Lamprecht
2020-12-04 12:45 ` Thomas Lamprecht
2020-12-02 9:21 ` [pve-devel] [PATCH manager 2/7] status/plugin: extend send/_connect/_disconnect/test_connection Dominik Csapak
2020-12-02 9:21 ` Dominik Csapak [this message]
2020-12-02 9:21 ` [pve-devel] [PATCH manager 4/7] status/influxdb: implement influxdb 2.x http api Dominik Csapak
2020-12-02 9:21 ` [pve-devel] [PATCH manager 5/7] status/influxdb: remove unnecessary comment Dominik Csapak
2020-12-02 9:21 ` [pve-devel] [PATCH manager 6/7] ui: add necessary fields for influxdb http api Dominik Csapak
2020-12-02 9:21 ` [pve-devel] [PATCH manager 7/7] ui: dc/MetricServerView: add onlineHelp to edit windows Dominik Csapak
2020-12-02 9:21 ` [pve-devel] [PATCH docs 1/1] external metrics server: extend docs to explain http api Dominik Csapak
2021-01-28 16:36 ` [pve-devel] applied-series: [PATCH common/storage/manager/docs] implement http api for influxdb status plugin 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=20201202092113.15911-6-d.csapak@proxmox.com \
--to=d.csapak@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