[pve-devel] [PATCH v4 pve-manager 55/69] api: notification: disallow removing targets if they are used
Wolfgang Bumiller
w.bumiller at proxmox.com
Mon Jul 24 15:50:30 CEST 2023
On Thu, Jul 20, 2023 at 04:32:22PM +0200, Lukas Wagner wrote:
> Check notification targets configured in datacenter.cfg and jobs.cfg,
> failing if the group/endpoint to be removed is still in use there.
>
> Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
> ---
> PVE/API2/Cluster/Notifications.pm | 44 ++++++++++++++++++++++++++++++-
> 1 file changed, 43 insertions(+), 1 deletion(-)
>
> diff --git a/PVE/API2/Cluster/Notifications.pm b/PVE/API2/Cluster/Notifications.pm
> index fa2c1d9d..cf913452 100644
> --- a/PVE/API2/Cluster/Notifications.pm
> +++ b/PVE/API2/Cluster/Notifications.pm
> @@ -6,6 +6,7 @@ use strict;
> use Storable qw(dclone);
> use JSON;
>
> +use PVE::Exception qw(raise_param_exc);
> use PVE::Tools qw(extract_param);
> use PVE::JSONSchema qw(get_standard_option);
> use PVE::RESTHandler;
> @@ -55,6 +56,31 @@ sub raise_api_error {
> die $exc;
> }
>
> +sub target_used_by {
> + my ($target) = @_;
> +
> + my $used_by = [];
> +
> + # Check keys in datacenter.cfg
> + my $dc_conf = PVE::Cluster::cfs_read_file('datacenter.cfg');
> + for my $key (qw(target-package-updates target-replication target-fencing)) {
> + if ($dc_conf->{notify} && $dc_conf->{notify}->{$key} eq $target) {
> + push @$used_by, $key;
> + }
> + }
> +
> + # Check backup jobs
> + my $jobs_conf = PVE::Cluster::cfs_read_file('jobs.cfg');
I'm not exactly a big fan of requiring a function to know all the places
that might declare notification targets, but I suppose for now this is
"good enough".
If more of these get added we might need a better way, for instance we
could give other packages a way to register callbacks to collect this
information...
> + for my $key (keys %{$jobs_conf->{ids}}) {
> + my $job = $jobs_conf->{ids}->{$key};
> + if ($job->{'notification-target'} eq $target) {
> + push @$used_by, $key;
> + }
> + }
> +
> + return join(', ', @$used_by);
> +}
> +
> __PACKAGE__->register_method ({
> name => 'index',
> path => '',
More information about the pve-devel
mailing list