[pmg-devel] [PATCH common 2/2] PVE/Tools: add 'upid_get_status_type'
Dominik Csapak
d.csapak at proxmox.com
Thu Jun 24 09:10:11 CEST 2021
as a single point where we get the type of upid status
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/PVE/Tools.pm | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 8946e93..7cca4a4 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -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) = @_;
--
2.20.1
More information about the pmg-devel
mailing list