[pve-devel] [PATCH v2 qemu-server 5/7] api: add handling for new boot order format
Stefan Reiter
s.reiter at proxmox.com
Tue Oct 6 15:32:16 CEST 2020
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 at proxmox.com>
---
PVE/API2/Qemu.pm | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 0d82d3e..f1e9759 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -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);
--
2.20.1
More information about the pve-devel
mailing list