summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-06-09 15:42:37 -0400
committerCara Salter <cara@devcara.com>2022-06-09 15:42:37 -0400
commitc3fca2f891372827e37d8aae07bd2223bb3a3327 (patch)
tree2dd3be25783bc59efe86811b1a419e1abc217c67
parent0b82b7b47ac34cb9a14613a83ce6eb386ae21086 (diff)
downloadsolarctl-c3fca2f891372827e37d8aae07bd2223bb3a3327.tar.gz
solarctl-c3fca2f891372827e37d8aae07bd2223bb3a3327.zip
state: Manipulate VM state
Closes #1
-rw-r--r--src/main.rs43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index d55df8e..83d572c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -24,6 +24,9 @@ enum Action {
Stop {
/// The UUID of the machine to stop
uuid: String,
+
+ #[clap(long, short)]
+ force: bool
},
Start {
/// The UUID of the machine to start
@@ -33,6 +36,12 @@ enum Action {
/// The UUID of the machine to pause
uuid: String,
},
+ Reboot {
+ uuid: String,
+
+ #[clap(long, short)]
+ force: bool
+ }
}
fn main() {
@@ -46,14 +55,17 @@ fn main() {
Action::List => {
list(args, client).unwrap();
},
- Action::Stop { uuid } => {
- stop(root, client, uuid).unwrap();
+ Action::Stop { uuid, force } => {
+ stop(root, client, uuid, force).unwrap();
},
Action::Start { uuid } => {
start(root, client, uuid).unwrap();
},
Action::Pause { uuid } => {
pause(root, client, uuid).unwrap();
+ },
+ Action::Reboot { uuid, force } => {
+ reboot(root, client, uuid, force).unwrap();
}
};
}
@@ -81,8 +93,12 @@ fn list(a: Args, c: Client) -> Result<(), CliError> {
Ok(())
}
-fn stop(server: String, c: Client, u: String) -> Result<(), CliError> {
- let res = c.post(format!("http://{}/planets/{}/shutdown", server, u)).send()?;
+fn stop(server: String, c: Client, u: String, f: bool) -> Result<(), CliError> {
+ let mut url = format!("http://{}/planets/{}/shutdown", server, u);
+ if f {
+ url.push_str("/hard");
+ }
+ let res = c.post(url).send()?;
match res.status() {
StatusCode::OK => {
@@ -125,3 +141,22 @@ fn pause(server: String, c: Client, u: String) -> Result<(), CliError> {
Ok(())
}
+
+fn reboot(server: String, c: Client, u: String, f: bool) -> Result<(), CliError> {
+ let mut url = format!("http://{}/planets/{}/reboot", server, u);
+ if f {
+ url.push_str("/hard");
+ }
+ let res = c.post(url).send()?;
+
+ match res.status() {
+ StatusCode::OK => {
+ println!("Rebooted.");
+ },
+ _ => {
+ return Err(CliError::Cli(format!("Could not reboot VM: {}", res.text()?)));
+ },
+ };
+
+ Ok(())
+}