Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

fix: relogin to master even if slave is used (issue #10) #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down