diff --git a/src/iaas_ops.rs b/src/iaas_ops.rs new file mode 100644 index 0000000..8943f3e --- /dev/null +++ b/src/iaas_ops.rs @@ -0,0 +1,93 @@ +use serde_json::Value; + +use crate::error::Error; + +pub trait IaaSOps { + // FIXME: Create a new type PowerStatus and return Result + async fn power_off_sync(&self, nodes: &Vec, force: bool) -> Result { + Err(Error::Message( + "This infrastructure does not support power off operation".to_string(), + )) + } + + // FIXME: Create a new type PowerStatus and return Result + async fn power_on_sync(&self, nodes: &Vec) -> Result { + Err(Error::Message( + "This infrastructure does not support power on operation".to_string(), + )) + } + + // FIXME: Create a new type PowerStatus and return Result + async fn power_reset_sync(&self, nodes: &Vec, force: bool) -> Result { + Err(Error::Message( + "This infrastructure does not support power reset operation".to_string(), + )) + } +} + +pub struct Csm { + pub base_url: String, + pub auth_token: String, + pub root_cert: Vec, +} + +impl Csm { + pub fn new(base_url: String, auth_token: String, root_cert: Vec) -> Csm { + Csm { + base_url, + auth_token, + root_cert, + } + } +} + +impl IaaSOps for Csm { + async fn power_off_sync(&self, nodes: &Vec, force: bool) -> Result { + // Validate operation + let operation = if force { "force-off" } else { "soft-off" }; + + // Create power transition through CSM + crate::pcs::transitions::http_client::post_block( + &self.base_url, + &self.auth_token, + &self.root_cert, + operation, + &nodes, + ) + .await + } + + async fn power_on_sync(&self, nodes: &Vec) -> Result { + // Validate operation + let operation = "on"; + + // Create power transition through CSM + crate::pcs::transitions::http_client::post_block( + &self.base_url, + &self.auth_token, + &self.root_cert, + operation, + &nodes, + ) + .await + } + + async fn power_reset_sync(&self, nodes: &Vec, force: bool) -> Result { + // Validate operation + let operation = if force { + "hard-restart" + } else { + "soft-restart" + }; + + // Create power transition through CSM + crate::pcs::transitions::http_client::post_block( + &self.base_url, + &self.auth_token, + &self.root_cert, + operation, + &nodes, + ) + .await + } +} diff --git a/src/lib.rs b/src/lib.rs index cf4e291..a17eed1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ pub mod common; pub mod error; #[cfg(feature = "ochami")] pub mod hsm; +pub mod iaas_ops; pub mod ims; pub mod node; pub mod pcs; -pub mod power_ops; diff --git a/src/power_ops.rs b/src/power_ops.rs deleted file mode 100644 index 54ba9ce..0000000 --- a/src/power_ops.rs +++ /dev/null @@ -1,8 +0,0 @@ -use serde_json::Value; - -use crate::error::Error; - -pub trait Power { - // FIXME: Create a new type PowerStatus and return Result - fn power_off(base_url: &str, auth_token: &str, root_cert: &[u8]) -> Result; -}