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 b4d4c09
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions control-plane/src/orchestration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ 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";
static TERMINATE_ENCLAVE: &str = "terminate-enclave";
static DESCRIBE_ENCLAVES: &str = "describe-enclaves";
static RUN_ENCLAVE: &str = "run-enclave";


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 +43,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 +57,16 @@ impl Orchestration {

info!("Starting new enclave...");
let mut run_command = vec![
"nitro-cli",
"run-enclave",
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 +84,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 b4d4c09

Please sign in to comment.