From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 2BF4961604 for ; Fri, 20 Nov 2020 10:51:22 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 231E2F6E9 for ; Fri, 20 Nov 2020 10:50:52 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id CFAB7F6DD for ; Fri, 20 Nov 2020 10:50:50 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9BAB943CF4 for ; Fri, 20 Nov 2020 10:50:50 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Fri, 20 Nov 2020 10:50:48 +0100 Message-Id: <20201120095049.15194-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201120095049.15194-1-d.csapak@proxmox.com> References: <20201120095049.15194-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.333 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [scan.pm, cluster.pm, hardware.pm, metricserverconfig.pm, services.pm] Subject: [pve-devel] [PATCH manager 3/4] api2/cluster: add 'metricserver' api endpoints X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Nov 2020 09:51:22 -0000 modeled after our typical api endpoints for sectionschema configs Signed-off-by: Dominik Csapak --- PVE/API2/Cluster.pm | 7 + PVE/API2/Makefile | 1 + PVE/API2/MetricServerConfig.pm | 238 +++++++++++++++++++++++++++++++++ 3 files changed, 246 insertions(+) create mode 100644 PVE/API2/MetricServerConfig.pm diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm index e768cbc6..4eb387b1 100644 --- a/PVE/API2/Cluster.pm +++ b/PVE/API2/Cluster.pm @@ -29,6 +29,7 @@ use PVE::API2::ClusterConfig; use PVE::API2::Firewall::Cluster; use PVE::API2::HAConfig; use PVE::API2::ReplicationConfig; +use PVE::API2::MetricServerConfig; my $have_sdn; eval { @@ -43,6 +44,11 @@ __PACKAGE__->register_method ({ path => 'replication', }); +__PACKAGE__->register_method ({ + subclass => "PVE::API2::MetricServerConfig", + path => 'metricserver', +}); + __PACKAGE__->register_method ({ subclass => "PVE::API2::ClusterConfig", path => 'config', @@ -132,6 +138,7 @@ __PACKAGE__->register_method ({ { name => 'config' }, { name => 'acme' }, { name => 'ceph' }, + { name => 'metricserver' }, ]; if ($have_sdn) { diff --git a/PVE/API2/Makefile b/PVE/API2/Makefile index bc5ccc36..fdadbc40 100644 --- a/PVE/API2/Makefile +++ b/PVE/API2/Makefile @@ -24,6 +24,7 @@ PERLSOURCE = \ NodeConfig.pm \ Scan.pm \ Hardware.pm \ + MetricServerConfig.pm \ Services.pm all: diff --git a/PVE/API2/MetricServerConfig.pm b/PVE/API2/MetricServerConfig.pm new file mode 100644 index 00000000..6d4df628 --- /dev/null +++ b/PVE/API2/MetricServerConfig.pm @@ -0,0 +1,238 @@ +package PVE::API2::MetricServerConfig; + +use warnings; +use strict; + +use PVE::Tools qw(extract_param); +use PVE::Exception qw(raise_perm_exc raise_param_exc); +use PVE::JSONSchema qw(get_standard_option); +use PVE::RPCEnvironment; +use PVE::ExtMetric; + +use PVE::RESTHandler; + +use base qw(PVE::RESTHandler); + +__PACKAGE__->register_method ({ + name => 'index', + path => '', + method => 'GET', + description => "List configured metric servers.", + permissions => { + check => ['perm', '/', ['Sys.Audit']], + }, + parameters => { + additionalProperties => 0, + properties => {}, + }, + returns => { + type => 'array', + items => { + type => "object", + properties => { + id => { + description => "The ID of the entry.", + type => 'string' + }, + disable => { + description => "Flag to disable the plugin.", + type => 'boolean', + }, + type => { + description => "Plugin type.", + type => 'string', + }, + server => { + description => "Server dns name or IP address", + type => 'string', + }, + port => { + description => "Server network port", + type => 'integer', + }, + }, + }, + links => [ { rel => 'child', href => "{id}" } ], + }, + code => sub { + my ($param) = @_; + + my $res = []; + my $status_cfg = PVE::Cluster::cfs_read_file('status.cfg'); + + for my $id (keys %{$status_cfg->{ids}}) { + my $plugin_config = $status_cfg->{ids}->{$id}; + push @$res, { + id => $id, + disable => $plugin_config->{disable} // 0, + type => $plugin_config->{type}, + server => $plugin_config->{server}, + port => $plugin_config->{port}, + }; + } + + return $res; + }}); + +__PACKAGE__->register_method ({ + name => 'read', + path => '{id}', + method => 'GET', + description => "Read replication job configuration.", + permissions => { + check => ['perm', '/', ['Sys.Audit']], + }, + parameters => { + additionalProperties => 0, + properties => { + id => { + type => 'string', + format => 'pve-configid', + }, + }, + }, + returns => { type => 'object' }, + code => sub { + my ($param) = @_; + + my $status_cfg = PVE::Cluster::cfs_read_file('status.cfg'); + my $id = $param->{id}; + + if (!defined($status_cfg->{ids}->{$id})) { + die "status server entry '$id' does not exist\n"; + } + + return $status_cfg->{ids}->{$id}; + }}); + +__PACKAGE__->register_method ({ + name => 'create', + path => '', + protected => 1, + method => 'POST', + description => "Create a new external metric server config", + permissions => { + check => ['perm', '/', ['Sys.Modify']], + }, + parameters => PVE::Status::Plugin->createSchema(), + returns => { type => 'null' }, + code => sub { + my ($param) = @_; + + my $type = extract_param($param, 'type'); + my $plugin = PVE::Status::Plugin->lookup($type); + my $id = extract_param($param, 'id'); + + my $code = sub { + my $cfg = PVE::Cluster::cfs_read_file('status.cfg'); + + die "Metric server '$id' already exists\n" + if $cfg->{ids}->{$id}; + + my $opts = $plugin->check_config($id, $param, 1, 1); + $cfg->{ids}->{$id} = $opts; + + PVE::Cluster::cfs_write_file('status.cfg', $cfg); + }; + + PVE::Cluster::cfs_lock_file('status.cfg', undef, $code); + die $@ if $@; + + return undef; + }}); + + +__PACKAGE__->register_method ({ + name => 'update', + protected => 1, + path => '{id}', + method => 'PUT', + description => "Update metric server configuration.", + permissions => { + check => ['perm', '/', ['Sys.Modify']], + }, + parameters => PVE::Status::Plugin->updateSchema(), + returns => { type => 'null' }, + code => sub { + my ($param) = @_; + + my $id = extract_param($param, 'id'); + my $digest = extract_param($param, 'digest'); + my $delete = extract_param($param, 'delete'); + + my $code = sub { + my $cfg = PVE::Cluster::cfs_read_file('status.cfg'); + + PVE::SectionConfig::assert_if_modified($cfg, $digest); + + my $data = $cfg->{ids}->{$id}; + die "no such server '$id'\n" if !$data; + + my $plugin = PVE::Status::Plugin->lookup($data->{type}); + my $opts = $plugin->check_config($id, $param, 0, 1); + + foreach my $k (%$opts) { + $data->{$k} = $opts->{$k}; + } + + if ($delete) { + my $options = $plugin->private()->{options}->{$data->{type}}; + foreach my $k (PVE::Tools::split_list($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}; + delete $data->{$k}; + } + } + + PVE::Cluster::cfs_write_file('status.cfg', $cfg); + }; + + PVE::Cluster::cfs_lock_file('status.cfg', undef, $code); + die $@ if $@; + + return undef; + }}); + +__PACKAGE__->register_method ({ + name => 'delete', + protected => 1, + path => '{id}', + method => 'DELETE', + description => "Remove Metric server.", + permissions => { + check => ['perm', '/', ['Sys.Modify']], + }, + parameters => { + additionalProperties => 0, + properties => { + id => { + type => 'string', + format => 'pve-configid', + }, + } + }, + returns => { type => 'null' }, + code => sub { + my ($param) = @_; + + my $rpcenv = PVE::RPCEnvironment::get(); + + my $code = sub { + my $cfg = PVE::Cluster::cfs_read_file('status.cfg'); + + my $id = $param->{id}; + delete $cfg->{ids}->{$id}; + PVE::Cluster::cfs_write_file('status.cfg', $cfg); + }; + + PVE::Cluster::cfs_lock_file('status.cfg', undef, $code); + die $@ if $@; + + return undef; + }}); + +1; -- 2.20.1