Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
hanneary committed Dec 10, 2024
1 parent 277cb4a commit 4d0e658
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions control-plane/src/orchestration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ pub enum OrchestrationError {
}

static EMPTY_VEC: Vec<Value> = Vec::new();
static ENCLAVE_CID: &str = "2021";
static EIF_PATH: &str = "enclave.eif";
static NITRO_CLI: &str = "nitro-cli";

pub struct Orchestration;

impl Orchestration {
pub async fn shutdown_all_enclaves() -> Result<String, OrchestrationError> {
let command = vec!["sh", "-c", "nitro-cli", "terminate-enclave", "--all"];
let command = vec!["sh", "-c", NITRO_CLI, "terminate-enclave", "--all"];
Self::run_command_capture_stdout(&command).await
}

Expand All @@ -36,7 +39,7 @@ impl Orchestration {
info!("[HOST] Checking for running enclaves...");

let running_enclaves =
Self::run_command_capture_stdout(&["nitro-cli", "describe-enclaves"]).await?;
Self::run_command_capture_stdout(&[NITRO_CLI, "describe-enclaves"]).await?;
let enclaves: Value = serde_json::from_str(&running_enclaves)?;
let enclaves_array = enclaves.as_array().unwrap_or(&EMPTY_VEC);
if !enclaves_array.is_empty() {
Expand All @@ -50,16 +53,16 @@ impl Orchestration {

info!("Starting new enclave...");
let mut run_command = vec![
"nitro-cli",
NITRO_CLI,
"run-enclave",
"--cpu-count",
&run_config.num_cpus,
"--memory",
&run_config.ram_size_mib,
"--enclave-cid",
"2021",
ENCLAVE_CID,
"--eif-path",
"enclave.eif",
EIF_PATH,
];

if run_config.debug_mode == "true" {
Expand All @@ -77,7 +80,7 @@ impl Orchestration {
if run_config.debug_mode == "true" {
info!("Attaching headless console for running enclaves...");
let running_enclaves =
Self::run_command_capture_stdout(&["nitro-cli", "describe-enclaves"]).await?;
Self::run_command_capture_stdout(&[NITRO_CLI, "describe-enclaves"]).await?;
let enclaves: Value = serde_json::from_str(&running_enclaves)?;
let enclaves_array = enclaves.as_array().unwrap_or(&EMPTY_VEC).clone();
for enclave in enclaves_array {
Expand Down

0 comments on commit 4d0e658

Please sign in to comment.