Skip to content

Commit 372a047

Browse files
committed
feat(io-engine-client): add cli for resizing a nexus
Signed-off-by: Diwakar Sharma <diwakar.sharma@datacore.com>
1 parent 404234d commit 372a047

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

io-engine/src/bin/io-engine-client/v1/nexus_cli.rs

+60
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ pub fn subcommands() -> Command {
196196
.help("uuid of nexus"),
197197
);
198198

199+
let resize = Command::new("resize")
200+
.about("Resize nexus")
201+
.arg(Arg::new("uuid").required(true).index(1).help("Nexus uuid"))
202+
.arg(
203+
Arg::new("size")
204+
.required(true)
205+
.index(2)
206+
.help("Requested new size of the nexus"),
207+
);
208+
199209
Command::new("nexus")
200210
.subcommand_required(true)
201211
.arg_required_else_help(true)
@@ -210,6 +220,7 @@ pub fn subcommands() -> Command {
210220
.subcommand(ana_state)
211221
.subcommand(list)
212222
.subcommand(children)
223+
.subcommand(resize)
213224
.subcommand(nexus_child_cli::subcommands())
214225
}
215226

@@ -220,6 +231,7 @@ pub async fn handler(ctx: Context, matches: &ArgMatches) -> crate::Result<()> {
220231
("shutdown", args) => nexus_shutdown(ctx, args).await,
221232
("list", args) => nexus_list(ctx, args).await,
222233
("children", args) => nexus_children_2(ctx, args).await,
234+
("resize", args) => nexus_resize(ctx, args).await,
223235
("publish", args) => nexus_publish(ctx, args).await,
224236
("unpublish", args) => nexus_unpublish(ctx, args).await,
225237
("ana_state", args) => nexus_nvme_ana_state(ctx, args).await,
@@ -564,6 +576,54 @@ async fn nexus_children_2(
564576
Ok(())
565577
}
566578

579+
async fn nexus_resize(
580+
mut ctx: Context,
581+
matches: &ArgMatches,
582+
) -> crate::Result<()> {
583+
let uuid = matches
584+
.get_one::<String>("uuid")
585+
.ok_or_else(|| ClientError::MissingValue {
586+
field: "uuid".to_string(),
587+
})?
588+
.to_owned();
589+
590+
let requested_size =
591+
parse_size(matches.get_one::<String>("size").ok_or_else(|| {
592+
ClientError::MissingValue {
593+
field: "size".to_string(),
594+
}
595+
})?)
596+
.map_err(|s| Status::invalid_argument(format!("Bad size '{s}'")))
597+
.context(GrpcStatus)?;
598+
599+
let response = ctx
600+
.v1
601+
.nexus
602+
.resize_nexus(v1::nexus::ResizeNexusRequest {
603+
uuid: uuid.clone(),
604+
requested_size: requested_size.get_bytes() as u64,
605+
})
606+
.await
607+
.context(GrpcStatus)?;
608+
609+
match ctx.output {
610+
OutputFormat::Json => {
611+
println!(
612+
"{}",
613+
serde_json::to_string_pretty(&response.get_ref())
614+
.unwrap()
615+
.to_colored_json_auto()
616+
.unwrap()
617+
);
618+
}
619+
OutputFormat::Default => {
620+
println!("Resized nexus {uuid} to {requested_size}");
621+
}
622+
};
623+
624+
Ok(())
625+
}
626+
567627
async fn nexus_publish(
568628
mut ctx: Context,
569629
matches: &ArgMatches,

0 commit comments

Comments
 (0)