mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
@@ -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),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
15
src/main.rs
15
src/main.rs
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user