From: Fabian Grünbichler Date: Wed, 10 Oct 2018 11:55:03 +0000 (+0200) Subject: Tools/Config: refactor lrm status json reading X-Git-Url: https://git.proxmox.com/?p=pve-ha-manager.git;a=commitdiff_plain;h=6529b6a4e2dbf14c930b9d85495b92456a4d5399 Tools/Config: refactor lrm status json reading to avoid unnecessary dependency on PVE::Cluster in PVE::HA::Tools. reading the LRM status file was the only instance of reading from the CFS via this method. Signed-off-by: Fabian Grünbichler --- diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm index 5de4779..5660d19 100644 --- a/src/PVE/HA/Config.pm +++ b/src/PVE/HA/Config.pm @@ -48,9 +48,13 @@ sub read_lrm_status { die "undefined node" if !defined($node); - my $filename = "/etc/pve/nodes/$node/lrm_status"; + my $cfs_path = "nodes/$node/lrm_status"; + + my $raw = PVE::Cluster::get_config($cfs_path); + die "unable to read file '/etc/pve/$cfs_path'\n" + if !defined($raw); - return PVE::HA::Tools::read_json_from_file($filename, {}); + return json_reader(undef, $raw); } sub write_lrm_status { diff --git a/src/PVE/HA/Tools.pm b/src/PVE/HA/Tools.pm index 88f775e..2bdd6ea 100644 --- a/src/PVE/HA/Tools.pm +++ b/src/PVE/HA/Tools.pm @@ -124,16 +124,7 @@ sub read_json_from_file { if (defined($default) && (! -f $filename)) { $data = $default; } else { - my $raw; - # workaround for bug #775 - if ($filename =~ m|^/etc/pve/|) { - $filename =~ s|^/etc/pve/+||; - $raw = PVE::Cluster::get_config($filename); - die "unable to read file '/etc/pve/$filename'\n" - if !defined($raw); - } else { - $raw = PVE::Tools::file_get_contents($filename); - } + my $raw = PVE::Tools::file_get_contents($filename); $data = decode_json($raw); }