mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-16 15:07:46 +00:00
runtime-rs: support qemu in VirtContainer
Added registration of qemu config plugin and support for creating Qemu Hypervisor instance. Signed-off-by: Pavel Mores <pmores@redhat.com>
This commit is contained in:
parent
1413dfe91c
commit
2f6d0d408b
@ -21,7 +21,10 @@ use anyhow::{anyhow, Context, Result};
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use common::{message::Message, RuntimeHandler, RuntimeInstance};
|
use common::{message::Message, RuntimeHandler, RuntimeInstance};
|
||||||
use hypervisor::{dragonball::Dragonball, Hypervisor, HYPERVISOR_DRAGONBALL};
|
use hypervisor::{dragonball::Dragonball, Hypervisor, HYPERVISOR_DRAGONBALL};
|
||||||
use kata_types::config::{hypervisor::register_hypervisor_plugin, DragonballConfig, TomlConfig};
|
use hypervisor::{qemu::Qemu, HYPERVISOR_QEMU};
|
||||||
|
use kata_types::config::{
|
||||||
|
hypervisor::register_hypervisor_plugin, DragonballConfig, QemuConfig, TomlConfig,
|
||||||
|
};
|
||||||
use resource::ResourceManager;
|
use resource::ResourceManager;
|
||||||
use sandbox::VIRTCONTAINER;
|
use sandbox::VIRTCONTAINER;
|
||||||
use tokio::sync::mpsc::Sender;
|
use tokio::sync::mpsc::Sender;
|
||||||
@ -36,6 +39,8 @@ impl RuntimeHandler for VirtContainer {
|
|||||||
// register
|
// register
|
||||||
let dragonball_config = Arc::new(DragonballConfig::new());
|
let dragonball_config = Arc::new(DragonballConfig::new());
|
||||||
register_hypervisor_plugin("dragonball", dragonball_config);
|
register_hypervisor_plugin("dragonball", dragonball_config);
|
||||||
|
let qemu_config = Arc::new(QemuConfig::new());
|
||||||
|
register_hypervisor_plugin("qemu", qemu_config);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,6 +111,13 @@ async fn new_hypervisor(toml_config: &TomlConfig) -> Result<Arc<dyn Hypervisor>>
|
|||||||
.await;
|
.await;
|
||||||
Ok(Arc::new(hypervisor))
|
Ok(Arc::new(hypervisor))
|
||||||
}
|
}
|
||||||
|
HYPERVISOR_QEMU => {
|
||||||
|
let mut hypervisor = Qemu::new();
|
||||||
|
hypervisor
|
||||||
|
.set_hypervisor_config(hypervisor_config.clone())
|
||||||
|
.await;
|
||||||
|
Ok(Arc::new(hypervisor))
|
||||||
|
}
|
||||||
_ => Err(anyhow!("Unsupported hypervisor {}", &hypervisor_name)),
|
_ => Err(anyhow!("Unsupported hypervisor {}", &hypervisor_name)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,4 +161,27 @@ agent_name="kata"
|
|||||||
let res = new_agent(&toml_config);
|
let res = new_agent(&toml_config);
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_new_hypervisor() {
|
||||||
|
VirtContainer::init().unwrap();
|
||||||
|
|
||||||
|
let toml_config = {
|
||||||
|
let config_content = r#"
|
||||||
|
[hypervisor.qemu]
|
||||||
|
path = "/bin/echo"
|
||||||
|
kernel = "/bin/echo"
|
||||||
|
image = "/bin/echo"
|
||||||
|
firmware = ""
|
||||||
|
|
||||||
|
[runtime]
|
||||||
|
hypervisor_name="qemu"
|
||||||
|
"#;
|
||||||
|
TomlConfig::load(config_content).map_err(|e| anyhow!("can not load config toml: {}", e))
|
||||||
|
}
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let res = new_hypervisor(&toml_config).await;
|
||||||
|
assert!(res.is_ok());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user