-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add traits related to IaaS functionality
- Loading branch information
Showing
3 changed files
with
94 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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,93 @@ | ||
use serde_json::Value; | ||
|
||
use crate::error::Error; | ||
|
||
pub trait IaaSOps { | ||
// FIXME: Create a new type PowerStatus and return Result<PowerStatus, Error> | ||
async fn power_off_sync(&self, nodes: &Vec<String>, force: bool) -> Result<Value, Error> { | ||
Err(Error::Message( | ||
"This infrastructure does not support power off operation".to_string(), | ||
)) | ||
} | ||
|
||
// FIXME: Create a new type PowerStatus and return Result<PowerStatus, Error> | ||
async fn power_on_sync(&self, nodes: &Vec<String>) -> Result<Value, Error> { | ||
Err(Error::Message( | ||
"This infrastructure does not support power on operation".to_string(), | ||
)) | ||
} | ||
|
||
// FIXME: Create a new type PowerStatus and return Result<PowerStatus, Error> | ||
async fn power_reset_sync(&self, nodes: &Vec<String>, force: bool) -> Result<Value, Error> { | ||
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<u8>, | ||
} | ||
|
||
impl Csm { | ||
pub fn new(base_url: String, auth_token: String, root_cert: Vec<u8>) -> Csm { | ||
Csm { | ||
base_url, | ||
auth_token, | ||
root_cert, | ||
} | ||
} | ||
} | ||
|
||
impl IaaSOps for Csm { | ||
async fn power_off_sync(&self, nodes: &Vec<String>, force: bool) -> Result<Value, Error> { | ||
// 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<String>) -> Result<Value, Error> { | ||
// 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<String>, force: bool) -> Result<Value, Error> { | ||
// 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 | ||
} | ||
} |
This file contains 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 was deleted.
Oops, something went wrong.