-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmachine.rs
More file actions
60 lines (50 loc) · 1.87 KB
/
machine.rs
File metadata and controls
60 lines (50 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::{config::ConfigManager, util::ApproximateDuration};
use chrono::Utc;
use colorize::AnsiColor;
use forevervm_sdk::api::http_api::{CreateMachineRequest, ListMachinesRequest};
pub async fn machine_list(tags: std::collections::HashMap<String, String>) -> anyhow::Result<()> {
let client = ConfigManager::new()?.client()?;
let request = ListMachinesRequest { tags };
let machines = client.list_machines(request).await?;
println!("Machines:");
for machine in machines.machines {
let expires_at = if let Some(expires_at) = machine.expires_at {
expires_at.to_string()
} else {
"never".to_string()
};
let status = if machine.has_pending_instruction {
"has_work".to_string()
} else {
"idle".to_string()
};
let age = ApproximateDuration::from(Utc::now() - machine.created_at);
println!("{}", machine.name.to_string().b_green());
println!(
" Created: {} ago ({})",
age.to_string().b_yellow(),
machine.created_at.to_string().b_yellow()
);
println!(" Expires: {}", expires_at.b_yellow());
println!(" Status: {}", status.b_yellow());
println!(" Running: {}", machine.running.to_string().b_yellow());
for (key, value) in machine.tags.into_iter() {
println!(" Tag: {} = {}", key.b_yellow(), value.b_yellow());
}
println!();
}
Ok(())
}
pub async fn machine_new(
tags: std::collections::HashMap<String, String>,
memory_mb: Option<u32>,
) -> anyhow::Result<()> {
let client = ConfigManager::new()?.client()?;
let request = CreateMachineRequest { tags, memory_mb };
let machine = client.create_machine(request).await?;
println!(
"Created machine {}",
machine.machine_name.to_string().b_green()
);
Ok(())
}