api: import-metadata: make warnings structured & merge ignored-volumes

This allows the frontends to translate them and avoids somewhat
duplicated info by having some warnings explicitly (ignored-volumes)
while others are in the warnings array.

By passing along the key and the value the frontend can also show the
warnings in-line, e.g. by marking a disk-entry in a grid as having
potential problems.

Ideally we'd have a central list of known types used for the API
return schema enum and to check when calling the $warn closure, but as
we only got three warnings keep this as is and only add a comment.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht
2024-03-10 19:25:34 +01:00
parent b628964289
commit 1a94dceb6f
2 changed files with 28 additions and 15 deletions

View File

@ -738,12 +738,6 @@ __PACKAGE__->register_method({
optional => 1, optional => 1,
description => 'Recognised network interfaces as `net$id` => { ...params } object.', description => 'Recognised network interfaces as `net$id` => { ...params } object.',
}, },
'ignored-volumes' => {
type => 'object',
additionalProperties => 1,
optional => 1,
description => 'Volumes that are explicitly ignored, like e.g., CDROM drives on ESXi.',
},
'warnings' => { 'warnings' => {
type => 'array', type => 'array',
description => 'List of known issues that can affect the import of a guest.' description => 'List of known issues that can affect the import of a guest.'
@ -753,7 +747,24 @@ __PACKAGE__->register_method({
type => "object", type => "object",
additionalProperties => 1, additionalProperties => 1,
properties => { properties => {
message => { 'type' => {
description => 'What this warning is about.',
enum => [
'cdrom-image-ignored',
'nvme-unsupported',
'ovmf-with-lsi-unsupported',
'serial-port-socket-only',
],
type => 'string',
},
'key' => {
description => 'Related subject (config) key of warning.',
optional => 1,
type => 'string',
},
'value' => {
description => 'Related subject (config) value of warning.',
optional => 1,
type => 'string', type => 'string',
}, },
}, },

View File

@ -921,10 +921,11 @@ sub get_create_args {
my $create_disks = {}; my $create_disks = {};
my $create_net = {}; my $create_net = {};
my $warnings = []; my $warnings = [];
my $ignored_volumes = {};
# NOTE: all types must be added to the return schema of the import-metadata API endpoint
my $warn = sub { my $warn = sub {
push @$warnings, { message => $_[0] }; my ($type, %properties) = @_;
push @$warnings, { type => $type, %properties };
}; };
my ($cores, $sockets) = $self->cpu_info(); my ($cores, $sockets) = $self->cpu_info();
@ -1008,7 +1009,8 @@ sub get_create_args {
# We currently do not pass cdroms through via the esxi storage. # We currently do not pass cdroms through via the esxi storage.
# Users should adapt import these from the storages directly/manually. # Users should adapt import these from the storages directly/manually.
$create_args->{"${bus}${count}"} = "none,media=cdrom"; $create_args->{"${bus}${count}"} = "none,media=cdrom";
$ignored_volumes->{"${bus}${count}"} = "$storeid:$path"; # CD-ROM image will not get imported
$warn->('cdrom-image-ignored', key => "${bus}${count}", value => "$storeid:$path");
} else { } else {
$create_disks->{"${bus}${count}"} = "$storeid:$path"; $create_disks->{"${bus}${count}"} = "$storeid:$path";
} }
@ -1018,10 +1020,10 @@ sub get_create_args {
}; };
$self->for_each_disk($add_disk); $self->for_each_disk($add_disk);
if (@nvmes) { if (@nvmes) {
$warn->("PVE currently does not support NVMe guest disks, they are converted to SCSI");
for my $nvme (@nvmes) { for my $nvme (@nvmes) {
my ($slot, $file, $devtype, $kind) = @$nvme; my ($slot, $file, $devtype, $kind) = @$nvme;
$add_disk->('nvme', $slot, $file, $devtype, $kind, 1); $warn->('nvme-unsupported', key => "nvme${slot}", value => "$file");
$add_disk->('scsi', $slot, $file, $devtype, $kind, 1);
} }
} }
@ -1033,7 +1035,8 @@ sub get_create_args {
} else { } else {
$scsihw = 'virtio-scsi-single'; $scsihw = 'virtio-scsi-single';
} }
$warn->("OVMF is built without LSI drivers, scsi hardware was set to $scsihw"); # OVMF is built without LSI drivers, scsi hardware was set to $scsihw
$warn->('ovmf-with-lsi-unsupported', key => 'scsihw', value => "$scsihw");
} }
} }
$create_args->{scsihw} = $scsihw; $create_args->{scsihw} = $scsihw;
@ -1057,7 +1060,7 @@ sub get_create_args {
$self->for_each_serial(sub { $self->for_each_serial(sub {
my ($id, $serial) = @_; my ($id, $serial) = @_;
# currently we only support 'socket' type serials anyway # currently we only support 'socket' type serials anyway
$warn->("serial ports are currently all mapped to sockets") if $serid == 0; $warn->('serial-port-socket-only', key => "serial$serid");
$create_args->{"serial$serid"} = 'socket'; $create_args->{"serial$serid"} = 'socket';
++$serid; ++$serid;
}); });
@ -1068,7 +1071,6 @@ sub get_create_args {
'create-args' => $create_args, 'create-args' => $create_args,
disks => $create_disks, disks => $create_disks,
net => $create_net, net => $create_net,
'ignored-volumes' => $ignored_volumes,
warnings => $warnings, warnings => $warnings,
}; };
} }