summaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-09-08 18:38:15 +0300
committerLars Wirzenius <liw@liw.fi>2023-09-08 18:38:15 +0300
commit9e52fa76411a37fce9c455efa70e2f6b1a5c1071 (patch)
tree2dcb65eed265c5fbb6682645b9dfc2e0b9f69fb5 /src/cmd
parent669a34a9bd7cbbd92203d5a18260de3d4aa0b7f2 (diff)
downloadvmadm-9e52fa76411a37fce9c455efa70e2f6b1a5c1071.tar.gz
feat: "reboot" subcommand
Sponsored-by: author
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/mod.rs3
-rw-r--r--src/cmd/reboot.rs32
2 files changed, 35 insertions, 0 deletions
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(())
+}