]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
move common code to separate file
authorDietmar Maurer <dietmar@proxmox.com>
Sat, 6 Dec 2014 10:04:20 +0000 (11:04 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Sat, 6 Dec 2014 10:04:20 +0000 (11:04 +0100)
PVE/HA/Tools.pm [new file with mode: 0644]

diff --git a/PVE/HA/Tools.pm b/PVE/HA/Tools.pm
new file mode 100644 (file)
index 0000000..f78f66b
--- /dev/null
@@ -0,0 +1,32 @@
+package PVE::HA::Tools;
+
+use strict;
+use warnings;
+use JSON; 
+use PVE::Tools;
+
+sub read_json_from_file {
+    my ($filename, $default) = @_;
+
+    my $data;
+
+    if (defined($default) && (! -f $filename)) {
+       $data = $default;
+    } else {
+       my $raw = PVE::Tools::file_get_contents($filename);
+       $data = decode_json($raw);
+    }
+
+    return $data;
+}
+
+sub write_json_to_file {
+    my ($filename, $data) = @_;
+
+    my $raw = encode_json($data);
+    PVE::Tools::file_set_contents($filename, $raw);
+}
+
+
+1;