HewlettPackard / oneview-golang

Golang bindings for OneView api's
Apache License 2.0
27 stars 21 forks source link

GetIloIPAddress() does not work with GetServerHardwareList() #286

Closed mikeshapp closed 3 years ago

mikeshapp commented 3 years ago

I'm trying to get the ILO IP addresses for all servers returned by GetServerHardwareList()

Using:# go version go version go1.15.6 linux/amd64 OneView Client API Version: 2000

GetIloIPAddress() works with GetServerHardwareByName() because it sets the Client member:

    serverHardwareList.Members[0].Client = c

GetServerHardwareList() does not set the Client member for each server, leaving it as nil, so GetIloIPAddress() panics:

For example, these will panic in GetIloIPAddress() because the Client member is not set:

    filters := []string{""}
    ServerList, err := ovc.GetServerHardwareList(filters, "", "", "", "")
    for i := 0; i < ServerList.Total; i++ {
            iloIpaddress := ServerList.Members[i].GetIloIPAddress()
    }

OR

    filters := []string{""}
    ServerList, err := ovc.GetServerHardwareList(filters, "", "", "", "")
   for _, serverName := range ServerList.Members {
            iloIpaddress := serverName.GetIloIPAddress()
    }

I can workaround it by setting the Client member before using GetIloIPAddress() but it would be better to have it set in GetServerHardwareList():

This will display all the server ILO IP addresses returned by GetServerHardwareList():

    filters := []string{""}
    ServerList, err := ovc.GetServerHardwareList(filters, "", "", "", "")
    for i := 0; i < ServerList.Total; i++ {
            ServerList.Members[i].Client = ovc
    }
    for i := 0; i < ServerList.Total; i++ {
            iloIpaddress := ServerList.Members[i].GetIloIPAddress()
    }
AsisBagga commented 3 years ago

@mikeshapp Hi Mike, Thanks for pointing this out, this has been taken care in new PR, and changes will show up in coming release.

AsisBagga commented 3 years ago

Since this enhancement is added to source code, good to close the issue.

mikeshapp commented 3 years ago

I tested it with this code and it works correctly (no longer panics):

filters := []string{""} ServerList, err := ovc.GetServerHardwareList(filters, "", "", "", "") for _, serverName := range ServerList.Members { iloIpaddress := serverName.GetIloIPAddress() fmt.Printf("Server Name: %-30s ILO: %s\n", serverName.Name, iloIpaddress) }