]> git.proxmox.com Git - pve-common.git/commitdiff
PVE/Tools: add 'upid_get_status_type'
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 24 Jun 2021 07:10:11 +0000 (09:10 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 28 Jun 2021 12:47:53 +0000 (14:47 +0200)
as a single point where we get the type of upid status

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/PVE/Tools.pm

index 8946e93c6c1f1d8c22cf87533a1eb3cc2abe6a51..7cca4a48b5e9394f150844adaa81f9816c1a923b 100644 (file)
@@ -1179,6 +1179,26 @@ sub upid_status_is_error {
     return !($status eq 'OK' || $status =~ m/^WARNINGS: \d+$/);
 }
 
+# takes the parsed status and returns the type,
+# either ok, warning, error or unknown
+sub upid_get_status_type {
+    my ($status) = @_;
+
+    if (!$status) {
+       return 'unknown';
+    }
+
+    if ($status eq 'OK') {
+       return 'ok';
+    } elsif ($status =~ m/^WARNINGS: \d+$/) {
+       return 'warning';
+    } elsif ($status eq 'unexpected status') {
+       return 'unknown';
+    } else {
+       return 'error';
+    }
+}
+
 # useful functions to store comments in config files
 sub encode_text {
     my ($text) = @_;