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-05-06 20:24:57 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("cmdline")
|
|
|
|
.long("cmdline")
|
|
|
|
.help("Kernel command line")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2019-05-06 19:15:44 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("disk")
|
|
|
|
.long("disk")
|
|
|
|
.help("Path to VM disk image")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2019-05-09 15:01:42 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("net")
|
|
|
|
.long("net")
|
|
|
|
.help("Network parameters \"tap=<if_name>,mac=<mac_addr>\"")
|
|
|
|
.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-05-06 20:24:57 +00:00
|
|
|
let cmdline = cmd_arguments
|
|
|
|
.value_of("cmdline")
|
|
|
|
.map(std::string::ToString::to_string)
|
|
|
|
.expect("Missing argument: cmdline");
|
|
|
|
|
2019-05-06 19:15:44 +00:00
|
|
|
let disk_arg = cmd_arguments
|
|
|
|
.value_of("disk")
|
|
|
|
.map(PathBuf::from)
|
|
|
|
.expect("Missing argument: disk");
|
|
|
|
let disk_path = disk_arg.as_path();
|
|
|
|
|
2019-05-09 15:01:42 +00:00
|
|
|
let mut net_params = None;
|
|
|
|
if let Some(net) = cmd_arguments.value_of("net") {
|
|
|
|
net_params = Some(net.to_string());
|
|
|
|
}
|
|
|
|
|
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-05-09 15:01:42 +00:00
|
|
|
let vm_config =
|
|
|
|
VmConfig::new(kernel_path, disk_path, cmdline, net_params, 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
|
|
|
}
|