mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-11-04 19:11:11 +00:00
vmm: api: Make NetConfig defaults match between CLI and HTTP API
In order to let the CLI and the HTTP API behave the same regarding the NetConfig structure, this patch defines some default values for tap, ip, mask, mac and iommu. tap is None, ip is 192.168.249.1, mask is 255.255.255.0, mac is a randomly generated value, and iommu is false. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
eff78f746a
commit
befd342da4
@ -279,18 +279,17 @@ components:
|
||||
default: false
|
||||
|
||||
NetConfig:
|
||||
required:
|
||||
- ip
|
||||
- mask
|
||||
- mac
|
||||
type: object
|
||||
properties:
|
||||
tap:
|
||||
type: string
|
||||
default: ""
|
||||
ip:
|
||||
type: string
|
||||
default: "192.168.249.1"
|
||||
mask:
|
||||
type: string
|
||||
default: "255.255.255.0"
|
||||
mac:
|
||||
type: string
|
||||
iommu:
|
||||
|
@ -302,14 +302,34 @@ impl DiskConfig {
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct NetConfig {
|
||||
#[serde(default = "default_netconfig_tap")]
|
||||
pub tap: Option<String>,
|
||||
#[serde(default = "default_netconfig_ip")]
|
||||
pub ip: Ipv4Addr,
|
||||
#[serde(default = "default_netconfig_mask")]
|
||||
pub mask: Ipv4Addr,
|
||||
#[serde(default = "default_netconfig_mac")]
|
||||
pub mac: MacAddr,
|
||||
#[serde(default)]
|
||||
pub iommu: bool,
|
||||
}
|
||||
|
||||
fn default_netconfig_tap() -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
fn default_netconfig_ip() -> Ipv4Addr {
|
||||
Ipv4Addr::new(192, 168, 249, 1)
|
||||
}
|
||||
|
||||
fn default_netconfig_mask() -> Ipv4Addr {
|
||||
Ipv4Addr::new(255, 255, 255, 0)
|
||||
}
|
||||
|
||||
fn default_netconfig_mac() -> MacAddr {
|
||||
MacAddr::local_random()
|
||||
}
|
||||
|
||||
impl NetConfig {
|
||||
pub fn parse(net: &str) -> Result<Self> {
|
||||
// Split the parameters based on the comma delimiter
|
||||
@ -335,10 +355,10 @@ impl NetConfig {
|
||||
}
|
||||
}
|
||||
|
||||
let mut tap: Option<String> = None;
|
||||
let mut ip: Ipv4Addr = Ipv4Addr::new(192, 168, 249, 1);
|
||||
let mut mask: Ipv4Addr = Ipv4Addr::new(255, 255, 255, 0);
|
||||
let mut mac: MacAddr = MacAddr::local_random();
|
||||
let mut tap: Option<String> = default_netconfig_tap();
|
||||
let mut ip: Ipv4Addr = default_netconfig_ip();
|
||||
let mut mask: Ipv4Addr = default_netconfig_mask();
|
||||
let mut mac: MacAddr = default_netconfig_mac();
|
||||
let iommu = parse_on_off(iommu_str)?;
|
||||
|
||||
if !tap_str.is_empty() {
|
||||
|
Loading…
Reference in New Issue
Block a user