vmm: Add a VmRestore command

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz
2020-02-26 00:03:06 +01:00
committed by Rob Bradford
parent 39d4f817f0
commit 92c73c3b78
4 changed files with 72 additions and 0 deletions

View File

@@ -2,10 +2,13 @@
//
// SPDX-License-Identifier: Apache-2.0
use crate::config::VmConfig;
use crate::vm::{VmSnapshot, VM_SNAPSHOT_ID};
use anyhow::anyhow;
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use url::Url;
use vm_migration::{MigratableError, Snapshot};
@@ -59,3 +62,23 @@ pub fn recv_vm_snapshot(source_url: &str) -> std::result::Result<Snapshot, Migra
))),
}
}
pub fn vm_config_from_snapshot(
snapshot: &Snapshot,
) -> std::result::Result<Arc<Mutex<VmConfig>>, MigratableError> {
if let Some(vm_section) = snapshot
.snapshot_data
.get(&format!("{}-section", VM_SNAPSHOT_ID))
{
let vm_snapshot: VmSnapshot =
serde_json::from_slice(&vm_section.snapshot).map_err(|e| {
MigratableError::Restore(anyhow!("Could not deserialize VM snapshot {}", e))
})?;
return Ok(vm_snapshot.config);
}
Err(MigratableError::Restore(anyhow!(
"Could not find VM config snapshot section"
)))
}