From mboxrd@z Thu Jan 1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
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 DE6896C398
for <pve-devel@lists.proxmox.com>; Wed, 22 Sep 2021 12:42:20 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
by firstgate.proxmox.com (Proxmox) with ESMTP id DB079194B8
for <pve-devel@lists.proxmox.com>; Wed, 22 Sep 2021 12:42:20 +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 id 74B7B19498
for <pve-devel@lists.proxmox.com>; Wed, 22 Sep 2021 12:42:19 +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 44C5344A39;
Wed, 22 Sep 2021 12:42:19 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: =?UTF-8?q?Dominic=20J=C3=A4ger?= <d.jaeger@proxmox.com>
Date: Wed, 22 Sep 2021 12:42:17 +0200
Message-Id: <20210922104218.3398996-2-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20210922104218.3398996-1-d.csapak@proxmox.com>
References: <20210922104218.3398996-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results: 0
AWL 0.364 Adjusted score from AWL reputation of From: address
BAYES_00 -1.9 Bayes spam probability is 0 to 1%
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. [datacenterconfig.pm]
Subject: [pve-devel] [PATCH cluster v2 1/1] dc.cfg: Add notes to datacenter
config
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>,
<mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>,
<mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 22 Sep 2021 10:42:20 -0000
From: Dominic Jäger <d.jaeger@proxmox.com>
Similar to notes for nodes.
datacenter.cfg normally uses key-value pairs defined in the schema.
We bypass this to allow potentially long comments at the top.
Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
data/PVE/DataCenterConfig.pm | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/data/PVE/DataCenterConfig.pm b/data/PVE/DataCenterConfig.pm
index 24ebf3f..fa8ba4a 100644
--- a/data/PVE/DataCenterConfig.pm
+++ b/data/PVE/DataCenterConfig.pm
@@ -181,6 +181,13 @@ my $datacenter_schema = {
format => $u2f_format,
description => 'u2f',
},
+ description => {
+ type => 'string',
+ description => "Datacenter description. Shown in the web-interface datacenter notes panel."
+ ." This is saved as comment inside the configuration file.",
+ maxLength => 64 * 1024,
+ optional => 1,
+ },
},
};
@@ -190,8 +197,21 @@ sub get_datacenter_schema { return $datacenter_schema };
sub parse_datacenter_config {
my ($filename, $raw) = @_;
+ # description may be comment or key-value pair (or both)
+ my $comment = '';
+ my @lines = split(/\n/, $raw);
+ foreach my $line (@lines) {
+ if ($line =~ /^\#(.*)\s*$/) {
+ $comment .= PVE::Tools::decode_text($1) . "\n";
+ }
+ }
+
+ # parse_config ignores lines with # => use $raw
my $res = PVE::JSONSchema::parse_config($datacenter_schema, $filename, $raw // '');
+ $res->{description} = $comment;
+
+
if (my $migration = $res->{migration}) {
$res->{migration} = PVE::JSONSchema::parse_property_string($migration_format, $migration);
}
@@ -251,7 +271,16 @@ sub write_datacenter_config {
$cfg->{u2f} = PVE::JSONSchema::print_property_string($u2f, $u2f_format);
}
- return PVE::JSONSchema::dump_config($datacenter_schema, $filename, $cfg);
+ my $comment = '';
+ # add description as comment to top of file
+ my $description = $cfg->{description} || '';
+ foreach my $line (split(/\n/, $description)) {
+ $comment .= '#' . PVE::Tools::encode_text($line) . "\n";
+ }
+ delete $cfg->{description}; # add only as comment, no additional key-value pair
+ my $dump = PVE::JSONSchema::dump_config($datacenter_schema, $filename, $cfg);
+
+ return $comment . "\n" . $dump;
}
PVE::Cluster::cfs_register_file('datacenter.cfg',
--
2.30.2