diff --git a/crates/firecracker-state/src/repo/virtual_machine.rs b/crates/firecracker-state/src/repo/virtual_machine.rs index 93212cc..8aea160 100644 --- a/crates/firecracker-state/src/repo/virtual_machine.rs +++ b/crates/firecracker-state/src/repo/virtual_machine.rs @@ -121,6 +121,7 @@ pub async fn update(pool: &Pool, id: &str, vm: VirtualMachine) -> Result vmlinux = ?, rootfs = ?, bootargs = ? + updated_at = CURRENT_TIMESTAMP WHERE id = ?"#, ) .bind(&vm.project_dir) diff --git a/crates/firecracker-up/src/cmd/ps.rs b/crates/firecracker-up/src/cmd/ps.rs index 3f8ac21..9d2bb94 100644 --- a/crates/firecracker-up/src/cmd/ps.rs +++ b/crates/firecracker-up/src/cmd/ps.rs @@ -1,6 +1,6 @@ use anyhow::Error; -use crate::date::format_duration_ago; +use crate::date::{format_duration_ago, format_status}; pub async fn list_all_instances(all: bool) -> Result<(), Error> { let pool = firecracker_state::create_connection_pool().await?; @@ -16,19 +16,62 @@ pub async fn list_all_instances(all: bool) -> Result<(), Error> { println!("No Firecracker MicroVM instances found."); return Ok(()); } + let distro_length = vms.iter().map(|vm| vm.distro.len()).max().unwrap_or(10) + 2; + let name_length = vms + .iter() + .map(|vm| vm.name.len()) + .max() + .unwrap_or(10) + .max(10) + + 2; + let vcpu_length = vms + .iter() + .map(|vm| vm.vcpu.to_string().len()) + .max() + .unwrap_or(10) + + 2; + let memory_length = vms + .iter() + .map(|vm| format!("{} MiB", vm.memory).len()) + .max() + .unwrap_or(10) + + 2; + let status_length = vms + .iter() + .map(|vm| format_status(&vm.status, vm.updated_at).len()) + .max() + .unwrap_or(10); + let pid_length = vms + .iter() + .map(|vm| vm.pid.unwrap_or(0).to_string().len()) + .max() + .unwrap_or(10) + + 2; + let ip_length = vms + .iter() + .map(|vm| vm.ip_address.clone().unwrap_or_default().len()) + .max() + .unwrap_or(10) + + 2; + let created_length = vms + .iter() + .map(|vm| format_duration_ago(vm.created_at).len()) + .max() + .unwrap_or(10) + + 2; println!( - "{:<20} {:<10} {:<5} {:<10} {:<15} {:<10} {:<15} {:<10}", + "{:) -> String { ) } } + +pub fn format_status(status: &str, date: DateTime) -> String { + if status == "RUNNING" { + format!("Up {}", format_duration_ago(date)) + } else { + status.to_string() + } +} -- 2.51.2 From bcf778792220e07e17a288678da54e2e61f1d69e Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Sun, 14 Sep 2025 17:13:03 +0300 Subject: [PATCH 2/2] fix: update virtual machine update function to set updated_at timestamp --- crates/firecracker-state/src/repo/virtual_machine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/firecracker-state/src/repo/virtual_machine.rs b/crates/firecracker-state/src/repo/virtual_machine.rs index 8aea160..118d9b1 100644 --- a/crates/firecracker-state/src/repo/virtual_machine.rs +++ b/crates/firecracker-state/src/repo/virtual_machine.rs @@ -120,7 +120,7 @@ pub async fn update(pool: &Pool, id: &str, vm: VirtualMachine) -> Result distro = ?, vmlinux = ?, rootfs = ?, - bootargs = ? + bootargs = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?"#, )