From 900dada5eb27e07e7c797ca0b0ba23833c69c206 Mon Sep 17 00:00:00 2001 From: thebinary Date: Mon, 24 Jun 2019 11:46:38 +0545 Subject: [PATCH] fix: relogin to master even if slave is used --- client.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/client.go b/client.go index 225a5d1..b8eb9c2 100644 --- a/client.go +++ b/client.go @@ -45,6 +45,21 @@ func (client *XenAPIClient) Login() (err error) { err = client.RPCCall(&result, "session.login_with_password", params) if err == nil { + if resultError, ok := result["ErrorDescription"]; ok { + errorDescription := resultError.([]interface{}) + errorName := errorDescription[0] + + if errorName == "HOST_IS_SLAVE" { + master := errorDescription[1].(string) + + log.Infof("Host:%s is slave. Attempting relogin to master:%s", client.Host, master) + client.Host = master + client.Url = fmt.Sprintf("http://%s", master) + client.RPC, _ = xmlrpc.NewClient(client.Url, nil) + + return client.Login() + } + } // err might not be set properly, so check the reference if result["Value"] == nil { return errors.New("Invalid credentials supplied")