mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
ch-remote: support live disk resizing
Support disk resizing via ch-remote and REST api. On-behalf-of: SAP thomas.prescher@sap.com Signed-off-by: Thomas Prescher <thomas.prescher@cyberus-technology.de>
This commit is contained in:
committed by
Rob Bradford
parent
aac240d076
commit
5fb078305a
@@ -65,6 +65,8 @@ enum Error {
|
||||
ReadingStdin(#[source] std::io::Error),
|
||||
#[error("Error reading from file")]
|
||||
ReadingFile(#[source] std::io::Error),
|
||||
#[error("Invalid disk size")]
|
||||
InvalidDiskSize(#[source] ByteSizedParseError),
|
||||
}
|
||||
|
||||
enum TargetApi<'a> {
|
||||
@@ -320,6 +322,22 @@ fn rest_api_do_command(matches: &ArgMatches, socket: &mut UnixStream) -> ApiResu
|
||||
)?;
|
||||
simple_api_command(socket, "PUT", "resize", Some(&resize)).map_err(Error::HttpApiClient)
|
||||
}
|
||||
Some("resize-disk") => {
|
||||
let resize_disk = resize_disk_config(
|
||||
matches
|
||||
.subcommand_matches("resize-disk")
|
||||
.unwrap()
|
||||
.get_one::<String>("disk")
|
||||
.unwrap(),
|
||||
matches
|
||||
.subcommand_matches("resize-disk")
|
||||
.unwrap()
|
||||
.get_one::<String>("size")
|
||||
.unwrap(),
|
||||
)?;
|
||||
simple_api_command(socket, "PUT", "resize-disk", Some(&resize_disk))
|
||||
.map_err(Error::HttpApiClient)
|
||||
}
|
||||
Some("resize-zone") => {
|
||||
let resize_zone = resize_zone_config(
|
||||
matches
|
||||
@@ -762,6 +780,15 @@ fn resize_config(
|
||||
Ok(serde_json::to_string(&resize).unwrap())
|
||||
}
|
||||
|
||||
fn resize_disk_config(id: &str, size: &str) -> Result<String, Error> {
|
||||
let resize_disk = vmm::api::VmResizeDiskData {
|
||||
id: id.to_owned(),
|
||||
desired_size: size.parse::<ByteSized>().map_err(Error::InvalidDiskSize)?.0,
|
||||
};
|
||||
|
||||
Ok(serde_json::to_string(&resize_disk).unwrap())
|
||||
}
|
||||
|
||||
fn resize_zone_config(id: &str, size: &str) -> Result<String, Error> {
|
||||
let resize_zone = vmm::api::VmResizeZoneData {
|
||||
id: id.to_owned(),
|
||||
@@ -1022,6 +1049,20 @@ fn get_cli_commands_sorted() -> Box<[Command]> {
|
||||
.help("New memory size in bytes (supports K/M/G suffix)")
|
||||
.num_args(1),
|
||||
),
|
||||
Command::new("resize-disk")
|
||||
.about("Resize an attached disk")
|
||||
.arg(
|
||||
Arg::new("disk")
|
||||
.long("disk")
|
||||
.help("Disk identifier")
|
||||
.num_args(1),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("size")
|
||||
.long("size")
|
||||
.help("New disk size")
|
||||
.num_args(1),
|
||||
),
|
||||
Command::new("resize-zone")
|
||||
.about("Resize a memory zone")
|
||||
.arg(
|
||||
|
||||
Reference in New Issue
Block a user