From: Lukas Wagner <l.wagner@proxmox.com>
To: Proxmox Backup Server development discussion
<pbs-devel@lists.proxmox.com>, Stefan Lendl <s.lendl@proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox-backup 03/10] config: write vlan network interface
Date: Wed, 17 Jan 2024 10:50:27 +0100 [thread overview]
Message-ID: <0e8e713e-35c5-47d4-912a-c6d4ba8c5ed2@proxmox.com> (raw)
In-Reply-To: <20240111155303.1072675-7-s.lendl@proxmox.com>
On 1/11/24 16:52, Stefan Lendl wrote:
> add vlan_id and vlan_raw_device to Interface struct
> write them out if the interface type is Vlan
> add several tests
>
> Signed-off-by: Stefan Lendl <s.lendl@proxmox.com>
> ---
> pbs-api-types/src/network.rs | 17 ++++++++
> pbs-config/src/network/mod.rs | 73 ++++++++++++++++++++++++++++++++++-
> 2 files changed, 89 insertions(+), 1 deletion(-)
>
> diff --git a/pbs-api-types/src/network.rs b/pbs-api-types/src/network.rs
> index e3a5e481..fe083dc6 100644
> --- a/pbs-api-types/src/network.rs
> +++ b/pbs-api-types/src/network.rs
> @@ -224,6 +224,15 @@ pub const NETWORK_INTERFACE_LIST_SCHEMA: Schema =
> schema: NETWORK_INTERFACE_ARRAY_SCHEMA,
> optional: true,
> },
> + "vlan-id": {
> + description: "VLAN ID.",
> + type: u16,
> + optional: true,
> + },
> + "vlan-raw-device": {
> + schema: NETWORK_INTERFACE_NAME_SCHEMA,
> + optional: true,
> + },
> bond_mode: {
> type: LinuxBondMode,
> optional: true,
> @@ -287,6 +296,12 @@ pub struct Interface {
> /// Enable bridge vlan support.
> #[serde(skip_serializing_if = "Option::is_none")]
> pub bridge_vlan_aware: Option<bool>,
> + #[serde(skip_serializing_if = "Option::is_none")]
> + #[serde(rename = "vlan-id")]
> + pub vlan_id: Option<u16>,
> + #[serde(skip_serializing_if = "Option::is_none")]
> + #[serde(rename = "vlan-raw-device")]
> + pub vlan_raw_device: Option<String>,
>
> #[serde(skip_serializing_if = "Option::is_none")]
> pub slaves: Option<Vec<String>>,
> @@ -319,6 +334,8 @@ impl Interface {
> mtu: None,
> bridge_ports: None,
> bridge_vlan_aware: None,
> + vlan_id: None,
> + vlan_raw_device: None,
> slaves: None,
> bond_mode: None,
> bond_primary: None,
> diff --git a/pbs-config/src/network/mod.rs b/pbs-config/src/network/mod.rs
> index 7fec7e29..971c1ebe 100644
> --- a/pbs-config/src/network/mod.rs
> +++ b/pbs-config/src/network/mod.rs
> @@ -79,6 +79,14 @@ fn write_iface_attributes(iface: &Interface, w: &mut dyn Write) -> Result<(), Er
> writeln!(w, "\tbond-slaves {}", slaves.join(" "))?;
> }
> }
> + NetworkInterfaceType::Vlan => {
> + if let Some(vlan_id) = iface.vlan_id {
> + writeln!(w, "\tvlan-id {}", vlan_id)?;
> + }
> + if let Some(vlan_raw_device) = &iface.vlan_raw_device {
> + writeln!(w, "\tvlan-raw-device {}", vlan_raw_device)?;
Mini-nit: You can inline the string formatting: {vlan_raw_device}
> + }
> + }
> _ => {}
> }
>
> @@ -580,5 +588,68 @@ iface enp3s0 inet static
> .trim()
> );
> }
> -}
>
> + #[test]
> + fn test_write_network_config_vlan_id_in_name() {
> + let iface_name = String::from("vmbr0.100");
> + let mut iface = Interface::new(iface_name.clone());
> + iface.interface_type = Vlan;
> + iface.method = Some(Manual);
> + iface.active = true;
> +
> + let nw_config = NetworkConfig {
> + interfaces: BTreeMap::from([(iface_name.clone(), iface)]),
> + order: vec![Iface(iface_name.clone())],
> + };
> + assert_eq!(
> + String::try_from(nw_config).unwrap().trim(),
> + "iface vmbr0.100 inet manual"
> + );
> + }
> +
> + #[test]
> + fn test_write_network_config_vlan_with_raw_device() {
> + let iface_name = String::from("vlan100");
> + let mut iface = Interface::new(iface_name.clone());
> + iface.interface_type = Vlan;
> + iface.vlan_raw_device = Some(String::from("vmbr0"));
> + iface.method = Some(Manual);
> + iface.active = true;
> +
> + let nw_config = NetworkConfig {
> + interfaces: BTreeMap::from([(iface_name.clone(), iface)]),
> + order: vec![Iface(iface_name.clone())],
> + };
> + assert_eq!(
> + String::try_from(nw_config).unwrap().trim(),
> + r#"
> +iface vlan100 inet manual
> + vlan-raw-device vmbr0"#
> + .trim()
> + );
> + }
> +
> + #[test]
> + fn test_write_network_config_vlan_with_individual_name() {
> + let iface_name = String::from("individual_name");
> + let mut iface = Interface::new(iface_name.clone());
> + iface.interface_type = Vlan;
> + iface.vlan_raw_device = Some(String::from("vmbr0"));
> + iface.vlan_id = Some(100);
> + iface.method = Some(Manual);
> + iface.active = true;
> +
> + let nw_config = NetworkConfig {
> + interfaces: BTreeMap::from([(iface_name.clone(), iface)]),
> + order: vec![Iface(iface_name.clone())],
> + };
> + assert_eq!(
> + String::try_from(nw_config).unwrap().trim(),
> + r#"
> +iface individual_name inet manual
> + vlan-id 100
> + vlan-raw-device vmbr0"#
> + .trim()
> + );
> + }
> +}
--
- Lukas
next prev parent reply other threads:[~2024-01-17 9:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-11 15:52 [pbs-devel] [PATCH widget-toolkit/proxmox-backup 00/10] Fix #3115: VLAN Network Interface Configuration Stefan Lendl
2024-01-11 15:52 ` [pbs-devel] [PATCH proxmox-backup 01/10] tests: move network tests to parser.rs Stefan Lendl
2024-01-11 15:52 ` [pbs-devel] [PATCH proxmox-backup 02/10] tests: rudimentary NetworkConfig.write_config tests Stefan Lendl
2024-01-11 15:52 ` [pbs-devel] [PATCH proxmox-backup 03/10] config: write vlan network interface Stefan Lendl
2024-01-17 9:50 ` Lukas Wagner [this message]
2024-01-11 15:53 ` [pbs-devel] [PATCH proxmox-backup 04/10] config: parse vlan interface from config Stefan Lendl
2024-01-11 15:53 ` [pbs-devel] [PATCH proxmox-backup 05/10] config: remove unnecessary pub in various methods in NetworkConfig Stefan Lendl
2024-01-17 9:50 ` Lukas Wagner
2024-01-11 15:53 ` [pbs-devel] [PATCH proxmox-backup 06/10] fmt: fix intendation in api macro Stefan Lendl
2024-01-11 15:53 ` [pbs-devel] [PATCH proxmox-backup 07/10] api: create and update vlan interfaces Stefan Lendl
2024-01-17 9:50 ` Lukas Wagner
2024-01-11 15:53 ` [pbs-devel] [PATCH proxmox-backup 08/10] refactor(api): simplify setting interface properties Stefan Lendl
2024-01-17 9:50 ` Lukas Wagner
2024-01-11 15:53 ` [pbs-devel] [PATCH proxmox-backup 09/10] ui: enable vlan widget Stefan Lendl
2024-01-11 15:53 ` [pbs-devel] [PATCH widget-toolkit 10/10] form: include VlanField from PVE Stefan Lendl
2024-01-11 16:01 ` Lukas Wagner
2024-01-17 9:50 ` [pbs-devel] [PATCH widget-toolkit/proxmox-backup 00/10] Fix #3115: VLAN Network Interface Configuration Lukas Wagner
2024-01-22 11:06 ` Stefan Lendl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0e8e713e-35c5-47d4-912a-c6d4ba8c5ed2@proxmox.com \
--to=l.wagner@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
--cc=s.lendl@proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.