From cf349fc6944858a14b29d60543163fe9de6eb5f3 Mon Sep 17 00:00:00 2001 From: Tait Hoyem Date: Tue, 27 Sep 2022 09:19:23 -0600 Subject: [PATCH] Switch UUIDs from uuid::Uuid to String to preserve dashes. --- src/requests.rs | 27 +++++++++++++++++++++++++++ src/responses.rs | 18 +++++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/requests.rs b/src/requests.rs index 8242550..5d77766 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -18,6 +18,9 @@ use crate::{ MonitorCheckListResponse, MonitorCheckTypesResponse, MonitorContactListResponse, + VmStartResponse, + VmStopResponse, + VmRebootResponse, }, types::{ LNError, @@ -93,6 +96,12 @@ pub enum RecordSubArgs { pub enum VmSubArgs { /// List all VMs on my account. List(VMListRequest), + /// Restart a VM, given an ID. + Reboot(VmRebootRequest), + /// Stop a VM, given an ID. + Stop(VmStopRequest), + /// Turn on a VM, given an ID. + Start(VmStartRequest), } #[derive(Serialize, Deserialize, Debug, clap::Subcommand)] #[serde(untagged)] @@ -210,6 +219,9 @@ impl Args { Self::Network(NetworkSubArgs::List(net_list)) => print_req(net_list)?, Self::Floating(FloatingSubArgs::List(ip_list)) => print_req(ip_list)?, Self::Vm(VmSubArgs::List(vm_list)) => print_req(vm_list)?, + Self::Vm(VmSubArgs::Start(vm_to_start)) => print_req(vm_to_start)?, + Self::Vm(VmSubArgs::Stop(vm_to_stop)) => print_req(vm_to_stop)?, + Self::Vm(VmSubArgs::Reboot(vm_to_reboot)) => print_req(vm_to_reboot)?, Self::Volume(VolumeSubArgs::List(vol_list)) => print_req(vol_list)?, Self::Image(ImageSubArgs::List(image_list)) => print_req(image_list)?, Self::Billing(BillingSubArgs::Credit(billing_credit)) => print_req(billing_credit)?, @@ -291,3 +303,18 @@ pub struct MonitorContactListRequest {} pub struct EmailUserListRequest { domain_id: i32, } + +#[lunanode_request(response="VmStartResponse", endpoint="vm/start/")] +pub struct VmStartRequest { + vm_id: String, +} + +#[lunanode_request(response="VmStopResponse", endpoint="vm/stop/")] +pub struct VmStopRequest { + vm_id: String, +} + +#[lunanode_request(response="VmRebootResponse", endpoint="vm/reboot/")] +pub struct VmRebootRequest { + vm_id: String, +} diff --git a/src/responses.rs b/src/responses.rs index d9fcd32..cc37692 100644 --- a/src/responses.rs +++ b/src/responses.rs @@ -19,9 +19,8 @@ use uuid; #[derive(Serialize, Deserialize, PartialEq, Debug)] /// Defines a VM (used for requests using the VM section) pub struct VirtualMachine { - #[serde_as(as="DisplayFromStr")] /// the UUID of the VM - vm_id: uuid::Uuid, // should be UUIDv4 + vm_id: String, // should be UUIDv4 /// the name of the VM set by the user name: String, // the name set by the user #[serde_as(as="DisplayFromStr")] @@ -76,7 +75,7 @@ enum AttachmentType { #[serde_as] #[derive(Serialize, Deserialize, Debug)] struct FloatingIp { - attached_id: Option, + attached_id: Option, attached_name: Option, attached_type: AttachmentType, hostname: String, @@ -121,7 +120,7 @@ pub struct VMInfoExtra { vcpu: i32, #[serde_as(as="DisplayFromStr")] /// UUIDv4 of the VM - vm_id: uuid::Uuid, + vm_id: String, } #[derive(Serialize, Deserialize, Debug)] #[serde(untagged)] @@ -279,7 +278,7 @@ pub struct Volume { id: i32, #[serde_as(as="DisplayFromStr")] /// the UUID for the volume - identification: uuid::Uuid, + identification: String, /// the name set by the user name: String, /// The region where the volume is located. @@ -604,3 +603,12 @@ pub struct EmailUserListResponse { #[serde(flatten)] users: std::collections::HashMap, } + +#[lunanode_response] +pub struct VmStartResponse {} + +#[lunanode_response] +pub struct VmStopResponse {} + +#[lunanode_response] +pub struct VmRebootResponse {}