Skip to content

Implement Redfish power-state retrieval and reset control#112

Merged
davidallendj merged 20 commits into
mainfrom
lritzdorf/power
Aug 14, 2025
Merged

Implement Redfish power-state retrieval and reset control#112
davidallendj merged 20 commits into
mainfrom
lritzdorf/power

Conversation

@LRitzdorf

@LRitzdorf LRitzdorf commented Jul 25, 2025

Copy link
Copy Markdown
Collaborator

This PR adds a new power subcommand, which has three functions:

  • Query node power states (default behavior)
  • Query supported Redfish reset types (-l flag)
  • Request that the node perform a particular type of reset (-r <ResetType> flag)

At the moment, this relies on the YAML output from the collect subcommand, but doesn't actually need most of the information — it just needs to be able to look up a node's BMC IP and its index within the BMC's Systems list, given an xname (or other ID). In the future, this could probably be accomplished via an SMD query, retaining SMD as the single source of truth.

Also, a bmc_index field is added to the InventoryDetail struct used by collect. This is used by power, and is also sent to SMD (though it should be ignored by the latter).

@LRitzdorf
LRitzdorf requested a review from davidallendj July 28, 2025 17:27
@davidallendj

davidallendj commented Jul 28, 2025

Copy link
Copy Markdown
Collaborator

Would you mind adding a few lines on how to use the command? I'm not sure

I'm trying the examples with magellan power --help and not exactly sure what the arguments should be. I'd assume the node ID should be something stored in SMD?

[allend@re-head magellan]$ ./magellan power x3000c0s0b0n0 -l
{"level":"info","time":"2025-07-28T13:23:03-06:00","message":"parsing default inventory file from 'collect': "}
{"level":"error","error":"open : no such file or directory","time":"2025-07-28T13:23:03-06:00","message":"failed to read collected inventory from "}
{"level":"error","error":"open : no such file or directory","time":"2025-07-28T13:23:03-06:00","message":"failed to parse inventory file "}

I can see that the x3000c0s0b0n0 node is stored in SMD with ochami smd component get -F json-pretty.

@LRitzdorf

Copy link
Copy Markdown
Collaborator Author

That's the correct syntax, but as the error logs show, it's trying to parse a nonexistent inventory file. That needs to be generated by collect, and the resulting filename passed to power via the -f/--inventory-file flag. This is how we obtain the node list for now — in the future, we'll likely want to query SMD directly, though I'm still looking into how exactly we can retrieve the information we need.

Comment thread cmd/power.go
Comment thread cmd/power.go Outdated
@LRitzdorf
LRitzdorf marked this pull request as ready for review July 31, 2025 21:14
@davidallendj

Copy link
Copy Markdown
Collaborator

Can you rebase with the latest changes to main?

Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
This avoids making the user guess, or (heaven forbid) manually curl
their BMCs, to determine which Redfish reset types are available.

Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
Shouldn't we be using Viper to get these, rather than assigning directly
to variables from Cobra `StringVar` flags?

Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
The new BMC_Index field is output by the crawler, and read by the power
tool.

Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
The config system here seems very half-baked; should ask someone more
familiar with how this is set up. It definitely feels like we're not
using Viper properly, though.

Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
Normally, we'd expect a ComputerSystem to live at e.g.
`/redfish/v1/Systems/1`, but that `1` is allowed to be a non-integer
value. We now support that.

Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
There's still a small hard-coded assumption of xname formatting present,
but at least the naming doesn't imply that only xnames are allowed.

Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
….yaml

Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
Comment thread cmd/power.go Outdated
Comment thread pkg/power/power.go Outdated
Comment thread pkg/crawler/main.go Outdated
Comment thread pkg/power/power.go
Comment thread pkg/power/power.go Outdated
Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
Signed-off-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
@davidallendj
davidallendj self-requested a review August 14, 2025 21:36

@davidallendj davidallendj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@davidallendj
davidallendj merged commit a46cdfa into main Aug 14, 2025
4 checks passed
@davidallendj
davidallendj deleted the lritzdorf/power branch August 14, 2025 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants