1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

F #2759: GOCA - add states methods for the host

This commit is contained in:
treywelsh 2019-01-14 11:21:04 +01:00 committed by Ruben S. Montero
parent eab7c21144
commit 6f59f41de2

View File

@ -1,5 +1,10 @@
package goca
import (
"errors"
"strconv"
)
// Host represents an OpenNebula Host
type Host struct {
XMLResource
@ -150,3 +155,24 @@ func (host *Host) Monitoring() error {
_, err := client.Call("one.host.monitoring", host.ID)
return err
}
// State returns the HostState
func (host *Host) State() (HostState, error) {
stateString, ok := host.XPath("/HOST/STATE")
if ok != true {
return -1, errors.New("Unable to parse host State")
}
state, _ := strconv.Atoi(stateString)
return HostState(state), nil
}
// StateString returns the HostState as string
func (host *Host) StateString() (string, error) {
state, err := host.State()
if err != nil {
return "", err
}
return HostState(state).String(), nil
}