[pve-devel] [PATCH v1 pve-common 11/18] pbsclient: let `status` method return a hash instead of an array

Max Carrara m.carrara at proxmox.com
Fri Aug 2 15:26:49 CEST 2024


Instead of returning an (arguably awkward) array with four elements,
where each element has a special meaning, return the hash that is
constructed from the `proxmox-backup-client status` command's JSON
output.

The documentation is updated accordingly.

This method isn't used anywhere in our code base at the moment, so I
assume it is safe to change it. Checked with ripgrep.

Signed-off-by: Max Carrara <m.carrara at proxmox.com>
---
 src/PVE/PBSClient.pm | 32 ++++++++++----------------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/src/PVE/PBSClient.pm b/src/PVE/PBSClient.pm
index 69b4e40..26f73ef 100644
--- a/src/PVE/PBSClient.pm
+++ b/src/PVE/PBSClient.pm
@@ -731,36 +731,24 @@ sub prune_group {
 
 =head3 status
 
-    ($total, $free, $used, $active) = $client->status()
+    $status = $client->status()
 
-Return the I<status> of the client's repository as an array.
+Return the I<status> of the client's repository as a hash.
 
-The array contains the C<$total>, C<$free> and C<$used> size of the repository
-as bytes, as well as whether the repository is C<$active> or not.
+The returned hash has the following structure:
+
+    {
+	avail => 41735159808,  # sizes are in bytes!
+	total => 264240103424,
+	used => 41735159808,
+    }
 
 =cut
 
 sub status {
     my ($self) = @_;
 
-    my $total = 0;
-    my $free = 0;
-    my $used = 0;
-    my $active = 0;
-
-    eval {
-	my $res = run_client_cmd($self, "status");
-
-	$active = 1;
-	$total = $res->{total};
-	$used = $res->{used};
-	$free = $res->{avail};
-    };
-    if (my $err = $@) {
-	warn $err;
-    }
-
-    return ($total, $free, $used, $active);
+    return run_client_cmd($self, "status");
 };
 
 =pod
-- 
2.39.2





More information about the pve-devel mailing list