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 /src/cmd | |
parent | 082e96cb2efb57f20b63e6908b8b28ff40119197 (diff) | |
download | vmadm-84dde1be5e02c639f818a7b3f167d9d5b7c47a8c.tar.gz |
feat: add a recreate subcommand
Sponsored-by: author
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/mod.rs | 3 | ||||
-rw-r--r-- | src/cmd/recreate.rs | 32 |
2 files changed, 35 insertions, 0 deletions
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(()) +} |