From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 4FAE11FF163 for ; Mon, 6 Oct 2025 13:24:39 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9528E1FE9; Mon, 6 Oct 2025 13:24:42 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Mon, 6 Oct 2025 13:24:03 +0200 Message-ID: <20251006112409.2141871-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251006112409.2141871-1-d.csapak@proxmox.com> References: <20251006112409.2141871-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.026 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH storage 2/2] api: list: return 'formats' info in a better structured way X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" returning the formats in the way of: ``` "format": [ { "format1" => 1, "format2" => 1, ... }, "defaultFormat" ] ``` is not a very good return format, since it abuses an array as a tuple, and unnecessarily encodes a list of formats as an object. Also, we can't describe it properly in JSONSchema in perl, nor our perl->rust generator is able to handle that. Instead, return it like this: ``` "formats": { "default": "defaultFormat", "supported": ["format1", "format2", ...] } ``` which makes it much more sensible for an api return schema, and it's possible to annotate it in the JSONSchema. For compatibility reasons, keep the old property around, and add a comment to remove with 10.0 Signed-off-by: Dominik Csapak --- src/PVE/API2/Storage/Status.pm | 25 ++++++++++++++++++++++++- src/PVE/Storage.pm | 12 ++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/PVE/API2/Storage/Status.pm b/src/PVE/API2/Storage/Status.pm index ff32782..8107401 100644 --- a/src/PVE/API2/Storage/Status.pm +++ b/src/PVE/API2/Storage/Status.pm @@ -178,6 +178,7 @@ __PACKAGE__->register_method({ optional => 1, }, + # FIXME: remove with 10.0 # we can't include this return schema, since we cannot properly # describe what it actually is with the json schema: # @@ -185,9 +186,31 @@ __PACKAGE__->register_method({ # object, and the second is a string. #format => { # description => "Lists the supported and default format." - # . " Only included if 'format' parameter is set.", + # . "Deprecated (use 'formats' instead). Only included " + # . "if 'format' parameter is set.", # optional => 1, #}, + formats => { + description => "Lists the supported and default format. Use" + . " 'formats' instead. Only included if 'format' parameter is set.", + optional => 1, + type => 'object', + properties => { + supported => { + type => 'array', + description => 'The list of supported formats', + items => { + type => 'string', + enum => [qw(qcow2 raw subvol vmdk)], + }, + }, + default => { + description => "The default format of the storage.", + type => 'string', + enum => [qw(qcow2 raw subvol vmdk)], + }, + }, + }, }, }, links => [{ rel => 'child', href => "{storage}" }], diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm index 1dde2b7..935d457 100755 --- a/src/PVE/Storage.pm +++ b/src/PVE/Storage.pm @@ -1485,6 +1485,18 @@ sub storage_info { my $plugin = PVE::Storage::Plugin->lookup($scfg->{type}); if ($includeformat) { my $formats = $plugin->get_formats($scfg, $storeid); + + my $supported = []; + for my $format (sort keys $formats->{valid}->%*) { + push $supported->@*, $format if $formats->{valid}->{$format}; + } + + $info->{$storeid}->{'formats'} = { + supported => $supported, + default => $formats->{default}, + }; + + # FIXME: deprecated, remove with 10.0 $info->{$storeid}->{format} = [$formats->{valid}, $formats->{default}]; my $pd = $plugin->plugindata(); -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel