1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
pub mod api;
pub mod capi;
mod driver;
#[macro_use]
extern crate log;
#[macro_use]
extern crate bitflags;
use api::Introspectable;
use api::{DriverInitParam, DriverType};
use driver::dummy::Dummy;
#[cfg(feature = "hyper-v")]
use driver::hyperv::HyperV;
#[cfg(feature = "kvm")]
use driver::kvm::Kvm;
#[cfg(feature = "virtualbox")]
use driver::virtualbox::VBox;
#[cfg(feature = "xen")]
use driver::xen::Xen;
#[cfg(feature = "kvm")]
use kvmi::create_kvmi;
#[allow(unreachable_code)]
pub fn init(
domain_name: &str,
driver_type: Option<DriverType>,
init_option: Option<DriverInitParam>,
) -> Box<dyn Introspectable> {
debug!("Microvmi init");
match driver_type {
Some(drv_type) => match drv_type {
DriverType::Dummy => {
Box::new(Dummy::new(domain_name, init_option)) as Box<dyn Introspectable>
}
#[cfg(feature = "hyper-v")]
DriverType::HyperV => {
Box::new(HyperV::new(domain_name, init_option)) as Box<dyn Introspectable>
}
#[cfg(feature = "kvm")]
DriverType::KVM => create_kvm(domain_name, init_option),
#[cfg(feature = "virtualbox")]
DriverType::VirtualBox => {
Box::new(VBox::new(domain_name, init_option)) as Box<dyn Introspectable>
}
#[cfg(feature = "xen")]
DriverType::Xen => {
Box::new(Xen::new(domain_name, init_option)) as Box<dyn Introspectable>
}
},
None => {
#[cfg(feature = "hyper-v")]
{
return Box::new(HyperV::new(domain_name, init_option)) as Box<dyn Introspectable>;
}
#[cfg(feature = "kvm")]
{
return create_kvm(domain_name, init_option);
}
#[cfg(feature = "virtualbox")]
{
return Box::new(VBox::new(domain_name, init_option)) as Box<dyn Introspectable>;
}
#[cfg(feature = "xen")]
{
return Box::new(Xen::new(domain_name, init_option)) as Box<dyn Introspectable>;
}
Box::new(Dummy::new(domain_name, init_option)) as Box<dyn Introspectable>
}
}
}
#[cfg(feature = "kvm")]
fn create_kvm(domain_name: &str, init_option: Option<DriverInitParam>) -> Box<dyn Introspectable> {
Box::new(Kvm::new(domain_name, create_kvmi(), init_option).unwrap()) as Box<dyn Introspectable>
}