From 290a96390a19f147f8b3d7a84642beab0ba69e1c Mon Sep 17 00:00:00 2001 From: Joel Rebello Date: Tue, 7 Apr 2020 10:40:17 +0200 Subject: [PATCH] Streamline the IsOn() method This fixes the IsOn() method to return false if the host is powered off, the previous implementation would return an error if the host is powered off. --- providers/dell/idrac8/actions.go | 7 ++++++- providers/dell/idrac9/actions.go | 7 ++++++- providers/hp/ilo/actions.go | 8 +++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/providers/dell/idrac8/actions.go b/providers/dell/idrac8/actions.go index 0719927f..d17c94e8 100644 --- a/providers/dell/idrac8/actions.go +++ b/providers/dell/idrac8/actions.go @@ -115,8 +115,13 @@ func (i *IDrac8) IsOn() (status bool, err error) { if err != nil { return false, fmt.Errorf("%v: %v", err, output) } + if strings.Contains(output, "Server power status: ON") { - return true, err + return true, nil + } + + if strings.Contains(output, "Server power status: OFF") { + return false, nil } return status, fmt.Errorf(output) diff --git a/providers/dell/idrac9/actions.go b/providers/dell/idrac9/actions.go index c4d9b95e..ee5dc06e 100644 --- a/providers/dell/idrac9/actions.go +++ b/providers/dell/idrac9/actions.go @@ -115,8 +115,13 @@ func (i *IDrac9) IsOn() (status bool, err error) { if err != nil { return false, fmt.Errorf("%v: %v", err, output) } + if strings.Contains(output, "Server power status: ON") { - return true, err + return true, nil + } + + if strings.Contains(output, "Server power status: OFF") { + return false, nil } return status, fmt.Errorf(output) diff --git a/providers/hp/ilo/actions.go b/providers/hp/ilo/actions.go index bba9dcaf..64a3e78b 100644 --- a/providers/hp/ilo/actions.go +++ b/providers/hp/ilo/actions.go @@ -117,9 +117,15 @@ func (i *Ilo) IsOn() (status bool, err error) { if err != nil { return false, fmt.Errorf("%v: %v", err, output) } + if strings.Contains(output, "currently: On") { - return true, err + return true, nil } + + if strings.Contains(output, "currently: Off") { + return true, nil + } + return status, fmt.Errorf(output) }