From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <t.lamprecht@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id A8DCD60762
 for <pve-devel@lists.proxmox.com>; Thu,  8 Oct 2020 11:04:45 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 93BEFD290
 for <pve-devel@lists.proxmox.com>; Thu,  8 Oct 2020 11:04:45 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id D1936D274
 for <pve-devel@lists.proxmox.com>; Thu,  8 Oct 2020 11:04:44 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 91D4045C36;
 Thu,  8 Oct 2020 11:04:44 +0200 (CEST)
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Alexandre Derumier <aderumier@odiso.com>
References: <20201005150912.463000-1-aderumier@odiso.com>
 <20201005150912.463000-28-aderumier@odiso.com>
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
Message-ID: <9d354181-8f41-22b4-8e00-70b3bbb314f0@proxmox.com>
Date: Thu, 8 Oct 2020 11:04:43 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:82.0) Gecko/20100101
 Thunderbird/82.0
MIME-Version: 1.0
In-Reply-To: <20201005150912.463000-28-aderumier@odiso.com>
Content-Type: text/plain; charset=UTF-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.138 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 NICE_REPLY_A           -0.001 Looks like a legit reply (A)
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [vnets.pm]
Subject: Re: [pve-devel] [PATCH v10 pve-network 27/35] api: add
 running/pending zones/vnets/subnets/controllers
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>
X-List-Received-Date: Thu, 08 Oct 2020 09:04:45 -0000

On 05.10.20 17:09, Alexandre Derumier wrote:
> diff --git a/PVE/API2/Network/SDN/Vnets.pm b/PVE/API2/Network/SDN/Vnets.pm
> index 0fbb747..6ff61c5 100644
> --- a/PVE/API2/Network/SDN/Vnets.pm
> +++ b/PVE/API2/Network/SDN/Vnets.pm
> @@ -3,6 +3,8 @@ package PVE::API2::Network::SDN::Vnets;
>  use strict;
>  use warnings;
>  
> +use Hash::Diff qw( diff );

You add this use statement here, but never use it nor add the corresponding
dependency to debian/control (would probably be libhash-diff-perl?)

Can I just drop this line or do I overlook something?

> +
>  use PVE::SafeSyslog;
>  use PVE::Tools qw(extract_param);
>  use PVE::Cluster qw(cfs_read_file cfs_write_file);
> @@ -33,10 +35,22 @@ my $api_sdn_vnets_config = sub {
>      my $scfg = dclone(PVE::Network::SDN::Vnets::sdn_vnets_config($cfg, $id));
>      $scfg->{vnet} = $id;
>      $scfg->{digest} = $cfg->{digest};
> -
> +    
>      return $scfg;
>  };
>  
> +my $api_sdn_vnets_deleted_config = sub {
> +    my ($cfg, $running_cfg, $id) = @_;
> +
> +    if (!$cfg->{ids}->{$id}) {
> +
> +	my $vnet_cfg = dclone(PVE::Network::SDN::Vnets::sdn_vnets_config($running_cfg->{vnets}, $id));
> +	$vnet_cfg->{state} = "deleted";
> +	$vnet_cfg->{vnet} = $id;
> +	return $vnet_cfg;
> +    }
> +};
> +
>  __PACKAGE__->register_method ({
>      name => 'index',
>      path => '',
> @@ -49,6 +63,18 @@ __PACKAGE__->register_method ({
>      },
>      parameters => {
>  	additionalProperties => 0,
> +	properties => {
> +            running => {
> +                type => 'boolean',
> +                optional => 1,
> +                description => "Display running config.",
> +            },
> +	    pending => {
> +		type => 'boolean',
> +		optional => 1,
> +		description => "Display pending config.",
> +	    },
> +	},
>      },
>      returns => {
>  	type => 'array',
> @@ -64,7 +90,17 @@ __PACKAGE__->register_method ({
>  	my $rpcenv = PVE::RPCEnvironment::get();
>  	my $authuser = $rpcenv->get_user();
>  
> -	my $cfg = PVE::Network::SDN::Vnets::config();
> +	my $cfg = {};
> +	if($param->{pending}) {
> +	    my $running_cfg = PVE::Network::SDN::config();
> +	    my $config = PVE::Network::SDN::Vnets::config();
> +	    $cfg = PVE::Network::SDN::pending_config($running_cfg, $config, 'vnets');
> +	} elsif ($param->{running}) {
> +	    my $running_cfg = PVE::Network::SDN::config();
> +	    $cfg = $running_cfg->{vnets};
> +	} else {
> +	    $cfg = PVE::Network::SDN::Vnets::config();
> +	}
>  
>  	my @sids = PVE::Network::SDN::Vnets::sdn_vnets_ids($cfg);
>  	my $res = [];
> @@ -93,13 +129,33 @@ __PACKAGE__->register_method ({
>  	    vnet => get_standard_option('pve-sdn-vnet-id', {
>  		completion => \&PVE::Network::SDN::Vnets::complete_sdn_vnets,
>  	    }),
> +            running => {
> +                type => 'boolean',
> +                optional => 1,
> +                description => "Display running config.",
> +            },
> +	    pending => {
> +		type => 'boolean',
> +		optional => 1,
> +		description => "Display pending config.",
> +	    },
>  	},
>      },
>      returns => { type => 'object' },
>      code => sub {
>  	my ($param) = @_;
>  
> -	my $cfg = PVE::Network::SDN::Vnets::config();
> +	my $cfg = {};
> +	if($param->{pending}) {
> +	    my $running_cfg = PVE::Network::SDN::config();
> +	    my $config = PVE::Network::SDN::Vnets::config();
> +	    $cfg = PVE::Network::SDN::pending_config($running_cfg, $config, 'vnets');
> +	} elsif ($param->{running}) {
> +	    my $running_cfg = PVE::Network::SDN::config();
> +	    $cfg = $running_cfg->{vnets};
> +	} else {
> +	    $cfg = PVE::Network::SDN::Vnets::config();
> +	}
>  
>  	return $api_sdn_vnets_config->($cfg, $param->{vnet});
>      }});