api: list: return 'formats' info in a better structured way
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 <d.csapak@proxmox.com>
This commit is contained in:
committed by
Fabian Grünbichler
parent
ede776abef
commit
633392285c
@ -178,6 +178,7 @@ __PACKAGE__->register_method({
|
|||||||
optional => 1,
|
optional => 1,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
# FIXME: remove with 10.0
|
||||||
# we can't include this return schema, since we cannot properly
|
# we can't include this return schema, since we cannot properly
|
||||||
# describe what it actually is with the json schema:
|
# describe what it actually is with the json schema:
|
||||||
#
|
#
|
||||||
@ -185,9 +186,31 @@ __PACKAGE__->register_method({
|
|||||||
# object, and the second is a string.
|
# object, and the second is a string.
|
||||||
#format => {
|
#format => {
|
||||||
# description => "Lists the supported and default 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,
|
# 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}" }],
|
links => [{ rel => 'child', href => "{storage}" }],
|
||||||
|
|||||||
@ -1485,6 +1485,18 @@ sub storage_info {
|
|||||||
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
|
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
|
||||||
if ($includeformat) {
|
if ($includeformat) {
|
||||||
my $formats = $plugin->get_formats($scfg, $storeid);
|
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}];
|
$info->{$storeid}->{format} = [$formats->{valid}, $formats->{default}];
|
||||||
|
|
||||||
my $pd = $plugin->plugindata();
|
my $pd = $plugin->plugindata();
|
||||||
|
|||||||
Reference in New Issue
Block a user