summaryrefslogtreecommitdiff
path: root/src/cmd/start.rs
blob: a69f54cfa2ee9c333ea5f37742d91903bcf1b8fd (plain)
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
//! The `start` sub-command.

use crate::libvirt::{Libvirt, VirtError};
use crate::spec::Specification;
use crate::util::wait_for_ssh;
use log::info;

/// Errors from this module.
#[derive(Debug, thiserror::Error)]
pub enum StartError {
    /// Error from libvirt.
    #[error(transparent)]
    VirtError(#[from] VirtError),

    /// Error doing I/O.
    #[error(transparent)]
    IoError(#[from] std::io::Error),
}

/// Start existing VMs corresponding to specifications.
pub fn start(specs: &[Specification]) -> Result<(), StartError> {
    let libvirt = Libvirt::connect("qemu:///system")?;
    for spec in specs {
        info!("starting virtual machine {}", spec.name);
        libvirt.start(&spec.name)?;
    }
    for spec in specs {
        wait_for_ssh(&spec.name);
    }
    Ok(())
}