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 08/10] refactor(api): simplify setting interface properties
Date: Wed, 17 Jan 2024 10:50:34 +0100 [thread overview]
Message-ID: <ace0cf1b-a1f5-4cee-b9c6-585632e26928@proxmox.com> (raw)
In-Reply-To: <20240111155303.1072675-17-s.lendl@proxmox.com>
On 1/11/24 16:53, Stefan Lendl wrote:
> 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;
> +
In general our PUT handlers do not require the caller to send at fields,
but only those that have changed. Fields that should be cleared are
represented by the 'deleted' field.
This means the old code is actually necessary: If a field is not
submitted, it should *not* be changed. Only if a new value is sent, the
field should be updated.
Your change happens to work from the UI, since the network dialog
happens to always send all fields - which is not that AFAIK not that
common for our UI.
Your change however breaks the CLI tool:
For example, set a comment for an interface and then do a
proxmox-backup-manager network update enp6s18.10 --autostart false
You will notice that comment is cleared after that command :)
> 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);
--
- 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
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 [this message]
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=ace0cf1b-a1f5-4cee-b9c6-585632e26928@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox