-
Notifications
You must be signed in to change notification settings - Fork 82
Return of ipmi #3373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Return of ipmi #3373
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c0f4e0a
Translated IPMI "class" from ruby to rust
mchf 2fc8747
Hooked Ipmi calls into the manager service
mchf c976c6c
Added forgotten file with ipmi "class" implementation
mchf e0bd389
Formatting
mchf 8f74a32
Minor refactoring
mchf 5ee5314
Reorganized code
mchf f7429a7
Improvements based on the review
mchf d956460
Merge branch 'master' into return-of-ipmi
mchf d6ac1c1
Modifications according to clippy
mchf 5d04e6c
Fixed typos
mchf 20c643f
Updated changelog
mchf 952f37d
Merge branch 'master' into return-of-ipmi
mchf f0a24a5
Changed wording
mchf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // Copyright (c) [2026] SUSE LLC | ||
| // | ||
| // All Rights Reserved. | ||
| // | ||
| // This program is free software; you can redistribute it and/or modify it | ||
| // under the terms of the GNU General Public License as published by the Free | ||
| // Software Foundation; either version 2 of the License, or (at your option) | ||
| // any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, but WITHOUT | ||
| // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| // more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License along | ||
| // with this program; if not, contact SUSE LLC. | ||
| // | ||
| // To contact SUSE LLC about this file by physical or electronic mail, you may | ||
| // find current contact information at www.suse.com. | ||
|
|
||
| use std::fs; | ||
| use std::io::Write; | ||
| use std::path::{Path, PathBuf}; | ||
| use std::process::Command; | ||
| use tempfile::NamedTempFile; | ||
|
|
||
| #[derive(thiserror::Error, Debug)] | ||
| pub enum Error { | ||
| #[error("ipmitool not found")] | ||
| Tool { desc: String }, | ||
| #[error("ipmitool command call failed")] | ||
| Command { desc: String }, | ||
| } | ||
|
|
||
| pub struct Ipmi { | ||
| tool: PathBuf, | ||
| device: PathBuf, | ||
| } | ||
|
|
||
| impl Ipmi { | ||
| const IPMI_STARTED: u8 = 0x07; | ||
| const IPMI_FINISHED: u8 = 0x08; | ||
| const IPMI_ABORTED: u8 = 0x09; | ||
| const IPMI_FAILED: u8 = 0x0A; | ||
|
|
||
| pub fn new(dev: &Path, tool: &Path) -> Self { | ||
| let instance = Self { | ||
| tool: tool.to_path_buf(), | ||
| device: dev.to_path_buf(), | ||
| }; | ||
|
|
||
| tracing::info!("IPMI available: {}", instance.is_available()); | ||
|
|
||
| instance | ||
| } | ||
|
|
||
| pub fn started(&self) -> Result<(), Error> { | ||
| self.send_command(Self::IPMI_STARTED) | ||
| } | ||
|
|
||
| pub fn finished(&self) -> Result<(), Error> { | ||
| self.send_command(Self::IPMI_FINISHED) | ||
| } | ||
|
|
||
| pub fn aborted(&self) -> Result<(), Error> { | ||
| self.send_command(Self::IPMI_ABORTED) | ||
| } | ||
|
|
||
| pub fn failed(&self) -> Result<(), Error> { | ||
| self.send_command(Self::IPMI_FAILED) | ||
| } | ||
|
|
||
| fn is_available(&self) -> bool { | ||
| fs::metadata(&self.device).is_ok() && fs::metadata(&self.tool).is_ok() | ||
| } | ||
|
|
||
| fn send_command(&self, code: u8) -> Result<(), Error> { | ||
| if !self.is_available() { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| // Create a temporary file that is automatically deleted | ||
| let mut file = match NamedTempFile::new() { | ||
| Ok(f) => f, | ||
| Err(e) => { | ||
| return Err(Error::Tool { | ||
| desc: format!("ipmitool failed, cannot create temporary event file. {}", e), | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| // Write the event string | ||
| let content = format!("0x04 0x1F 0x00 0x6f 0x{:02x} 0x00 0x00\n", code); | ||
|
|
||
| if file.write_all(content.as_bytes()).is_err() { | ||
| return Err(Error::Tool { | ||
| desc: "ipmitool failed, cannot create event file".to_string(), | ||
| }); | ||
| } | ||
|
|
||
| // Execute ipmitool | ||
| let status = Command::new(&self.tool) | ||
| .arg("event") | ||
| .arg("file") | ||
| .arg(file.path()) | ||
| .status(); | ||
|
|
||
| match status { | ||
| Ok(s) => { | ||
| if !s.success() { | ||
| Err(Error::Command { | ||
| desc: format!("ipmitool failed, exit code: {:?}", s.code()), | ||
| }) | ||
| } else { | ||
| Ok(()) | ||
| } | ||
| } | ||
| Err(e) => Err(Error::Command { | ||
| desc: format!("ipmitool failed, status: {}", e), | ||
| }), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Default for Ipmi { | ||
| fn default() -> Self { | ||
| Self::new(Path::new("/dev/ipmi0"), Path::new("/usr/bin/ipmitool")) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.