summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-02-28 20:58:17 +0200
committerLars Wirzenius <liw@liw.fi>2022-02-28 20:58:17 +0200
commit84dde1be5e02c639f818a7b3f167d9d5b7c47a8c (patch)
tree2094488c09e0bbbdb46a8f332557e3aa4f64ab3e /src
parent082e96cb2efb57f20b63e6908b8b28ff40119197 (diff)
downloadvmadm-84dde1be5e02c639f818a7b3f167d9d5b7c47a8c.tar.gz
feat: add a recreate subcommand
Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r--src/bin/vmadm.rs14
-rw-r--r--src/cmd/mod.rs3
-rw-r--r--src/cmd/recreate.rs32
3 files changed, 49 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(())
+}