summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-02-28 18:59:14 +0000
committerLars Wirzenius <liw@liw.fi>2022-02-28 18:59:14 +0000
commitf5b7ee0ce079e22f37e42c23277ed32aebb41919 (patch)
tree2094488c09e0bbbdb46a8f332557e3aa4f64ab3e
parent082e96cb2efb57f20b63e6908b8b28ff40119197 (diff)
parent84dde1be5e02c639f818a7b3f167d9d5b7c47a8c (diff)
downloadvmadm-f5b7ee0ce079e22f37e42c23277ed32aebb41919.tar.gz
Merge branch 'recreate' into 'main'
feat: add a recreate subcommand Closes #33 See merge request larswirzenius/vmadm!57
-rw-r--r--src/bin/vmadm.rs14
-rw-r--r--src/cmd/mod.rs3
-rw-r--r--src/cmd/recreate.rs32
-rw-r--r--vmadm.md8
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(())
+}
diff --git a/vmadm.md b/vmadm.md
index aec706f..71a49d1 100644
--- a/vmadm.md
+++ b/vmadm.md
@@ -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