Skip to content

Commit

Permalink
feat(volume/resize): add volume resize to rest plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Diwakar Sharma <diwakar.sharma@datacore.com>
  • Loading branch information
dsharma-dc committed Feb 16, 2024
1 parent b91fe26 commit c638025
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions control-plane/plugin/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions control-plane/plugin/src/resources/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ pub enum Error {
id: String,
source: openapi::tower::client::Error<openapi::models::RestJsonError>,
},
/// Error when resize volume request fails.
#[snafu(display("Failed to resize volume {id}. Error {source}"))]
ResizeVolumeError {
id: String,
source: openapi::tower::client::Error<openapi::models::RestJsonError>,
},
/// Error when set volume property request fails.
#[snafu(display("Failed to set volume {id} property, Error {source}"))]
ScaleVolumePropertyError {
Expand Down
33 changes: 33 additions & 0 deletions control-plane/plugin/src/resources/volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit c638025

Please sign in to comment.