mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-02 11:35:46 +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
|
default: false
|
||||||
|
|
||||||
NetConfig:
|
NetConfig:
|
||||||
required:
|
|
||||||
- ip
|
|
||||||
- mask
|
|
||||||
- mac
|
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
tap:
|
tap:
|
||||||
type: string
|
type: string
|
||||||
|
default: ""
|
||||||
ip:
|
ip:
|
||||||
type: string
|
type: string
|
||||||
|
default: "192.168.249.1"
|
||||||
mask:
|
mask:
|
||||||
type: string
|
type: string
|
||||||
|
default: "255.255.255.0"
|
||||||
mac:
|
mac:
|
||||||
type: string
|
type: string
|
||||||
iommu:
|
iommu:
|
||||||
|
@ -302,14 +302,34 @@ impl DiskConfig {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct NetConfig {
|
pub struct NetConfig {
|
||||||
|
#[serde(default = "default_netconfig_tap")]
|
||||||
pub tap: Option<String>,
|
pub tap: Option<String>,
|
||||||
|
#[serde(default = "default_netconfig_ip")]
|
||||||
pub ip: Ipv4Addr,
|
pub ip: Ipv4Addr,
|
||||||
|
#[serde(default = "default_netconfig_mask")]
|
||||||
pub mask: Ipv4Addr,
|
pub mask: Ipv4Addr,
|
||||||
|
#[serde(default = "default_netconfig_mac")]
|
||||||
pub mac: MacAddr,
|
pub mac: MacAddr,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub iommu: bool,
|
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 {
|
impl NetConfig {
|
||||||
pub fn parse(net: &str) -> Result<Self> {
|
pub fn parse(net: &str) -> Result<Self> {
|
||||||
// Split the parameters based on the comma delimiter
|
// Split the parameters based on the comma delimiter
|
||||||
@ -335,10 +355,10 @@ impl NetConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut tap: Option<String> = None;
|
let mut tap: Option<String> = default_netconfig_tap();
|
||||||
let mut ip: Ipv4Addr = Ipv4Addr::new(192, 168, 249, 1);
|
let mut ip: Ipv4Addr = default_netconfig_ip();
|
||||||
let mut mask: Ipv4Addr = Ipv4Addr::new(255, 255, 255, 0);
|
let mut mask: Ipv4Addr = default_netconfig_mask();
|
||||||
let mut mac: MacAddr = MacAddr::local_random();
|
let mut mac: MacAddr = default_netconfig_mac();
|
||||||
let iommu = parse_on_off(iommu_str)?;
|
let iommu = parse_on_off(iommu_str)?;
|
||||||
|
|
||||||
if !tap_str.is_empty() {
|
if !tap_str.is_empty() {
|
||||||
|
Loading…
Reference in New Issue
Block a user