From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id BF8A61FF17C
	for <inbox@lore.proxmox.com>; Wed,  2 Apr 2025 12:42:03 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 7C0CDF8F7;
	Wed,  2 Apr 2025 12:41:53 +0200 (CEST)
Date: Wed, 02 Apr 2025 12:41:17 +0200
From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= <f.gruenbichler@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
References: <20250328171340.885413-1-g.goller@proxmox.com>
 <20250328171340.885413-40-g.goller@proxmox.com>
In-Reply-To: <20250328171340.885413-40-g.goller@proxmox.com>
MIME-Version: 1.0
User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid)
Message-Id: <1743588183.g68prsqc8e.astroid@yuna.none>
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.045 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: Re: [pve-devel] [PATCH pve-network 12/17] api: fabrics: add common
 helpers
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

On March 28, 2025 6:13 pm, Gabriel Goller wrote:
> From: Stefan Hanreich <s.hanreich@proxmox.com>
> 
> Since the perlmod API for both the openfabric and ospf are the same,
> add helpers for all CRUD operations that will be supported by the
> openfabric and ospf endpoints, so they can share the same code.
> 
> Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
> Co-authored-by: Gabriel Goller <g.goller@proxmox.com>
> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
> ---
>  src/PVE/API2/Network/SDN/Fabrics/Common.pm | 80 ++++++++++++++++++++++
>  src/PVE/API2/Network/SDN/Fabrics/Makefile  |  9 +++
>  2 files changed, 89 insertions(+)
>  create mode 100644 src/PVE/API2/Network/SDN/Fabrics/Common.pm
>  create mode 100644 src/PVE/API2/Network/SDN/Fabrics/Makefile
> 
> diff --git a/src/PVE/API2/Network/SDN/Fabrics/Common.pm b/src/PVE/API2/Network/SDN/Fabrics/Common.pm
> new file mode 100644
> index 000000000000..9d68264f6252
> --- /dev/null
> +++ b/src/PVE/API2/Network/SDN/Fabrics/Common.pm
> @@ -0,0 +1,80 @@
> +package PVE::API2::Network::SDN::Fabrics::Common;
> +
> +use strict;
> +use warnings;
> +
> +use PVE::Network::SDN::Fabrics;

weird order: delete, add, get, edit ;)

> +
> +sub delete_fabric {
> +    my ($type, $param) = @_;
> +
> +    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
> +    $fabrics->delete_fabric($param);
> +    PVE::Network::SDN::Fabrics::write_config($fabrics);

write_config is only called here in this module.. couldn't we just adapt
it to return undef instead of repeating it at every call site here..

and/or we could have a single do_action helper since we effectively
repeat the same code 6 times here..

and since these are basically the API handlers, we could add the missing
bits here and than just call them to handle the API request?

> +    return undef;
> +}
> +
> +sub delete_node {
> +    my ($type, $param) = @_;
> +
> +    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
> +    $fabrics->delete_node($param);
> +    PVE::Network::SDN::Fabrics::write_config($fabrics);
> +    return undef;
> +}
> +
> +sub add_node {
> +    my ($type, $param) = @_;
> +
> +    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
> +    $fabrics->add_node($param);
> +    PVE::Network::SDN::Fabrics::write_config($fabrics);
> +
> +    return undef;
> +}
> +
> +sub add_fabric {
> +    my ($type, $param) = @_;
> +
> +    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
> +    $fabrics->add_fabric($param);
> +    PVE::Network::SDN::Fabrics::write_config($fabrics);
> +
> +    return undef;
> +}
> +
> +sub get_fabric {
> +    my ($type, $param) = @_;
> +
> +    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
> +    my $return_value = $fabrics->get_fabric($param->{fabric});
> +    return $return_value;

this could just be

my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
return $fabrics->get_fabric($param->{fabric});

?

> +}
> +
> +sub get_node {
> +    my ($type, $param) = @_;
> +
> +    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
> +    my $return_value = $fabrics->get_node($param->{fabric}, $param->{node});
> +    return $return_value;

same here

> +}
> +
> +sub edit_fabric {
> +    my ($type, $param) = @_;
> +
> +    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
> +    $fabrics->edit_fabric($param);
> +    PVE::Network::SDN::Fabrics::write_config($fabrics);
> +    return undef;
> +}
> +
> +sub edit_node {
> +    my ($type, $param) = @_;
> +
> +    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
> +    $fabrics->edit_node($param);
> +    PVE::Network::SDN::Fabrics::write_config($fabrics);
> +    return undef;
> +}
> +
> +1;
> diff --git a/src/PVE/API2/Network/SDN/Fabrics/Makefile b/src/PVE/API2/Network/SDN/Fabrics/Makefile
> new file mode 100644
> index 000000000000..e433f2e7d0a6
> --- /dev/null
> +++ b/src/PVE/API2/Network/SDN/Fabrics/Makefile
> @@ -0,0 +1,9 @@
> +SOURCES=OpenFabric.pm Ospf.pm Common.pm
> +
> +
> +PERL5DIR=${DESTDIR}/usr/share/perl5
> +
> +.PHONY: install
> +install:
> +	for i in ${SOURCES}; do install -D -m 0644 $$i ${PERL5DIR}/PVE/API2/Network/SDN/Fabrics/$$i; done
> +
> -- 
> 2.39.5
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 
> 


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel