diff options
Diffstat (limited to 'src/cmd/shutdown.rs')
-rw-r--r-- | src/cmd/shutdown.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/cmd/shutdown.rs b/src/cmd/shutdown.rs new file mode 100644 index 0000000..b53ebd3 --- /dev/null +++ b/src/cmd/shutdown.rs @@ -0,0 +1,19 @@ +//! The `shutdown` sub-command. + +use crate::libvirt::{Libvirt, VirtError}; +use crate::spec::Specification; +use log::{debug, info}; + +/// Shut down VMs corresponding to specifications. +pub fn shutdown(specs: &[Specification]) -> Result<(), VirtError> { + let libvirt = Libvirt::connect("qemu:///system")?; + for spec in specs { + info!("shutting down virtual machine {}", spec.name); + libvirt.shutdown(&spec.name)?; + } + for spec in specs { + debug!("waiting for {} to become inactive", spec.name); + libvirt.wait_for_inactive(&spec.name)?; + } + Ok(()) +} |