From 9e52fa76411a37fce9c455efa70e2f6b1a5c1071 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 8 Sep 2023 18:38:15 +0300 Subject: feat: "reboot" subcommand Sponsored-by: author --- src/bin/vmadm.rs | 14 ++++++++++++++ src/cmd/mod.rs | 3 +++ src/cmd/reboot.rs | 32 ++++++++++++++++++++++++++++++++ vmadm.md | 8 ++++++++ 4 files changed, 57 insertions(+) create mode 100644 src/cmd/reboot.rs diff --git a/src/bin/vmadm.rs b/src/bin/vmadm.rs index 159a172..b515e45 100644 --- a/src/bin/vmadm.rs +++ b/src/bin/vmadm.rs @@ -67,6 +67,14 @@ enum Command { specs: Vec, }, + #[clap(visible_alias = "restart")] + Reboot { + #[clap(flatten)] + common: CommonOptions, + + specs: Vec, + }, + #[clap(visible_alias = "stop")] Shutdown { #[clap(flatten)] @@ -144,6 +152,12 @@ fn main() -> anyhow::Result<()> { cmd::start(&specs, &progress)?; } + Command::Reboot { common, specs } => { + let progress = get_progress(&common); + let specs = get_specs(&common, &specs)?; + cmd::reboot(&specs, &progress)?; + } + Command::Shutdown { common, specs } => { let progress = get_progress(&common); let specs = get_specs(&common, &specs)?; diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index dda28da..2659b4b 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -29,3 +29,6 @@ pub use config::config; pub mod spec; pub use spec::spec; + +pub mod reboot; +pub use reboot::reboot; diff --git a/src/cmd/reboot.rs b/src/cmd/reboot.rs new file mode 100644 index 0000000..ebbea4b --- /dev/null +++ b/src/cmd/reboot.rs @@ -0,0 +1,32 @@ +//! The `reboot` sub-command. + +use crate::cmd::shutdown::shutdown; +use crate::cmd::start::{start, StartError}; +use crate::libvirt::VirtError; +use crate::progress::Progress; +use crate::spec::Specification; + +/// Errors returned by this module. +#[derive(Debug, thiserror::Error)] +pub enum RebootError { + /// Problem with new. + #[error(transparent)] + New(#[from] StartError), + + /// Problem from libvirt server. + #[error(transparent)] + VirtError(#[from] VirtError), +} + +/// The `recreate` sub-command. +/// +/// This shuts down, then starts virtual machines. +pub fn reboot(specs: &[Specification], progress: &Progress) -> Result<(), RebootError> { + progress.chatty("Restarting virtual machines"); + + shutdown(specs, progress)?; + start(specs, progress)?; + + progress.chatty("Restart successful"); + Ok(()) +} diff --git a/vmadm.md b/vmadm.md index 7d5ae96..2fb6eeb 100644 --- a/vmadm.md +++ b/vmadm.md @@ -258,6 +258,14 @@ when I run ssh -F .ssh/config debian@smoke hostname when I run vmadm start --config config.yaml smoke.yaml ~~~ +Do it again, but using the `vmadm reboot` helper command. + + +~~~scenario +when I run vmadm reboot --config config.yaml smoke.yaml +when I run ssh -F .ssh/config debian@smoke hostname +~~~ + Finally, we delete it twice. ~~~scenario -- cgit v1.2.1