[pve-devel] [PATCH storage v2 2/4] pbs: Make it possible to reuse PBS connection for datastore API call

Christian Ebner c.ebner at proxmox.com
Thu Nov 16 10:40:29 CET 2023


> On 15.11.2023 17:00 CET Philipp Hufnagl <p.hufnagl at proxmox.com> wrote:
> 
>  
> It would be nice to reuse an existing PBS connection for scan_datastore.
> Because scan_datastore is used multiple in the code, it can not be
> canged without breaking existing code.

Typo s/canged/changed.
 
> 
> This change add an optional connection parameter to scan_datastore. If
> it is passed it will use this connection. If not, it will create a new
> one.
> 
> Signed-off-by: Philipp Hufnagl <p.hufnagl at proxmox.com>
> ---
>  src/PVE/Storage/PBSPlugin.pm | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/src/PVE/Storage/PBSPlugin.pm b/src/PVE/Storage/PBSPlugin.pm
> index 96373a4..81df21e 100644
> --- a/src/PVE/Storage/PBSPlugin.pm
> +++ b/src/PVE/Storage/PBSPlugin.pm
> @@ -808,9 +808,11 @@ sub status {
>  #   fingerprint   (optional for trusted certs)
>  # }
>  sub scan_datastores {
> -    my ($scfg, $password) = @_;
> +    my ($scfg, $password, $conn) = @_;
>  
> -    my $conn = pbs_api_connect($scfg, $password);
> +    if (!defined($conn)){
> +	$conn = pbs_api_connect($scfg, $password);
> +    }

This can be written more compactly as:
$conn = pbs_api_connect($scfg, $password) if !defined($conn);

>  
>      my $response = eval { $conn->get('/api2/json/admin/datastore', {}) };
>      die "error fetching datastores - $@" if $@;
> -- 
> 2.39.2
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel





More information about the pve-devel mailing list