2020-03-06 15:32:06 +00:00
|
|
|
// Copyright © 2020 Intel Corporation
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//
|
|
|
|
|
|
|
|
#[macro_use(crate_authors)]
|
|
|
|
extern crate clap;
|
|
|
|
|
2020-10-23 10:20:37 +00:00
|
|
|
use api_client::simple_api_command;
|
2021-07-20 13:46:18 +00:00
|
|
|
use api_client::simple_api_command_with_fds;
|
2020-10-23 10:20:37 +00:00
|
|
|
use api_client::Error as ApiClientError;
|
2021-12-31 23:09:17 +00:00
|
|
|
use clap::{App, AppSettings, Arg, ArgMatches};
|
2020-09-08 14:51:00 +00:00
|
|
|
use option_parser::{ByteSized, ByteSizedParseError};
|
2020-06-08 14:25:37 +00:00
|
|
|
use std::fmt;
|
2020-03-06 15:32:06 +00:00
|
|
|
use std::os::unix::net::UnixStream;
|
|
|
|
use std::process;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
enum Error {
|
2020-10-23 10:20:37 +00:00
|
|
|
Connect(std::io::Error),
|
|
|
|
ApiClient(ApiClientError),
|
2021-03-25 17:01:21 +00:00
|
|
|
InvalidCpuCount(std::num::ParseIntError),
|
2020-09-08 14:51:00 +00:00
|
|
|
InvalidMemorySize(ByteSizedParseError),
|
|
|
|
InvalidBalloonSize(ByteSizedParseError),
|
2020-03-10 16:38:04 +00:00
|
|
|
AddDeviceConfig(vmm::config::Error),
|
2020-03-23 16:28:09 +00:00
|
|
|
AddDiskConfig(vmm::config::Error),
|
2020-04-14 08:13:48 +00:00
|
|
|
AddFsConfig(vmm::config::Error),
|
2020-03-23 16:28:09 +00:00
|
|
|
AddPmemConfig(vmm::config::Error),
|
2020-03-23 16:28:09 +00:00
|
|
|
AddNetConfig(vmm::config::Error),
|
2021-07-30 14:49:22 +00:00
|
|
|
AddUserDeviceConfig(vmm::config::Error),
|
2020-04-29 09:48:43 +00:00
|
|
|
AddVsockConfig(vmm::config::Error),
|
2020-04-07 12:50:19 +00:00
|
|
|
Restore(vmm::config::Error),
|
2020-03-06 15:32:06 +00:00
|
|
|
}
|
|
|
|
|
2020-06-08 14:25:37 +00:00
|
|
|
impl fmt::Display for Error {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use Error::*;
|
|
|
|
match self {
|
2020-10-23 10:20:37 +00:00
|
|
|
ApiClient(e) => e.fmt(f),
|
2020-11-24 15:42:41 +00:00
|
|
|
Connect(e) => write!(f, "Error opening HTTP socket: {}", e),
|
2021-03-25 17:01:21 +00:00
|
|
|
InvalidCpuCount(e) => write!(f, "Error parsing CPU count: {}", e),
|
2020-09-08 14:51:00 +00:00
|
|
|
InvalidMemorySize(e) => write!(f, "Error parsing memory size: {:?}", e),
|
|
|
|
InvalidBalloonSize(e) => write!(f, "Error parsing balloon size: {:?}", e),
|
2020-06-08 14:25:37 +00:00
|
|
|
AddDeviceConfig(e) => write!(f, "Error parsing device syntax: {}", e),
|
|
|
|
AddDiskConfig(e) => write!(f, "Error parsing disk syntax: {}", e),
|
|
|
|
AddFsConfig(e) => write!(f, "Error parsing filesystem syntax: {}", e),
|
|
|
|
AddPmemConfig(e) => write!(f, "Error parsing persistent memory syntax: {}", e),
|
|
|
|
AddNetConfig(e) => write!(f, "Error parsing network syntax: {}", e),
|
2021-07-30 14:49:22 +00:00
|
|
|
AddUserDeviceConfig(e) => write!(f, "Error parsing user device syntax: {}", e),
|
2020-06-08 14:25:37 +00:00
|
|
|
AddVsockConfig(e) => write!(f, "Error parsing vsock syntax: {}", e),
|
|
|
|
Restore(e) => write!(f, "Error parsing restore syntax: {}", e),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-10 11:34:27 +00:00
|
|
|
fn resize_api_command(
|
|
|
|
socket: &mut UnixStream,
|
|
|
|
cpus: Option<&str>,
|
|
|
|
memory: Option<&str>,
|
2020-04-03 09:27:20 +00:00
|
|
|
balloon: Option<&str>,
|
2020-03-10 11:34:27 +00:00
|
|
|
) -> Result<(), Error> {
|
|
|
|
let desired_vcpus: Option<u8> = if let Some(cpus) = cpus {
|
2021-03-25 17:01:21 +00:00
|
|
|
Some(cpus.parse().map_err(Error::InvalidCpuCount)?)
|
2020-03-10 11:34:27 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
let desired_ram: Option<u64> = if let Some(memory) = memory {
|
2020-09-08 14:51:00 +00:00
|
|
|
Some(
|
|
|
|
memory
|
|
|
|
.parse::<ByteSized>()
|
|
|
|
.map_err(Error::InvalidMemorySize)?
|
|
|
|
.0,
|
|
|
|
)
|
2020-03-10 11:34:27 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2020-10-14 10:04:42 +00:00
|
|
|
let desired_balloon: Option<u64> = if let Some(balloon) = balloon {
|
2020-09-08 14:51:00 +00:00
|
|
|
Some(
|
|
|
|
balloon
|
|
|
|
.parse::<ByteSized>()
|
|
|
|
.map_err(Error::InvalidBalloonSize)?
|
|
|
|
.0,
|
|
|
|
)
|
2020-04-03 09:27:20 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2020-03-10 11:34:27 +00:00
|
|
|
let resize = vmm::api::VmResizeData {
|
|
|
|
desired_vcpus,
|
|
|
|
desired_ram,
|
2020-10-14 10:04:42 +00:00
|
|
|
desired_balloon,
|
2020-03-10 11:34:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
simple_api_command(
|
|
|
|
socket,
|
|
|
|
"PUT",
|
|
|
|
"resize",
|
|
|
|
Some(&serde_json::to_string(&resize).unwrap()),
|
|
|
|
)
|
2020-10-23 10:20:37 +00:00
|
|
|
.map_err(Error::ApiClient)
|
2020-03-10 11:34:27 +00:00
|
|
|
}
|
|
|
|
|
2020-09-10 15:34:15 +00:00
|
|
|
fn resize_zone_api_command(socket: &mut UnixStream, id: &str, size: &str) -> Result<(), Error> {
|
|
|
|
let resize_zone = vmm::api::VmResizeZoneData {
|
|
|
|
id: id.to_owned(),
|
|
|
|
desired_ram: size
|
|
|
|
.parse::<ByteSized>()
|
|
|
|
.map_err(Error::InvalidMemorySize)?
|
|
|
|
.0,
|
|
|
|
};
|
|
|
|
|
|
|
|
simple_api_command(
|
|
|
|
socket,
|
|
|
|
"PUT",
|
|
|
|
"resize-zone",
|
|
|
|
Some(&serde_json::to_string(&resize_zone).unwrap()),
|
|
|
|
)
|
2020-10-23 10:20:37 +00:00
|
|
|
.map_err(Error::ApiClient)
|
2020-09-10 15:34:15 +00:00
|
|
|
}
|
|
|
|
|
2020-03-10 16:38:04 +00:00
|
|
|
fn add_device_api_command(socket: &mut UnixStream, config: &str) -> Result<(), Error> {
|
|
|
|
let device_config = vmm::config::DeviceConfig::parse(config).map_err(Error::AddDeviceConfig)?;
|
|
|
|
|
|
|
|
simple_api_command(
|
|
|
|
socket,
|
|
|
|
"PUT",
|
|
|
|
"add-device",
|
|
|
|
Some(&serde_json::to_string(&device_config).unwrap()),
|
|
|
|
)
|
2020-10-23 10:20:37 +00:00
|
|
|
.map_err(Error::ApiClient)
|
2020-03-10 16:38:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 14:49:22 +00:00
|
|
|
fn add_user_device_api_command(socket: &mut UnixStream, config: &str) -> Result<(), Error> {
|
|
|
|
let device_config =
|
|
|
|
vmm::config::UserDeviceConfig::parse(config).map_err(Error::AddUserDeviceConfig)?;
|
|
|
|
|
|
|
|
simple_api_command(
|
|
|
|
socket,
|
|
|
|
"PUT",
|
|
|
|
"add-user-device",
|
|
|
|
Some(&serde_json::to_string(&device_config).unwrap()),
|
|
|
|
)
|
|
|
|
.map_err(Error::ApiClient)
|
|
|
|
}
|
|
|
|
|
2020-03-10 16:38:04 +00:00
|
|
|
fn remove_device_api_command(socket: &mut UnixStream, id: &str) -> Result<(), Error> {
|
|
|
|
let remove_device_data = vmm::api::VmRemoveDeviceData { id: id.to_owned() };
|
|
|
|
|
|
|
|
simple_api_command(
|
|
|
|
socket,
|
|
|
|
"PUT",
|
|
|
|
"remove-device",
|
|
|
|
Some(&serde_json::to_string(&remove_device_data).unwrap()),
|
|
|
|
)
|
2020-10-23 10:20:37 +00:00
|
|
|
.map_err(Error::ApiClient)
|
2020-03-10 16:38:04 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 16:28:09 +00:00
|
|
|
fn add_disk_api_command(socket: &mut UnixStream, config: &str) -> Result<(), Error> {
|
|
|
|
let disk_config = vmm::config::DiskConfig::parse(config).map_err(Error::AddDiskConfig)?;
|
|
|
|
|
|
|
|
simple_api_command(
|
|
|
|
socket,
|
|
|
|
"PUT",
|
|
|
|
"add-disk",
|
|
|
|
Some(&serde_json::to_string(&disk_config).unwrap()),
|
|
|
|
)
|
2020-10-23 10:20:37 +00:00
|
|
|
.map_err(Error::ApiClient)
|
2020-03-23 16:28:09 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 08:13:48 +00:00
|
|
|
fn add_fs_api_command(socket: &mut UnixStream, config: &str) -> Result<(), Error> {
|
|
|
|
let fs_config = vmm::config::FsConfig::parse(config).map_err(Error::AddFsConfig)?;
|
|
|
|
|
|
|
|
simple_api_command(
|
|
|
|
socket,
|
|
|
|
"PUT",
|
|
|
|
"add-fs",
|
|
|
|
Some(&serde_json::to_string(&fs_config).unwrap()),
|
|
|
|
)
|
2020-10-23 10:20:37 +00:00
|
|
|
.map_err(Error::ApiClient)
|
2020-04-14 08:13:48 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 16:28:09 +00:00
|
|
|
fn add_pmem_api_command(socket: &mut UnixStream, config: &str) -> Result<(), Error> {
|
|
|
|
let pmem_config = vmm::config::PmemConfig::parse(config).map_err(Error::AddPmemConfig)?;
|
|
|
|
|
|
|
|
simple_api_command(
|
|
|
|
socket,
|
|
|
|
"PUT",
|
|
|
|
"add-pmem",
|
|
|
|
Some(&serde_json::to_string(&pmem_config).unwrap()),
|
|
|
|
)
|
2020-10-23 10:20:37 +00:00
|
|
|
.map_err(Error::ApiClient)
|
2020-03-23 16:28:09 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 16:28:09 +00:00
|
|
|
fn add_net_api_command(socket: &mut UnixStream, config: &str) -> Result<(), Error> {
|
2021-07-20 13:46:18 +00:00
|
|
|
let mut net_config = vmm::config::NetConfig::parse(config).map_err(Error::AddNetConfig)?;
|
2020-03-23 16:28:09 +00:00
|
|
|
|
2021-07-20 13:46:18 +00:00
|
|
|
// NetConfig is modified on purpose here by taking the list of file
|
|
|
|
// descriptors out. Keeping the list and send it to the server side
|
|
|
|
// process would not make any sense since the file descriptor may be
|
|
|
|
// represented with different values.
|
|
|
|
let fds = net_config.fds.take().unwrap_or_default();
|
|
|
|
|
|
|
|
simple_api_command_with_fds(
|
2020-03-23 16:28:09 +00:00
|
|
|
socket,
|
|
|
|
"PUT",
|
|
|
|
"add-net",
|
|
|
|
Some(&serde_json::to_string(&net_config).unwrap()),
|
2021-07-20 13:46:18 +00:00
|
|
|
fds,
|
2020-03-23 16:28:09 +00:00
|
|
|
)
|
2020-10-23 10:20:37 +00:00
|
|
|
.map_err(Error::ApiClient)
|
2020-03-23 16:28:09 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 09:48:43 +00:00
|
|
|
fn add_vsock_api_command(socket: &mut UnixStream, config: &str) -> Result<(), Error> {
|
|
|
|
let vsock_config = vmm::config::VsockConfig::parse(config).map_err(Error::AddVsockConfig)?;
|
|
|
|
|
|
|
|
simple_api_command(
|
|
|
|
socket,
|
|
|
|
"PUT",
|
|
|
|
"add-vsock",
|
|
|
|
Some(&serde_json::to_string(&vsock_config).unwrap()),
|
|
|
|
)
|
2020-10-23 10:20:37 +00:00
|
|
|
.map_err(Error::ApiClient)
|
2020-04-29 09:48:43 +00:00
|
|
|
}
|
|
|
|
|
2020-04-02 09:12:54 +00:00
|
|
|
fn snapshot_api_command(socket: &mut UnixStream, url: &str) -> Result<(), Error> {
|
|
|
|
let snapshot_config = vmm::api::VmSnapshotConfig {
|
|
|
|
destination_url: String::from(url),
|
|
|
|
};
|
|
|
|
|
|
|
|
simple_api_command(
|
|
|
|
socket,
|
|
|
|
"PUT",
|
|
|
|
"snapshot",
|
|
|
|
Some(&serde_json::to_string(&snapshot_config).unwrap()),
|
|
|
|
)
|
2020-10-23 10:20:37 +00:00
|
|
|
.map_err(Error::ApiClient)
|
2020-04-02 09:12:54 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 12:50:19 +00:00
|
|
|
fn restore_api_command(socket: &mut UnixStream, config: &str) -> Result<(), Error> {
|
|
|
|
let restore_config = vmm::config::RestoreConfig::parse(config).map_err(Error::Restore)?;
|
2020-04-02 09:20:02 +00:00
|
|
|
|
|
|
|
simple_api_command(
|
|
|
|
socket,
|
|
|
|
"PUT",
|
|
|
|
"restore",
|
|
|
|
Some(&serde_json::to_string(&restore_config).unwrap()),
|
|
|
|
)
|
2020-10-23 10:20:37 +00:00
|
|
|
.map_err(Error::ApiClient)
|
2020-04-02 09:20:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 16:37:18 +00:00
|
|
|
fn receive_migration_api_command(socket: &mut UnixStream, url: &str) -> Result<(), Error> {
|
|
|
|
let receive_migration_data = vmm::api::VmReceiveMigrationData {
|
|
|
|
receiver_url: url.to_owned(),
|
|
|
|
};
|
|
|
|
simple_api_command(
|
|
|
|
socket,
|
|
|
|
"PUT",
|
|
|
|
"receive-migration",
|
|
|
|
Some(&serde_json::to_string(&receive_migration_data).unwrap()),
|
|
|
|
)
|
|
|
|
.map_err(Error::ApiClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn send_migration_api_command(socket: &mut UnixStream, url: &str) -> Result<(), Error> {
|
|
|
|
let send_migration_data = vmm::api::VmSendMigrationData {
|
|
|
|
destination_url: url.to_owned(),
|
|
|
|
};
|
|
|
|
simple_api_command(
|
|
|
|
socket,
|
|
|
|
"PUT",
|
|
|
|
"send-migration",
|
|
|
|
Some(&serde_json::to_string(&send_migration_data).unwrap()),
|
|
|
|
)
|
|
|
|
.map_err(Error::ApiClient)
|
|
|
|
}
|
|
|
|
|
2020-03-06 15:32:06 +00:00
|
|
|
fn do_command(matches: &ArgMatches) -> Result<(), Error> {
|
|
|
|
let mut socket =
|
2020-10-23 10:20:37 +00:00
|
|
|
UnixStream::connect(matches.value_of("api-socket").unwrap()).map_err(Error::Connect)?;
|
2020-03-06 15:32:06 +00:00
|
|
|
|
|
|
|
match matches.subcommand_name() {
|
2020-10-23 10:20:37 +00:00
|
|
|
Some("info") => {
|
|
|
|
simple_api_command(&mut socket, "GET", "info", None).map_err(Error::ApiClient)
|
|
|
|
}
|
|
|
|
Some("counters") => {
|
|
|
|
simple_api_command(&mut socket, "GET", "counters", None).map_err(Error::ApiClient)
|
|
|
|
}
|
2020-03-10 11:34:27 +00:00
|
|
|
Some("resize") => resize_api_command(
|
|
|
|
&mut socket,
|
|
|
|
matches
|
|
|
|
.subcommand_matches("resize")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("cpus"),
|
|
|
|
matches
|
|
|
|
.subcommand_matches("resize")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("memory"),
|
2020-04-03 09:27:20 +00:00
|
|
|
matches
|
|
|
|
.subcommand_matches("resize")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("balloon"),
|
2020-03-10 11:34:27 +00:00
|
|
|
),
|
2020-09-10 15:34:15 +00:00
|
|
|
Some("resize-zone") => resize_zone_api_command(
|
|
|
|
&mut socket,
|
|
|
|
matches
|
|
|
|
.subcommand_matches("resize-zone")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("id")
|
|
|
|
.unwrap(),
|
|
|
|
matches
|
|
|
|
.subcommand_matches("resize-zone")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("size")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2020-03-10 16:38:04 +00:00
|
|
|
Some("add-device") => add_device_api_command(
|
|
|
|
&mut socket,
|
|
|
|
matches
|
|
|
|
.subcommand_matches("add-device")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("device_config")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2020-03-10 16:38:04 +00:00
|
|
|
Some("remove-device") => remove_device_api_command(
|
|
|
|
&mut socket,
|
|
|
|
matches
|
|
|
|
.subcommand_matches("remove-device")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("id")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2020-03-23 16:28:09 +00:00
|
|
|
Some("add-disk") => add_disk_api_command(
|
|
|
|
&mut socket,
|
|
|
|
matches
|
|
|
|
.subcommand_matches("add-disk")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("disk_config")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2020-04-14 08:13:48 +00:00
|
|
|
Some("add-fs") => add_fs_api_command(
|
|
|
|
&mut socket,
|
|
|
|
matches
|
|
|
|
.subcommand_matches("add-fs")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("fs_config")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2020-03-23 16:28:09 +00:00
|
|
|
Some("add-pmem") => add_pmem_api_command(
|
|
|
|
&mut socket,
|
|
|
|
matches
|
|
|
|
.subcommand_matches("add-pmem")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("pmem_config")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2020-03-23 16:28:09 +00:00
|
|
|
Some("add-net") => add_net_api_command(
|
|
|
|
&mut socket,
|
|
|
|
matches
|
|
|
|
.subcommand_matches("add-net")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("net_config")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2021-07-30 14:49:22 +00:00
|
|
|
Some("add-user-device") => add_user_device_api_command(
|
|
|
|
&mut socket,
|
|
|
|
matches
|
|
|
|
.subcommand_matches("add-user-device")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("device_config")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2020-04-29 09:48:43 +00:00
|
|
|
Some("add-vsock") => add_vsock_api_command(
|
|
|
|
&mut socket,
|
|
|
|
matches
|
|
|
|
.subcommand_matches("add-vsock")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("vsock_config")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2020-04-02 09:12:54 +00:00
|
|
|
Some("snapshot") => snapshot_api_command(
|
|
|
|
&mut socket,
|
|
|
|
matches
|
|
|
|
.subcommand_matches("snapshot")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("snapshot_config")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2020-04-02 09:20:02 +00:00
|
|
|
Some("restore") => restore_api_command(
|
|
|
|
&mut socket,
|
|
|
|
matches
|
|
|
|
.subcommand_matches("restore")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("restore_config")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2020-11-02 16:37:18 +00:00
|
|
|
Some("send-migration") => send_migration_api_command(
|
|
|
|
&mut socket,
|
|
|
|
matches
|
|
|
|
.subcommand_matches("send-migration")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("send_migration_config")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
|
|
|
Some("receive-migration") => receive_migration_api_command(
|
|
|
|
&mut socket,
|
|
|
|
matches
|
|
|
|
.subcommand_matches("receive-migration")
|
|
|
|
.unwrap()
|
|
|
|
.value_of("receive_migration_config")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2020-10-23 10:20:37 +00:00
|
|
|
Some(c) => simple_api_command(&mut socket, "PUT", c, None).map_err(Error::ApiClient),
|
2020-03-06 15:32:06 +00:00
|
|
|
None => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let app = App::new("ch-remote")
|
|
|
|
.author(crate_authors!())
|
|
|
|
.setting(AppSettings::SubcommandRequired)
|
|
|
|
.about("Remotely control a cloud-hypervisor VMM.")
|
|
|
|
.arg(
|
2021-12-31 23:09:17 +00:00
|
|
|
Arg::new("api-socket")
|
2020-03-06 15:32:06 +00:00
|
|
|
.long("api-socket")
|
|
|
|
.help("HTTP API socket path (UNIX domain socket).")
|
|
|
|
.takes_value(true)
|
2020-05-08 08:27:38 +00:00
|
|
|
.number_of_values(1)
|
2020-03-06 15:32:06 +00:00
|
|
|
.required(true),
|
|
|
|
)
|
2020-03-10 16:38:04 +00:00
|
|
|
.subcommand(
|
2021-12-31 23:09:17 +00:00
|
|
|
App::new("add-device").about("Add VFIO device").arg(
|
|
|
|
Arg::new("device_config")
|
|
|
|
.index(1)
|
|
|
|
.help(vmm::config::DeviceConfig::SYNTAX),
|
|
|
|
),
|
2020-03-10 16:38:04 +00:00
|
|
|
)
|
2020-03-23 16:28:09 +00:00
|
|
|
.subcommand(
|
2021-12-31 23:09:17 +00:00
|
|
|
App::new("add-disk").about("Add block device").arg(
|
|
|
|
Arg::new("disk_config")
|
|
|
|
.index(1)
|
|
|
|
.help(vmm::config::DiskConfig::SYNTAX),
|
|
|
|
),
|
2020-03-23 16:28:09 +00:00
|
|
|
)
|
2020-04-14 08:13:48 +00:00
|
|
|
.subcommand(
|
2021-12-31 23:09:17 +00:00
|
|
|
App::new("add-fs")
|
2020-04-14 08:13:48 +00:00
|
|
|
.about("Add virtio-fs backed fs device")
|
|
|
|
.arg(
|
2021-12-31 23:09:17 +00:00
|
|
|
Arg::new("fs_config")
|
2020-04-14 08:13:48 +00:00
|
|
|
.index(1)
|
|
|
|
.help(vmm::config::FsConfig::SYNTAX),
|
|
|
|
),
|
|
|
|
)
|
2020-03-23 16:28:09 +00:00
|
|
|
.subcommand(
|
2021-12-31 23:09:17 +00:00
|
|
|
App::new("add-pmem")
|
2020-03-23 16:28:09 +00:00
|
|
|
.about("Add persistent memory device")
|
|
|
|
.arg(
|
2021-12-31 23:09:17 +00:00
|
|
|
Arg::new("pmem_config")
|
2020-03-23 16:28:09 +00:00
|
|
|
.index(1)
|
|
|
|
.help(vmm::config::PmemConfig::SYNTAX),
|
|
|
|
),
|
|
|
|
)
|
2020-03-23 16:28:09 +00:00
|
|
|
.subcommand(
|
2021-12-31 23:09:17 +00:00
|
|
|
App::new("add-net").about("Add network device").arg(
|
|
|
|
Arg::new("net_config")
|
|
|
|
.index(1)
|
|
|
|
.help(vmm::config::NetConfig::SYNTAX),
|
|
|
|
),
|
2020-04-29 09:48:43 +00:00
|
|
|
)
|
2021-07-30 14:49:22 +00:00
|
|
|
.subcommand(
|
2021-12-31 23:09:17 +00:00
|
|
|
App::new("add-user-device")
|
2021-07-30 14:49:22 +00:00
|
|
|
.about("Add userspace device")
|
|
|
|
.arg(
|
2021-12-31 23:09:17 +00:00
|
|
|
Arg::new("device_config")
|
2021-07-30 14:49:22 +00:00
|
|
|
.index(1)
|
|
|
|
.help(vmm::config::UserDeviceConfig::SYNTAX),
|
|
|
|
),
|
|
|
|
)
|
2020-04-29 09:48:43 +00:00
|
|
|
.subcommand(
|
2021-12-31 23:09:17 +00:00
|
|
|
App::new("add-vsock").about("Add vsock device").arg(
|
|
|
|
Arg::new("vsock_config")
|
|
|
|
.index(1)
|
|
|
|
.help(vmm::config::VsockConfig::SYNTAX),
|
|
|
|
),
|
2020-03-23 16:28:09 +00:00
|
|
|
)
|
2020-03-10 16:38:04 +00:00
|
|
|
.subcommand(
|
2021-12-31 23:09:17 +00:00
|
|
|
App::new("remove-device")
|
2020-03-10 16:38:04 +00:00
|
|
|
.about("Remove VFIO device")
|
2021-12-31 23:09:17 +00:00
|
|
|
.arg(Arg::new("id").index(1).help("<device_id>")),
|
2020-03-10 16:38:04 +00:00
|
|
|
)
|
2021-12-31 23:09:17 +00:00
|
|
|
.subcommand(App::new("info").about("Info on the VM"))
|
|
|
|
.subcommand(App::new("counters").about("Counters from the VM"))
|
|
|
|
.subcommand(App::new("pause").about("Pause the VM"))
|
|
|
|
.subcommand(App::new("reboot").about("Reboot the VM"))
|
|
|
|
.subcommand(App::new("power-button").about("Trigger a power button in the VM"))
|
2020-03-10 11:34:27 +00:00
|
|
|
.subcommand(
|
2021-12-31 23:09:17 +00:00
|
|
|
App::new("resize")
|
2020-03-10 11:34:27 +00:00
|
|
|
.about("Resize the VM")
|
|
|
|
.arg(
|
2021-12-31 23:09:17 +00:00
|
|
|
Arg::new("cpus")
|
2020-03-10 11:34:27 +00:00
|
|
|
.long("cpus")
|
|
|
|
.help("New vCPUs count")
|
|
|
|
.takes_value(true)
|
|
|
|
.number_of_values(1),
|
|
|
|
)
|
|
|
|
.arg(
|
2021-12-31 23:09:17 +00:00
|
|
|
Arg::new("memory")
|
2020-03-10 11:34:27 +00:00
|
|
|
.long("memory")
|
2020-09-08 14:51:00 +00:00
|
|
|
.help("New memory size in bytes (supports K/M/G suffix)")
|
2020-03-10 11:34:27 +00:00
|
|
|
.takes_value(true)
|
|
|
|
.number_of_values(1),
|
2020-04-03 09:27:20 +00:00
|
|
|
)
|
|
|
|
.arg(
|
2021-12-31 23:09:17 +00:00
|
|
|
Arg::new("balloon")
|
2020-04-03 09:27:20 +00:00
|
|
|
.long("balloon")
|
2020-10-14 10:04:42 +00:00
|
|
|
.help("New balloon size in bytes (supports K/M/G suffix)")
|
2020-04-03 09:27:20 +00:00
|
|
|
.takes_value(true)
|
|
|
|
.number_of_values(1),
|
2020-09-10 15:34:15 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
.subcommand(
|
2021-12-31 23:09:17 +00:00
|
|
|
App::new("resize-zone")
|
2020-09-10 15:34:15 +00:00
|
|
|
.about("Resize a memory zone")
|
|
|
|
.arg(
|
2021-12-31 23:09:17 +00:00
|
|
|
Arg::new("id")
|
2020-09-10 15:34:15 +00:00
|
|
|
.long("id")
|
|
|
|
.help("Memory zone identifier")
|
|
|
|
.takes_value(true)
|
|
|
|
.number_of_values(1),
|
|
|
|
)
|
|
|
|
.arg(
|
2021-12-31 23:09:17 +00:00
|
|
|
Arg::new("size")
|
2020-09-10 15:34:15 +00:00
|
|
|
.long("size")
|
|
|
|
.help("New memory zone size in bytes (supports K/M/G suffix)")
|
|
|
|
.takes_value(true)
|
|
|
|
.number_of_values(1),
|
2020-03-10 11:34:27 +00:00
|
|
|
),
|
|
|
|
)
|
2021-12-31 23:09:17 +00:00
|
|
|
.subcommand(App::new("resume").about("Resume the VM"))
|
|
|
|
.subcommand(App::new("shutdown").about("Shutdown the VM"))
|
2020-04-02 16:04:17 +00:00
|
|
|
.subcommand(
|
2021-12-31 23:09:17 +00:00
|
|
|
App::new("snapshot").about("Create a snapshot from VM").arg(
|
|
|
|
Arg::new("snapshot_config")
|
|
|
|
.index(1)
|
|
|
|
.help("<destination_url>"),
|
|
|
|
),
|
2020-04-02 16:04:17 +00:00
|
|
|
)
|
|
|
|
.subcommand(
|
2021-12-31 23:09:17 +00:00
|
|
|
App::new("restore").about("Restore VM from a snapshot").arg(
|
|
|
|
Arg::new("restore_config")
|
|
|
|
.index(1)
|
|
|
|
.help(vmm::config::RestoreConfig::SYNTAX),
|
|
|
|
),
|
2020-11-02 16:37:18 +00:00
|
|
|
)
|
|
|
|
.subcommand(
|
2021-12-31 23:09:17 +00:00
|
|
|
App::new("send-migration")
|
2020-11-02 16:37:18 +00:00
|
|
|
.about("Initiate a VM migration")
|
|
|
|
.arg(
|
2021-12-31 23:09:17 +00:00
|
|
|
Arg::new("send_migration_config")
|
2020-11-02 16:37:18 +00:00
|
|
|
.index(1)
|
|
|
|
.help("<destination_url>"),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.subcommand(
|
2021-12-31 23:09:17 +00:00
|
|
|
App::new("receive-migration")
|
2020-11-02 16:37:18 +00:00
|
|
|
.about("Receive a VM migration")
|
|
|
|
.arg(
|
2021-12-31 23:09:17 +00:00
|
|
|
Arg::new("receive_migration_config")
|
2020-11-02 16:37:18 +00:00
|
|
|
.index(1)
|
|
|
|
.help("<receiver_url>"),
|
|
|
|
),
|
2020-04-02 16:04:17 +00:00
|
|
|
);
|
2020-03-06 15:32:06 +00:00
|
|
|
|
|
|
|
let matches = app.get_matches();
|
|
|
|
|
|
|
|
if let Err(e) = do_command(&matches) {
|
2020-06-08 14:25:37 +00:00
|
|
|
eprintln!("Error running command: {}", e);
|
2020-03-06 15:32:06 +00:00
|
|
|
process::exit(1)
|
|
|
|
};
|
|
|
|
}
|