diff options
Diffstat (limited to 'src/cmd/start.rs')
-rw-r--r-- | src/cmd/start.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/cmd/start.rs b/src/cmd/start.rs new file mode 100644 index 0000000..a69f54c --- /dev/null +++ b/src/cmd/start.rs @@ -0,0 +1,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(()) +} |