diff --git a/control-plane/plugin/src/operations.rs b/control-plane/plugin/src/operations.rs index 645cf1eb8..211dd2ed9 100644 --- a/control-plane/plugin/src/operations.rs +++ b/control-plane/plugin/src/operations.rs @@ -85,6 +85,11 @@ pub trait Get { pub trait Scale { type ID; async fn scale(id: &Self::ID, replica_count: u8, output: &utils::OutputFormat) -> PluginResult; + async fn resize( + id: &Self::ID, + requested_size: u64, + output: &utils::OutputFormat, + ) -> PluginResult; } /// Replica topology trait. diff --git a/control-plane/plugin/src/resources/error.rs b/control-plane/plugin/src/resources/error.rs index 225540a40..e0c7b4984 100644 --- a/control-plane/plugin/src/resources/error.rs +++ b/control-plane/plugin/src/resources/error.rs @@ -74,6 +74,12 @@ pub enum Error { id: String, source: openapi::tower::client::Error, }, + /// Error when resize volume request fails. + #[snafu(display("Failed to resize volume {id}. Error {source}"))] + ResizeVolumeError { + id: String, + source: openapi::tower::client::Error, + }, /// Error when set volume property request fails. #[snafu(display("Failed to set volume {id} property, Error {source}"))] ScaleVolumePropertyError { diff --git a/control-plane/plugin/src/resources/volume.rs b/control-plane/plugin/src/resources/volume.rs index 8bc9cf1ac..304fe2195 100644 --- a/control-plane/plugin/src/resources/volume.rs +++ b/control-plane/plugin/src/resources/volume.rs @@ -190,6 +190,39 @@ impl Scale for Volume { } Ok(()) } + + async fn resize( + id: &Self::ID, + requested_size: u64, + output: &utils::OutputFormat, + ) -> PluginResult { + let req = openapi::models::ResizeVolumeBody { + size: requested_size as usize, + }; + match RestClient::client() + .volumes_api() + .put_volume_size(id, req) + .await + { + Ok(volume) => match output { + OutputFormat::Yaml | OutputFormat::Json => { + // Print json or yaml based on output format. + utils::print_table(output, volume.into_body()); + } + OutputFormat::None => { + // In case the output format is not specified, show a success message. + println!("Volume {id} resized successfully 🚀") + } + }, + Err(e) => { + return Err(Error::ScaleVolumeError { + id: id.to_string(), + source: e, + }); + } + } + Ok(()) + } } #[async_trait(?Send)]