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 8406AF64E for ; Fri, 29 Sep 2023 15:02:05 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 65CAA16CF for ; Fri, 29 Sep 2023 15:02:05 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 for ; Fri, 29 Sep 2023 15:02:04 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4B802480F8 for ; Fri, 29 Sep 2023 15:02:04 +0200 (CEST) From: Aaron Lauterer To: pve-devel@lists.proxmox.com Date: Fri, 29 Sep 2023 15:02:01 +0200 Message-Id: <20230929130203.3902108-2-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230929130203.3902108-1-a.lauterer@proxmox.com> References: <20230929130203.3902108-1-a.lauterer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.078 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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. [cfg.pm] Subject: [pve-devel] [PATCH manager v4 1/3] api: ceph: add endpoint to fetch config keys 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, 29 Sep 2023 13:02:05 -0000 This new endpoint allows to get the values of config keys that are either set in the config db or the ceph.conf file. Values that are set in the ceph.conf file have priority over values set in the conifg db via 'ceph config set'. Expects the --config-keys parameter as a semicolon separated list of "
:" where the section is a section in the ceph.conf or config db. For example: global:osd_pool_default_size Signed-off-by: Aaron Lauterer --- changes since v3: * rebased v2: * fixed small typo v1: * use kebab-case parameter names * use kebab-case for the ceph config parameters, which also are returned that way * improve how we parse and merge the config db and ceph.conf file. This way though, we dont warn if we cannot find a config key. * renamed regex to make the distinctions clearer * dropped 'format => string-list' as it didn't work when leaving out [;, ] from the regex. But we don't need both. PVE/API2/Ceph/Cfg.pm | 82 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/PVE/API2/Ceph/Cfg.pm b/PVE/API2/Ceph/Cfg.pm index 2225a1ac..f06c42f4 100644 --- a/PVE/API2/Ceph/Cfg.pm +++ b/PVE/API2/Ceph/Cfg.pm @@ -4,6 +4,7 @@ use strict; use warnings; use PVE::Ceph::Tools; +use PVE::Cluster qw(cfs_read_file); use PVE::JSONSchema qw(get_standard_option); use PVE::RADOS; use PVE::Tools qw(file_get_contents); @@ -36,6 +37,7 @@ __PACKAGE__->register_method ({ my $result = [ { name => 'raw' }, { name => 'db' }, + { name => 'value' }, ]; return $result; @@ -110,3 +112,83 @@ __PACKAGE__->register_method ({ return $res; }}); + + +my $SINGLE_CONFIGKEY_RE = qr/[0-9a-z\-_\.]+:[0-9a-zA-Z\-_]+/i; +my $CONFIGKEYS_RE = qr/^(:?${SINGLE_CONFIGKEY_RE})(:?[;, ]${SINGLE_CONFIGKEY_RE})*$/; + +__PACKAGE__->register_method ({ + name => 'value', + path => 'value', + method => 'GET', + proxyto => 'node', + protected => 1, + permissions => { + check => ['perm', '/', [ 'Sys.Audit' ]], + }, + description => "Get configured values from either the config file or config DB.", + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + 'config-keys' => { + type => "string", + typetext => "
:[;
:]", + pattern => $CONFIGKEYS_RE, + description => "List of
: items.", + } + }, + }, + returns => { + type => 'object', + description => "Contains {section}->{key} children with the values", + }, + code => sub { + my ($param) = @_; + + PVE::Ceph::Tools::check_ceph_inited(); + + # Ceph treats '-' and '_' the same in parameter names, stick with '-' + my $normalize = sub { + my $t = shift; + $t =~ s/_/-/g; + return $t; + }; + + my $requested_keys = {}; + for my $pair (PVE::Tools::split_list($param->{'config-keys'})) { + my ($section, $key) = split(":", $pair); + $section = $normalize->($section); + $key = $normalize->($key); + + $requested_keys->{$section}->{$key} = 1; + } + + my $config = {}; + + my $rados = PVE::RADOS->new(); + my $configdb = $rados->mon_command( { prefix => 'config dump', format => 'json' }); + for my $s (@{$configdb}) { + my ($section, $name, $value) = $s->@{'section', 'name', 'value'}; + my $n_section = $normalize->($section); + my $n_name = $normalize->($name); + + $config->{$n_section}->{$n_name} = $value + if defined $requested_keys->{$n_section} && $n_name eq $n_name; + } + + # read ceph.conf after config db as it has priority if settings are present in both + my $config_file = cfs_read_file('ceph.conf'); # cfs_read_file to get it parsed + for my $section (keys %{$config_file}) { + my $n_section = $normalize->($section); + next if !defined $requested_keys->{$n_section}; + + for my $key (keys %{$config_file->{$section}}) { + my $n_key = $normalize->($key); + $config->{$n_section}->{$n_key} = $config_file->{$section}->{$key} + if $requested_keys->{$n_section}->{$n_key}; + } + } + + return $config; + }}); -- 2.39.2