mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Add a VmRestore command
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
committed by
Rob Bradford
parent
39d4f817f0
commit
92c73c3b78
@@ -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"
|
||||
)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user