Support set notify_on_release & release_agent

Support set notify_on_release & release_agent

Signed-off-by: Qingyuan Hou <qingyuan.hou@linux.alibaba.com>
This commit is contained in:
Qingyuan Hou
2020-12-10 01:35:01 +08:00
committed by Tim Zhang
parent 61a0957a65
commit a89f4a062e
2 changed files with 38 additions and 0 deletions

View File

@@ -246,6 +246,12 @@ pub trait Controller {
/// Does this controller already exist?
fn exists(&self) -> bool;
/// Set notify_on_release
fn set_notify_on_release(&self, enable: bool) -> Result<()>;
/// Set release_agent
fn set_release_agent(&self, path: &str) -> Result<()>;
/// Delete the controller.
fn delete(&self) -> Result<()>;
@@ -290,6 +296,22 @@ where
}
}
/// Set notify_on_release
fn set_notify_on_release(&self, enable: bool) -> Result<()> {
self.open_path("notify_on_release", true)
.and_then(|mut file| {
write!(file, "{}", enable as i32)
.map_err(|e| Error::with_cause(ErrorKind::WriteFailed, e))
})
}
/// Set release_agent
fn set_release_agent(&self, path: &str) -> Result<()> {
self.open_path("release_agent", true).and_then(|mut file| {
file.write_all(path.as_bytes())
.map_err(|e| Error::with_cause(ErrorKind::WriteFailed, e))
})
}
/// Does this controller already exist?
fn exists(&self) -> bool {
self.get_path().exists()