diff --git a/providers/hp/ilo/ilo.go b/providers/hp/ilo/ilo.go index 577eb76f..b904041f 100644 --- a/providers/hp/ilo/ilo.go +++ b/providers/hp/ilo/ilo.go @@ -106,7 +106,7 @@ func (i *Ilo) CheckCredentials() (err error) { } // get calls a given json endpoint of the iLO and returns the data -func (i *Ilo) get(endpoint string) (payload []byte, err error) { +func (i *Ilo) get(endpoint string, useSession bool) (payload []byte, err error) { i.log.V(1).Info("retrieving data from bmc", "step", "bmc connection", "vendor", hp.VendorID, "ip", i.ip, "endpoint", endpoint) bmcURL := fmt.Sprintf("https://%s", i.ip) @@ -120,10 +120,14 @@ func (i *Ilo) get(endpoint string) (payload []byte, err error) { return payload, err } - for _, cookie := range i.httpClient.Jar.Cookies(u) { - if cookie.Name == "sessionKey" { - req.AddCookie(cookie) + if useSession { + for _, cookie := range i.httpClient.Jar.Cookies(u) { + if cookie.Name == "sessionKey" { + req.AddCookie(cookie) + } } + } else { + req.SetBasicAuth(i.username, i.password) } reqDump, _ := httputil.DumpRequestOut(req, true) @@ -200,7 +204,7 @@ func (i *Ilo) ChassisSerial() (string, error) { return "", err } - payload, err := i.get("json/rck_info") + payload, err := i.get("json/rck_info", true) if err != nil { return "", err } @@ -257,7 +261,7 @@ func (i *Ilo) Name() (name string, err error) { } url := "json/overview" - payload, err := i.get(url) + payload, err := i.get(url, true) if err != nil { return name, err } @@ -279,7 +283,7 @@ func (i *Ilo) Status() (health string, err error) { } url := "json/overview" - payload, err := i.get(url) + payload, err := i.get(url, true) if err != nil { return health, err } @@ -305,7 +309,7 @@ func (i *Ilo) Memory() (mem int, err error) { } url := "json/mem_info" - payload, err := i.get(url) + payload, err := i.get(url, true) if err != nil { return mem, err } @@ -335,7 +339,7 @@ func (i *Ilo) CPU() (cpu string, cpuCount int, coreCount int, hyperthreadCount i } url := "json/proc_info" - payload, err := i.get(url) + payload, err := i.get(url, true) if err != nil { return cpu, cpuCount, coreCount, hyperthreadCount, err } @@ -361,7 +365,7 @@ func (i *Ilo) BiosVersion() (version string, err error) { } url := "json/overview" - payload, err := i.get(url) + payload, err := i.get(url, true) if err != nil { return version, err } @@ -387,7 +391,7 @@ func (i *Ilo) PowerKw() (power float64, err error) { } url := "json/power_summary" - payload, err := i.get(url) + payload, err := i.get(url, true) if err != nil { return power, err } @@ -409,7 +413,7 @@ func (i *Ilo) PowerState() (state string, err error) { } url := "json/power_summary" - payload, err := i.get(url) + payload, err := i.get(url, true) if err != nil { return state, err } @@ -431,7 +435,7 @@ func (i *Ilo) TempC() (temp int, err error) { } url := "json/health_temperature" - payload, err := i.get(url) + payload, err := i.get(url, true) if err != nil { return temp, err } @@ -484,7 +488,7 @@ func (i *Ilo) License() (name string, licType string, err error) { } url := "json/license" - payload, err := i.get(url) + payload, err := i.get(url, true) if err != nil { return name, licType, err } @@ -506,7 +510,7 @@ func (i *Ilo) parseChassisInfo() (*hp.ChassisInfo, error) { chassisInfo := &hp.ChassisInfo{} // We try the new way of doing things first (RedFish). - payload, err := i.get(hp.ChassisInfoNewURL) + payload, err := i.get(hp.ChassisInfoNewURL, false) if err == nil { err = json.Unmarshal(payload, chassisInfo) if err != nil { @@ -534,7 +538,7 @@ func (i *Ilo) parseChassisInfo() (*hp.ChassisInfo, error) { } // This just means that we have to try the old way of doing things, since RedFish is not available. - payload, err = i.get(hp.ChassisInfoOldURL) + payload, err = i.get(hp.ChassisInfoOldURL, true) if err != nil { return nil, err } @@ -555,7 +559,7 @@ func (i *Ilo) Psus() (psus []*devices.Psu, err error) { } url := "json/power_supplies" - payload, err := i.get(url) + payload, err := i.get(url, true) if err != nil { return psus, err } @@ -598,7 +602,7 @@ func (i *Ilo) Disks() (disks []*devices.Disk, err error) { } url := "json/health_phy_drives" - payload, err := i.get(url) + payload, err := i.get(url, true) if err != nil { return disks, err } diff --git a/providers/hp/ilo/query.go b/providers/hp/ilo/query.go index 713d7db7..5e48eaf9 100644 --- a/providers/hp/ilo/query.go +++ b/providers/hp/ilo/query.go @@ -48,7 +48,7 @@ func (i *Ilo) Screenshot() (response []byte, extension string, err error) { return response, extension, errors.ErrFeatureUnavailable } - response, err = i.get(endpoint) + response, err = i.get(endpoint, true) if err != nil { return []byte{}, extension, err } @@ -60,7 +60,7 @@ func (i *Ilo) queryDirectoryGroups() (directoryGroups []DirectoryGroups, err err endpoint := "json/directory_groups" - payload, err := i.get(endpoint) + payload, err := i.get(endpoint, true) if err != nil { msg := "GET request failed." i.log.V(1).Info(msg, @@ -94,7 +94,7 @@ func (i *Ilo) queryUsers() (usersInfo []UserInfo, err error) { endpoint := "json/user_info" - payload, err := i.get(endpoint) + payload, err := i.get(endpoint, true) if err != nil { msg := "GET request failed." i.log.V(1).Info(msg, @@ -129,7 +129,7 @@ func (i *Ilo) queryNetworkSntp() (networkSntp NetworkSntp, err error) { endpoint := "json/network_sntp/interface/0" - payload, err := i.get(endpoint) + payload, err := i.get(endpoint, true) if err != nil { msg := "GET request failed." i.log.V(1).Info(msg, @@ -163,7 +163,7 @@ func (i *Ilo) queryAccessSettings() (AccessSettings, error) { var accessSettings AccessSettings - payload, err := i.get(endpoint) + payload, err := i.get(endpoint, true) if err != nil { msg := "GET request failed." i.log.V(1).Info(msg, @@ -197,7 +197,7 @@ func (i *Ilo) queryNetworkIPv4() (NetworkIPv4, error) { var networkIPv4 NetworkIPv4 - payload, err := i.get(endpoint) + payload, err := i.get(endpoint, true) if err != nil { msg := "GET request failed." i.log.V(1).Info(msg, @@ -231,7 +231,7 @@ func (i *Ilo) queryPowerRegulator() (PowerRegulator, error) { var powerRegulator PowerRegulator - payload, err := i.get(endpoint) + payload, err := i.get(endpoint, true) if err != nil { msg := "GET request failed." i.log.V(1).Info(msg,