vmm: Move restore parameters into common RestoreConfig structure

The goal here is to move the restore parameters into a dedicated
structure that can be reused from the entire codebase, making the
addition or removal of a parameter easier.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2020-04-07 14:50:19 +02:00
parent 6712958f23
commit a517ca23a0
7 changed files with 63 additions and 29 deletions

View File

@@ -26,6 +26,7 @@ enum Error {
AddDiskConfig(vmm::config::Error),
AddPmemConfig(vmm::config::Error),
AddNetConfig(vmm::config::Error),
Restore(vmm::config::Error),
}
#[derive(Clone, Copy, Debug)]
@@ -262,10 +263,8 @@ fn snapshot_api_command(socket: &mut UnixStream, url: &str) -> Result<(), Error>
)
}
fn restore_api_command(socket: &mut UnixStream, url: &str) -> Result<(), Error> {
let restore_config = vmm::api::VmRestoreConfig {
source_url: String::from(url),
};
fn restore_api_command(socket: &mut UnixStream, config: &str) -> Result<(), Error> {
let restore_config = vmm::config::RestoreConfig::parse(config).map_err(Error::Restore)?;
simple_api_command(
socket,
@@ -445,7 +444,7 @@ fn main() {
.arg(
Arg::with_name("restore_config")
.index(1)
.help("<source_url>"),
.help(vmm::config::RestoreConfig::SYNTAX),
),
);

View File

@@ -234,10 +234,7 @@ fn create_app<'a, 'b>(
.arg(
Arg::with_name("restore")
.long("restore")
.help(
"Restore from a VM snapshot. \
Should be a valid URL (e.g file:///foo/bar or tcp://192.168.1.10/foo)",
)
.help(config::RestoreConfig::SYNTAX)
.takes_value(true)
.min_values(1)
.group("vmm-config"),
@@ -344,12 +341,16 @@ fn start_vmm(cmd_arguments: ArgMatches) {
)
.expect("Could not create the VM");
vmm::api::vm_boot(api_evt.try_clone().unwrap(), sender).expect("Could not boot the VM");
} else if let Some(restore_url) = cmd_arguments.value_of("restore") {
} else if let Some(restore_params) = cmd_arguments.value_of("restore") {
vmm::api::vm_restore(
api_evt.try_clone().unwrap(),
api_request_sender,
Arc::new(vmm::api::VmRestoreConfig {
source_url: restore_url.to_string(),
Arc::new(match config::RestoreConfig::parse(restore_params) {
Ok(config) => config,
Err(e) => {
println!("{}", e);
process::exit(1);
}
}),
)
.expect("Could not restore the VM");