public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Lendl <s.lendl@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 08/10] refactor(api): simplify setting interface properties
Date: Thu, 11 Jan 2024 16:53:09 +0100	[thread overview]
Message-ID: <20240111155303.1072675-17-s.lendl@proxmox.com> (raw)
In-Reply-To: <20240111155303.1072675-1-s.lendl@proxmox.com>

Instead of using `if ..is_some()` directly assign the Option properties of
Interface from Option parameters of update_ and create_interface.
Code is shorter and cleaner to read.

Signed-off-by: Stefan Lendl <s.lendl@proxmox.com>
---
 src/api2/node/network.rs | 54 +++++++++++-----------------------------
 1 file changed, 14 insertions(+), 40 deletions(-)

diff --git a/src/api2/node/network.rs b/src/api2/node/network.rs
index d1393103..84a017e9 100644
--- a/src/api2/node/network.rs
+++ b/src/api2/node/network.rs
@@ -301,25 +301,12 @@ pub fn create_interface(
 
     let mut interface = Interface::new(iface.clone());
     interface.interface_type = interface_type;
-
-    if let Some(autostart) = autostart {
-        interface.autostart = autostart;
-    }
-    if method.is_some() {
-        interface.method = method;
-    }
-    if method6.is_some() {
-        interface.method6 = method6;
-    }
-    if mtu.is_some() {
-        interface.mtu = mtu;
-    }
-    if comments.is_some() {
-        interface.comments = comments;
-    }
-    if comments6.is_some() {
-        interface.comments6 = comments6;
-    }
+    interface.autostart = autostart.unwrap_or(false);
+    interface.method = method;
+    interface.method6 = method6;
+    interface.mtu = mtu;
+    interface.comments = comments;
+    interface.comments6 = comments6;
 
     if let Some(cidr) = cidr {
         let (_, _, is_v6) = network::parse_cidr(&cidr)?;
@@ -697,25 +684,16 @@ pub fn update_interface(
         }
     }
 
-    if let Some(autostart) = autostart {
-        interface.autostart = autostart;
-    }
-    if method.is_some() {
-        interface.method = method;
-    }
-    if method6.is_some() {
-        interface.method6 = method6;
-    }
-    if mtu.is_some() {
-        interface.mtu = mtu;
-    }
+    interface.autostart = autostart.unwrap_or(false);
+    interface.method = method;
+    interface.method6 = method6;
+    interface.mtu = mtu;
+    interface.bridge_vlan_aware = bridge_vlan_aware;
+
     if let Some(ports) = bridge_ports {
         let ports = split_interface_list(&ports)?;
         set_bridge_ports(interface, ports)?;
     }
-    if bridge_vlan_aware.is_some() {
-        interface.bridge_vlan_aware = bridge_vlan_aware;
-    }
     if let Some(slaves) = slaves {
         let slaves = split_interface_list(&slaves)?;
         set_bond_slaves(interface, slaves)?;
@@ -768,12 +746,8 @@ pub fn update_interface(
         interface.gateway6 = Some(gateway6);
     }
 
-    if comments.is_some() {
-        interface.comments = comments;
-    }
-    if comments6.is_some() {
-        interface.comments6 = comments6;
-    }
+    interface.comments = comments;
+    interface.comments6 = comments6;
 
     if interface.cidr.is_some() || interface.gateway.is_some() {
         interface.method = Some(NetworkConfigMethod::Static);
-- 
2.42.0





  parent reply	other threads:[~2024-01-11 15:55 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
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 ` Stefan Lendl [this message]
2024-01-17  9:50   ` [pbs-devel] [PATCH proxmox-backup 08/10] refactor(api): simplify setting interface properties 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=20240111155303.1072675-17-s.lendl@proxmox.com \
    --to=s.lendl@proxmox.com \
    --cc=pbs-devel@lists.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal