From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH common] properly encode YAML via YAML::XS
Date: Thu, 17 Sep 2020 13:16:58 +0200 [thread overview]
Message-ID: <20200917111658.1358831-1-f.gruenbichler@proxmox.com> (raw)
otherwise we get strange errors when formatting data that was originally
JSON, and can thus contain JSON::true/JSON::false.
one example is the QMP query-blockstats command, which gets called (and
the resulting values returned) by /nodes/NODE/qemu/VMID/status/current
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
Notes:
alternatives include:
- dropping --output-format yaml altogether
- manually recursively mapping JSON::true/false to some sensible value before dumping
- outputting JSON instead of YAML, since the former is a subset of the latter (thanks Dominik ;))
https://forum.proxmox.com/threads/yaml-issues-with-pvesh.76017/
debian/control | 1 +
src/PVE/CLIFormatter.pm | 7 ++++---
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/debian/control b/debian/control
index 4aa95ed..d7508f5 100644
--- a/debian/control
+++ b/debian/control
@@ -34,6 +34,7 @@ Depends: libclone-perl,
libtimedate-perl,
liburi-perl,
libwww-perl,
+ libyaml-libyaml-perl,
${misc:Depends},
${perl:Depends},
Breaks: ifupdown2 (<< 2.0.1-1+pve5),
diff --git a/src/PVE/CLIFormatter.pm b/src/PVE/CLIFormatter.pm
index 4f18fa9..ccecfc3 100644
--- a/src/PVE/CLIFormatter.pm
+++ b/src/PVE/CLIFormatter.pm
@@ -5,7 +5,8 @@ use warnings;
use I18N::Langinfo;
use POSIX qw(strftime);
-use CPAN::Meta::YAML; # comes with perl-modules
+use YAML::XS; # supports Dumping JSON::PP::Boolean
+$YAML::XS::Boolean = "JSON::PP";
use PVE::JSONSchema;
use PVE::PTY;
@@ -87,7 +88,7 @@ PVE::JSONSchema::register_renderer('bytes', \&render_bytes);
sub render_yaml {
my ($value) = @_;
- my $data = CPAN::Meta::YAML::Dump($value);
+ my $data = YAML::XS::Dump($value);
$data =~ s/^---[\n\s]//; # remove yaml marker
return $data;
@@ -440,7 +441,7 @@ sub print_api_result {
}
if ($format eq 'yaml') {
- print encode('UTF-8', CPAN::Meta::YAML::Dump($data));
+ print encode('UTF-8', YAML::XS::Dump($data));
} elsif ($format eq 'json') {
# Note: we always use utf8 encoding for json format
print to_json($data, {utf8 => 1, allow_nonref => 1, canonical => 1 }) . "\n";
--
2.20.1
next reply other threads:[~2020-09-17 11:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-17 11:16 Fabian Grünbichler [this message]
2020-09-17 15:06 ` Thomas Lamprecht
2020-09-18 7:13 ` Fabian Grünbichler
2020-09-18 12:35 ` Thomas Lamprecht
2020-09-18 12:36 ` [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=20200917111658.1358831-1-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.