diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-02-28 20:58:17 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-02-28 20:58:17 +0200 |
commit | 84dde1be5e02c639f818a7b3f167d9d5b7c47a8c (patch) | |
tree | 2094488c09e0bbbdb46a8f332557e3aa4f64ab3e | |
parent | 082e96cb2efb57f20b63e6908b8b28ff40119197 (diff) | |
download | vmadm-84dde1be5e02c639f818a7b3f167d9d5b7c47a8c.tar.gz |
feat: add a recreate subcommand
Sponsored-by: author
-rw-r--r-- | src/bin/vmadm.rs | 14 | ||||
-rw-r--r-- | src/cmd/mod.rs | 3 | ||||
-rw-r--r-- | src/cmd/recreate.rs | 32 | ||||
-rw-r--r-- | vmadm.md | 8 |
4 files changed, 57 insertions, 0 deletions
diff --git a/src/bin/vmadm.rs b/src/bin/vmadm.rs index ab01330..a693b96 100644 --- a/src/bin/vmadm.rs +++ b/src/bin/vmadm.rs @@ -28,6 +28,14 @@ enum Command { specs: Vec<PathBuf>, }, + Recreate { + #[structopt(flatten)] + common: CommonOptions, + + #[structopt(parse(from_os_str))] + specs: Vec<PathBuf>, + }, + Config { #[structopt(flatten)] common: CommonOptions, @@ -106,6 +114,12 @@ fn main() -> anyhow::Result<()> { cmd::new(&specs, &progress)?; } + Command::Recreate { common, specs } => { + let progress = get_progress(&common); + let specs = get_specs(&common, &specs)?; + cmd::recreate(&specs, &progress)?; + } + Command::Config { common } => { let progress = get_progress(&common); let config = config(&common)?; diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 85ccf4e..dda28da 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -6,6 +6,9 @@ pub mod new; pub use new::new; +pub mod recreate; +pub use recreate::recreate; + pub mod list; pub use list::list; diff --git a/src/cmd/recreate.rs b/src/cmd/recreate.rs new file mode 100644 index 0000000..3bd9672 --- /dev/null +++ b/src/cmd/recreate.rs @@ -0,0 +1,32 @@ +//! The `recreate` sub-command. + +use crate::cmd::delete::delete; +use crate::cmd::new::{new, NewError}; +use crate::libvirt::VirtError; +use crate::progress::Progress; +use crate::spec::Specification; + +/// Errors returned by this module. +#[derive(Debug, thiserror::Error)] +pub enum RecreateError { + /// Problem with new. + #[error(transparent)] + New(#[from] NewError), + + /// Problem from libvirt server. + #[error(transparent)] + VirtError(#[from] VirtError), +} + +/// The `recreate` sub-command. +/// +/// This deletes, then news virtual machines. +pub fn recreate(specs: &[Specification], progress: &Progress) -> Result<(), RecreateError> { + progress.chatty("Re-creating virtual machines"); + + delete(specs, progress)?; + new(specs, progress)?; + + progress.chatty("re-creation successful"); + Ok(()) +} @@ -322,6 +322,14 @@ when I run ssh -F .ssh/config debian@smoke hostname when I run ssh -F .ssh/config debian@other hostname ~~~ +Then we recreate them. + +~~~scenario +when I run vmadm recreate --config config.yaml smoke.yaml other.yaml +when I run ssh -F .ssh/config debian@smoke hostname +when I run ssh -F .ssh/config debian@other hostname +~~~ + Finally, we delete them. ~~~scenario |