mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-01 02:55:45 +00:00
main: Move VmParams creation into a dedicated function
This brings more modularity to the code, which will be helpful when we will later test the CLI and OpenAPI generate the same VmConfig output. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
17a167dbb6
commit
43bd0e53c4
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1114,6 +1114,7 @@ dependencies = [
|
|||||||
"acpi_tables 0.1.0",
|
"acpi_tables 0.1.0",
|
||||||
"anyhow 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
"anyhow 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"arch 0.1.0",
|
"arch 0.1.0",
|
||||||
|
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"devices 0.1.0",
|
"devices 0.1.0",
|
||||||
"epoll 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"epoll 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"kvm-bindings 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"kvm-bindings 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
41
src/main.rs
41
src/main.rs
@ -287,28 +287,7 @@ fn main() {
|
|||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
// These .unwrap()s cannot fail as there is a default value defined
|
let vm_params = config::VmParams::from_arg_matches(&cmd_arguments);
|
||||||
let cpus = cmd_arguments.value_of("cpus").unwrap();
|
|
||||||
let memory = cmd_arguments.value_of("memory").unwrap();
|
|
||||||
let rng = cmd_arguments.value_of("rng").unwrap();
|
|
||||||
let serial = cmd_arguments.value_of("serial").unwrap();
|
|
||||||
|
|
||||||
let kernel = cmd_arguments.value_of("kernel");
|
|
||||||
let cmdline = cmd_arguments.value_of("cmdline");
|
|
||||||
|
|
||||||
let disks: Option<Vec<&str>> = cmd_arguments.values_of("disk").map(|x| x.collect());
|
|
||||||
let net: Option<Vec<&str>> = cmd_arguments.values_of("net").map(|x| x.collect());
|
|
||||||
let console = cmd_arguments.value_of("console").unwrap();
|
|
||||||
let fs: Option<Vec<&str>> = cmd_arguments.values_of("fs").map(|x| x.collect());
|
|
||||||
let pmem: Option<Vec<&str>> = cmd_arguments.values_of("pmem").map(|x| x.collect());
|
|
||||||
let devices: Option<Vec<&str>> = cmd_arguments.values_of("device").map(|x| x.collect());
|
|
||||||
let vhost_user_net: Option<Vec<&str>> = cmd_arguments
|
|
||||||
.values_of("vhost-user-net")
|
|
||||||
.map(|x| x.collect());
|
|
||||||
let vhost_user_blk: Option<Vec<&str>> = cmd_arguments
|
|
||||||
.values_of("vhost-user-blk")
|
|
||||||
.map(|x| x.collect());
|
|
||||||
let vsock: Option<Vec<&str>> = cmd_arguments.values_of("vsock").map(|x| x.collect());
|
|
||||||
|
|
||||||
let log_level = match cmd_arguments.occurrences_of("v") {
|
let log_level = match cmd_arguments.occurrences_of("v") {
|
||||||
0 => LevelFilter::Error,
|
0 => LevelFilter::Error,
|
||||||
@ -334,23 +313,7 @@ fn main() {
|
|||||||
.map(|()| log::set_max_level(log_level))
|
.map(|()| log::set_max_level(log_level))
|
||||||
.expect("Expected to be able to setup logger");
|
.expect("Expected to be able to setup logger");
|
||||||
|
|
||||||
let vm_config = match config::VmConfig::parse(config::VmParams {
|
let vm_config = match config::VmConfig::parse(vm_params) {
|
||||||
cpus,
|
|
||||||
memory,
|
|
||||||
kernel,
|
|
||||||
cmdline,
|
|
||||||
disks,
|
|
||||||
net,
|
|
||||||
rng,
|
|
||||||
fs,
|
|
||||||
pmem,
|
|
||||||
serial,
|
|
||||||
console,
|
|
||||||
devices,
|
|
||||||
vhost_user_net,
|
|
||||||
vhost_user_blk,
|
|
||||||
vsock,
|
|
||||||
}) {
|
|
||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Failed parsing parameters {:?}", e);
|
println!("Failed parsing parameters {:?}", e);
|
||||||
|
@ -12,6 +12,7 @@ mmio_support = ["vm-virtio/mmio_support"]
|
|||||||
cmos = ["devices/cmos"]
|
cmos = ["devices/cmos"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
clap = "2.33.0"
|
||||||
acpi_tables = { path = "../acpi_tables", optional = true }
|
acpi_tables = { path = "../acpi_tables", optional = true }
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
arch = { path = "../arch" }
|
arch = { path = "../arch" }
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
extern crate vm_virtio;
|
extern crate vm_virtio;
|
||||||
|
|
||||||
|
use clap::ArgMatches;
|
||||||
use net_util::MacAddr;
|
use net_util::MacAddr;
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use std::net::AddrParseError;
|
use std::net::AddrParseError;
|
||||||
@ -106,6 +107,49 @@ pub struct VmParams<'a> {
|
|||||||
pub vsock: Option<Vec<&'a str>>,
|
pub vsock: Option<Vec<&'a str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> VmParams<'a> {
|
||||||
|
pub fn from_arg_matches(args: &'a ArgMatches) -> Self {
|
||||||
|
// These .unwrap()s cannot fail as there is a default value defined
|
||||||
|
let cpus = args.value_of("cpus").unwrap();
|
||||||
|
let memory = args.value_of("memory").unwrap();
|
||||||
|
let rng = args.value_of("rng").unwrap();
|
||||||
|
let serial = args.value_of("serial").unwrap();
|
||||||
|
|
||||||
|
let kernel = args.value_of("kernel");
|
||||||
|
let cmdline = args.value_of("cmdline");
|
||||||
|
|
||||||
|
let disks: Option<Vec<&str>> = args.values_of("disk").map(|x| x.collect());
|
||||||
|
let net: Option<Vec<&str>> = args.values_of("net").map(|x| x.collect());
|
||||||
|
let console = args.value_of("console").unwrap();
|
||||||
|
let fs: Option<Vec<&str>> = args.values_of("fs").map(|x| x.collect());
|
||||||
|
let pmem: Option<Vec<&str>> = args.values_of("pmem").map(|x| x.collect());
|
||||||
|
let devices: Option<Vec<&str>> = args.values_of("device").map(|x| x.collect());
|
||||||
|
let vhost_user_net: Option<Vec<&str>> =
|
||||||
|
args.values_of("vhost-user-net").map(|x| x.collect());
|
||||||
|
let vhost_user_blk: Option<Vec<&str>> =
|
||||||
|
args.values_of("vhost-user-blk").map(|x| x.collect());
|
||||||
|
let vsock: Option<Vec<&str>> = args.values_of("vsock").map(|x| x.collect());
|
||||||
|
|
||||||
|
VmParams {
|
||||||
|
cpus,
|
||||||
|
memory,
|
||||||
|
kernel,
|
||||||
|
cmdline,
|
||||||
|
disks,
|
||||||
|
net,
|
||||||
|
rng,
|
||||||
|
fs,
|
||||||
|
pmem,
|
||||||
|
serial,
|
||||||
|
console,
|
||||||
|
devices,
|
||||||
|
vhost_user_net,
|
||||||
|
vhost_user_blk,
|
||||||
|
vsock,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_size(size: &str) -> Result<u64> {
|
fn parse_size(size: &str) -> Result<u64> {
|
||||||
let s = size.trim();
|
let s = size.trim();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user