From 3aedb73816b885e39f6b84ef289d82899cea2b60 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 8 May 2020 08:49:17 +0200 Subject: [PATCH] src/api2/node/network.rs: pass bridge_ports and slaves a property strings To make it compatible with pve. --- Cargo.toml | 2 +- src/api2/node/network.rs | 34 ++++++++++++++++++++++++++-------- src/api2/types.rs | 11 ++++++++--- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 16730f02..31940c41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ pam = "0.7" pam-sys = "0.5" percent-encoding = "2.1" pin-utils = "0.1.0-alpha" -proxmox = { version = "0.1.26", features = [ "sortable-macro", "api-macro" ] } +proxmox = { version = "0.1.27", features = [ "sortable-macro", "api-macro" ] } #proxmox = { git = "ssh://gitolite3@proxdev.maurer-it.com/rust/proxmox", version = "0.1.2", features = [ "sortable-macro", "api-macro" ] } #proxmox = { path = "../proxmox/proxmox", features = [ "sortable-macro", "api-macro" ] } regex = "1.2" diff --git a/src/api2/node/network.rs b/src/api2/node/network.rs index 796e52e8..e82c1ad2 100644 --- a/src/api2/node/network.rs +++ b/src/api2/node/network.rs @@ -3,12 +3,18 @@ use serde_json::{Value, to_value}; use ::serde::{Deserialize, Serialize}; use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission}; +use proxmox::api::schema::parse_property_string; use crate::config::network::{self, NetworkConfig}; use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY}; use crate::api2::types::*; use crate::server::{WorkerTask}; +fn split_interface_list(list: &str) -> Result, Error> { + let value = parse_property_string(&list, &NETWORK_INTERFACE_ARRAY_SCHEMA)?; + Ok(value.as_array().unwrap().iter().map(|v| v.as_str().unwrap().to_string()).collect()) +} + fn check_duplicate_gateway_v4(config: &NetworkConfig, iface: &str) -> Result<(), Error> { let current_gateway_v4 = config.interfaces.iter() @@ -214,10 +220,10 @@ pub fn create_interface( cidr6: Option, gateway6: Option, mtu: Option, - bridge_ports: Option>, + bridge_ports: Option, bridge_vlan_aware: Option, bond_mode: Option, - slaves: Option>, + slaves: Option, param: Value, ) -> Result<(), Error> { @@ -270,12 +276,18 @@ pub fn create_interface( match interface_type { NetworkInterfaceType::Bridge => { - if let Some(ports) = bridge_ports { interface.set_bridge_ports(ports)?; } + if let Some(ports) = bridge_ports { + let ports = split_interface_list(&ports)?; + interface.set_bridge_ports(ports)?; + } if bridge_vlan_aware.is_some() { interface.bridge_vlan_aware = bridge_vlan_aware; } } NetworkInterfaceType::Bond => { if bond_mode.is_some() { interface.bond_mode = bond_mode; } - if let Some(slaves) = slaves { interface.set_bond_slaves(slaves)?; } + if let Some(slaves) = slaves { + let slaves = split_interface_list(&slaves)?; + interface.set_bond_slaves(slaves)?; + } } _ => bail!("creating network interface type '{:?}' is not supported", interface_type), } @@ -442,10 +454,10 @@ pub fn update_interface( cidr6: Option, gateway6: Option, mtu: Option, - bridge_ports: Option>, + bridge_ports: Option, bridge_vlan_aware: Option, bond_mode: Option, - slaves: Option>, + slaves: Option, delete: Option>, digest: Option, param: Value, @@ -496,9 +508,15 @@ pub fn update_interface( if method.is_some() { interface.method = method; } if method6.is_some() { interface.method6 = method6; } if mtu.is_some() { interface.mtu = mtu; } - if let Some(ports) = bridge_ports { interface.set_bridge_ports(ports)?; } + if let Some(ports) = bridge_ports { + let ports = split_interface_list(&ports)?; + interface.set_bridge_ports(ports)?; + } if bridge_vlan_aware.is_some() { interface.bridge_vlan_aware = bridge_vlan_aware; } - if let Some(slaves) = slaves { interface.set_bond_slaves(slaves)?; } + if let Some(slaves) = slaves { + let slaves = split_interface_list(&slaves)?; + interface.set_bond_slaves(slaves)?; + } if bond_mode.is_some() { interface.bond_mode = bond_mode; } if let Some(cidr) = cidr { diff --git a/src/api2/types.rs b/src/api2/types.rs index f79e714d..a9c92de8 100644 --- a/src/api2/types.rs +++ b/src/api2/types.rs @@ -600,10 +600,15 @@ pub const NETWORK_INTERFACE_NAME_SCHEMA: Schema = StringSchema::new("Network int .max_length(libc::IFNAMSIZ-1) .schema(); -pub const NETWORK_INTERFACE_LIST_SCHEMA: Schema = ArraySchema::new( +pub const NETWORK_INTERFACE_ARRAY_SCHEMA: Schema = ArraySchema::new( "Network interface list.", &NETWORK_INTERFACE_NAME_SCHEMA) .schema(); +pub const NETWORK_INTERFACE_LIST_SCHEMA: Schema = StringSchema::new( + "A list of network devices, comma separated.") + .format(&ApiStringFormat::PropertyString(&NETWORK_INTERFACE_ARRAY_SCHEMA)) + .schema(); + #[api( properties: { name: { @@ -663,11 +668,11 @@ pub const NETWORK_INTERFACE_LIST_SCHEMA: Schema = ArraySchema::new( optional: true, }, bridge_ports: { - schema: NETWORK_INTERFACE_LIST_SCHEMA, + schema: NETWORK_INTERFACE_ARRAY_SCHEMA, optional: true, }, slaves: { - schema: NETWORK_INTERFACE_LIST_SCHEMA, + schema: NETWORK_INTERFACE_ARRAY_SCHEMA, optional: true, }, bond_mode: {