api: add handling for new boot order format

The API is updated to handle the deprecation correctly, i.e. when
updating the 'order' attribute, the old 'legacy' (default_key) values
are removed (would now be ignored anyway).

When removing a device that is in the bootorder list, it will be removed
from the aforementioned. Note that non-existing devices in the list will
not cause an error - they will simply be ignored - but it's still nice
to not have them in there.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
Stefan Reiter 2020-10-06 15:32:16 +02:00 committed by Thomas Lamprecht
parent 2141a802b8
commit 078c109fae

View File

@ -1191,6 +1191,12 @@ my $update_vm_api = sub {
my $modified = {}; # record what $option we modify
my $bootcfg = PVE::JSONSchema::parse_property_string('pve-qm-boot', $conf->{boot})
if $conf->{boot};
my @bootorder = PVE::Tools::split_list($bootcfg->{order})
if $bootcfg && $bootcfg->{order};
my $bootorder_deleted = grep {$_ eq 'bootorder'} @delete;
foreach my $opt (@delete) {
$modified->{$opt} = 1;
$conf = PVE::QemuConfig->load_config($vmid); # update/reload
@ -1205,6 +1211,13 @@ my $update_vm_api = sub {
my $is_pending_val = defined($conf->{pending}->{$opt});
delete $conf->{pending}->{$opt};
# remove from bootorder if necessary
if (!$bootorder_deleted && @bootorder && grep {$_ eq $opt} @bootorder) {
@bootorder = grep {$_ ne $opt} @bootorder;
$conf->{pending}->{boot} = PVE::QemuServer::print_bootorder(\@bootorder);
$modified->{boot} = 1;
}
if ($opt =~ m/^unused/) {
my $drive = PVE::QemuServer::parse_drive($opt, $val);
PVE::QemuConfig->check_protection($conf, "can't remove unused disk '$drive->{file}'");
@ -1283,6 +1296,24 @@ my $update_vm_api = sub {
$conf->{pending}->{$opt} = $param->{$opt};
} else {
$conf->{pending}->{$opt} = $param->{$opt};
if ($opt eq 'boot') {
my $new_bootcfg = PVE::JSONSchema::parse_property_string('pve-qm-boot', $param->{$opt});
if ($new_bootcfg->{order}) {
my @devs = PVE::Tools::split_list($new_bootcfg->{order});
for my $dev (@devs) {
my $exists = $conf->{$dev} || $conf->{pending}->{$dev};
my $deleted = grep {$_ eq $dev} @delete;
die "invalid bootorder: device '$dev' does not exist'\n"
if !$exists || $deleted;
}
# remove legacy boot order settings if new one set
$conf->{pending}->{$opt} = PVE::QemuServer::print_bootorder(\@devs);
PVE::QemuConfig->add_to_pending_delete($conf, "bootdisk")
if $conf->{bootdisk};
}
}
}
PVE::QemuConfig->remove_from_pending_delete($conf, $opt);
PVE::QemuConfig->write_config($vmid, $conf);