stmcginnis / gofish

Gofish is a Golang client library for DMTF Redfish and SNIA Swordfish interaction.
BSD 3-Clause "New" or "Revised" License
204 stars 109 forks source link

Allow to query individually an entry #341

Open Arno500 opened 2 months ago

Arno500 commented 2 months ago

I know it should not be done 80% of the time, but in specific cases I think there would be value in allowing to query only one element of a collection.

When we only need to change the state of one subelement when we know the naming/numbering is constant, forcing to query all the n entries is essentially a waste of time.

This can currently be bypassed by doing something like this:

var outlet gofishTypes.Outlet
err := rPdu.Get(rPdu.GetClient(), rPdu.ODataID+"/Outlets/"+outletId.String(), &outlet)

but I do not really like the idea and having a rPdu.Outlets.Get(outletId.String()) would be much better in my opinion!

What do you think?

stmcginnis commented 2 months ago

That makes sense. But I'll need to think a little about this to see how it could fit.

There are a couple other options. Assuming you've already retrieved all of the outputs, identified the outlet that you care about, and are doing additional updates to that object and just want to get a fresh instance of it, all objects have an ODataID. This can be used to get the object directly with something like:

myOutlet, err := redfish.GetOutlet(client, outlets[3].ODataID)

If you don't have the full collection of all outlet, but you know it will always be the same thing, you can basically do the same but just hardcode the URI. Basically with how you are doing it in the example you provided, but without needing to do the lower level Get() call directly.