mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Leverage virtio-net to provide connectivity
This patch expand the device registration to add a new virtio-net device in case the user provide the appropriate flag --net from the command line. If the flag is provided, the code will parse the TAP interface name and the expected MAC address from the command line. The VM will be connected to the provided TAP interface, and it will communicate the MAC address to the virtio-net driver. If the flag is not provided, the VM will not register any virtio-net device, therefore it will not have any connectivity with the host. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
committed by
Samuel Ortiz
parent
53f5295454
commit
c0be6642ad
14
src/main.rs
14
src/main.rs
@@ -37,6 +37,12 @@ fn main() {
|
||||
.help("Path to VM disk image")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("net")
|
||||
.long("net")
|
||||
.help("Network parameters \"tap=<if_name>,mac=<mac_addr>\"")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("cpus")
|
||||
.long("cpus")
|
||||
@@ -68,6 +74,11 @@ fn main() {
|
||||
.expect("Missing argument: disk");
|
||||
let disk_path = disk_arg.as_path();
|
||||
|
||||
let mut net_params = None;
|
||||
if let Some(net) = cmd_arguments.value_of("net") {
|
||||
net_params = Some(net.to_string());
|
||||
}
|
||||
|
||||
let mut vcpus = DEFAULT_VCPUS;
|
||||
if let Some(cpus) = cmd_arguments.value_of("cpus") {
|
||||
vcpus = cpus.parse::<u8>().unwrap();
|
||||
@@ -81,7 +92,8 @@ fn main() {
|
||||
println!("VM [{} vCPUS {} MB of memory]", vcpus, memory);
|
||||
println!("Booting {:?}...", kernel_path);
|
||||
|
||||
let vm_config = VmConfig::new(kernel_path, disk_path, cmdline, vcpus, memory).unwrap();
|
||||
let vm_config =
|
||||
VmConfig::new(kernel_path, disk_path, cmdline, net_params, vcpus, memory).unwrap();
|
||||
|
||||
vmm::boot_kernel(vm_config).unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user