[pve-devel] [PATCH storage v4 2/4] pbs: Make it possible to reuse PBS connection for datastore API call
Fiona Ebner
f.ebner at proxmox.com
Fri Feb 16 16:56:46 CET 2024
Am 27.11.23 um 12:39 schrieb Philipp Hufnagl:
> 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
> changed without breaking existing code.
>
I'm no fan of the second sentence. You do change it with the patch
without breaking existing code ;)
I'd rather just mention that this is in preparation for a call site
where the connection will be re-used.
> 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 | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/PVE/Storage/PBSPlugin.pm b/src/PVE/Storage/PBSPlugin.pm
> index 96373a4..b4d7914 100644
> --- a/src/PVE/Storage/PBSPlugin.pm
> +++ b/src/PVE/Storage/PBSPlugin.pm
> @@ -808,9 +808,9 @@ sub status {
> # fingerprint (optional for trusted certs)
> # }
> sub scan_datastores {
> - my ($scfg, $password) = @_;
> + my ($scfg, $password, $conn) = @_;
>
> - my $conn = pbs_api_connect($scfg, $password);
> + $conn = pbs_api_connect($scfg, $password) if !defined($conn);
>
Style nit: using '//=' would be slightly shorter/more straightforward.
> my $response = eval { $conn->get('/api2/json/admin/datastore', {}) };
> die "error fetching datastores - $@" if $@;
More information about the pve-devel
mailing list