cubic 0.14.0

Cubic is a lightweight command line manager for virtual machines. It has a simple, daemon-less and rootless design. All Cubic virtual machines run isolated in the user context. Cubic is built on top of QEMU, KVM and cloud-init. Show all supported images: $ cubic images Create a new virtual machine instance: $ cubic create mymachine --image ubuntu:noble List all virtual machine instances: $ cubic instances Start an instance: $ cubic start <instance name> Stop an instance: $ cubic stop <instance name> Open a shell in the instance: $ cubic ssh <machine name> Copy a file from the host to the instance: $ cubic scp <path/to/host/file> <machine>:<path/to/guest/file> Copy a file from the instance to the hots: $ cubic scp <machine>:<path/to/guest/file> <path/to/host/file>
use crate::error::Error;
use crate::instance::{InstanceDao, InstanceStore};
use crate::view::{Alignment, Console, TableView};
use clap::Parser;

/// List forwarded ports for all virtual machine instances
#[derive(Parser)]
pub struct ListPortCommand;

impl ListPortCommand {
    pub fn run(&self, console: &mut dyn Console, instance_dao: &InstanceDao) -> Result<(), Error> {
        let instance_names = instance_dao.get_instances();

        let mut view = TableView::new();
        view.add_row()
            .add("INSTANCE", Alignment::Left)
            .add("HOST", Alignment::Left)
            .add("GUEST", Alignment::Left)
            .add("PROTOCOL", Alignment::Left)
            .add("STATE", Alignment::Left);

        for instance_name in instance_names {
            let instance = &instance_dao.load(&instance_name)?;
            for rule in &instance.hostfwd {
                view.add_row()
                    .add(&instance_name, Alignment::Left)
                    .add(
                        &format!("{}:{}", rule.get_host_ip(), rule.get_host_port()),
                        Alignment::Left,
                    )
                    .add(&format!(":{}", rule.get_guest_port()), Alignment::Left)
                    .add(&format!("/{}", rule.get_protocol()), Alignment::Left)
                    .add(
                        instance_dao
                            .is_running(instance)
                            .then_some("in use")
                            .unwrap_or_default(),
                        Alignment::Left,
                    );
            }
        }
        view.print(console);
        Ok(())
    }
}