public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: "Dominic Jäger" <d.jaeger@proxmox.com>
Subject: [pve-devel] [PATCH cluster v2 1/1] dc.cfg: Add notes to datacenter config
Date: Wed, 22 Sep 2021 12:42:17 +0200	[thread overview]
Message-ID: <20210922104218.3398996-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210922104218.3398996-1-d.csapak@proxmox.com>

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





  reply	other threads:[~2021-09-22 10:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22 10:42 [pve-devel] [PATCH cluster/manager v2] add dc notes Dominik Csapak
2021-09-22 10:42 ` Dominik Csapak [this message]
2021-10-04  7:37   ` [pve-devel] applied: [PATCH cluster v2 1/1] dc.cfg: Add notes to datacenter config Thomas Lamprecht
2021-09-22 10:42 ` [pve-devel] [PATCH manager v2 1/1] ui: close #3504: Add datacenter notes Dominik Csapak
2021-11-09 17:42   ` [pve-devel] applied: " 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=20210922104218.3398996-2-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=d.jaeger@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal