Skip to content

Commit

Permalink
feat: add traits related to IaaS functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Masber committed Dec 1, 2024
1 parent 0e90bca commit 07c6447
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 9 deletions.
93 changes: 93 additions & 0 deletions src/iaas_ops.rs
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
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 0 additions & 8 deletions src/power_ops.rs

This file was deleted.

0 comments on commit 07c6447

Please sign in to comment.