2019-02-21 16:39:34 +00:00
|
|
|
// Copyright © 2019 Intel Corporation
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//
|
|
|
|
|
2019-02-22 16:05:02 +00:00
|
|
|
extern crate vmm;
|
|
|
|
|
2019-02-21 16:39:34 +00:00
|
|
|
#[macro_use(crate_version, crate_authors)]
|
|
|
|
extern crate clap;
|
|
|
|
|
|
|
|
use clap::{App, Arg};
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2019-03-07 13:56:43 +00:00
|
|
|
use vmm::vm::*;
|
|
|
|
|
2019-02-21 16:04:44 +00:00
|
|
|
fn main() {
|
2019-02-21 16:39:34 +00:00
|
|
|
let cmd_arguments = App::new("cloud-hypervisor")
|
|
|
|
.version(crate_version!())
|
|
|
|
.author(crate_authors!())
|
|
|
|
.about("Launch a cloud-hypervisor VMM.")
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("kernel")
|
|
|
|
.long("kernel")
|
|
|
|
.help("Path to kernel image (vmlinux)")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2019-03-11 16:36:27 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("cpus")
|
|
|
|
.long("cpus")
|
|
|
|
.help("Number of virtual CPUs")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2019-03-11 16:48:35 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("memory")
|
|
|
|
.long("memory")
|
|
|
|
.help("Amount of RAM (in MB)")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2019-02-21 16:39:34 +00:00
|
|
|
.get_matches();
|
|
|
|
|
2019-03-07 13:56:43 +00:00
|
|
|
let kernel_arg = cmd_arguments
|
2019-02-21 16:39:34 +00:00
|
|
|
.value_of("kernel")
|
|
|
|
.map(PathBuf::from)
|
|
|
|
.expect("Missing argument: kernel");
|
|
|
|
|
2019-03-07 13:56:43 +00:00
|
|
|
let kernel_path = kernel_arg.as_path();
|
|
|
|
|
2019-03-11 16:36:27 +00:00
|
|
|
let mut vcpus = DEFAULT_VCPUS;
|
|
|
|
if let Some(cpus) = cmd_arguments.value_of("cpus") {
|
|
|
|
vcpus = cpus.parse::<u8>().unwrap();
|
|
|
|
}
|
|
|
|
|
2019-03-11 16:48:35 +00:00
|
|
|
let mut memory = DEFAULT_MEMORY;
|
|
|
|
if let Some(mem) = cmd_arguments.value_of("memory") {
|
|
|
|
memory = mem.parse::<u64>().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("VM [{} vCPUS {} MB of memory]", vcpus, memory);
|
2019-03-07 13:56:43 +00:00
|
|
|
println!("Booting {:?}...", kernel_path);
|
|
|
|
|
2019-03-11 16:48:35 +00:00
|
|
|
let vm_config = VmConfig::new(kernel_path, vcpus, memory).unwrap();
|
2019-02-22 16:05:02 +00:00
|
|
|
|
2019-03-07 13:56:43 +00:00
|
|
|
vmm::boot_kernel(vm_config).unwrap();
|
2019-02-21 16:04:44 +00:00
|
|
|
}
|