mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-08-07 05:12:55 +00:00
drop get_pending_changes and simplify cloudinit_pending api call
- The forced-remove flag wasn't really used AFAICT and makes no sense IMO. - Whether or not we care about non-MAC changes does not belong here, but should instead taken into account in the actual hotplug path recording the cloud-init state (iow. into $cloudinit_record_changed().) (This is not done here atm.) - It seems much simpler to just have: * 'old' = the old value if it's not a new value * 'new' = the new value unless it's being deleted * If only one of them is set it's an addition or removal. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
d29483147d
commit
1b5706cd16
@ -1338,24 +1338,16 @@ __PACKAGE__->register_method({
|
|||||||
description => "Configuration option name.",
|
description => "Configuration option name.",
|
||||||
type => 'string',
|
type => 'string',
|
||||||
},
|
},
|
||||||
value => {
|
old => {
|
||||||
description => "Current value.",
|
description => "Value as it was used to generate the current cloudinit image.",
|
||||||
type => 'string',
|
type => 'string',
|
||||||
optional => 1,
|
optional => 1,
|
||||||
},
|
},
|
||||||
pending => {
|
new => {
|
||||||
description => "Pending value.",
|
description => "The new pending value.",
|
||||||
type => 'string',
|
type => 'string',
|
||||||
optional => 1,
|
optional => 1,
|
||||||
},
|
},
|
||||||
delete => {
|
|
||||||
description => "Indicates a pending delete request if present and not 0. " .
|
|
||||||
"The value 2 indicates a force-delete request.",
|
|
||||||
type => 'integer',
|
|
||||||
minimum => 0,
|
|
||||||
maximum => 2,
|
|
||||||
optional => 1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1365,17 +1357,29 @@ __PACKAGE__->register_method({
|
|||||||
my $vmid = $param->{vmid};
|
my $vmid = $param->{vmid};
|
||||||
my $conf = PVE::QemuConfig->load_config($vmid);
|
my $conf = PVE::QemuConfig->load_config($vmid);
|
||||||
|
|
||||||
if (defined($conf->{cipassword}) &&
|
my $ci = $conf->{cloudinit};
|
||||||
defined($conf->{cloudinit}->{cipassword}) &&
|
|
||||||
$conf->{cipassword} ne $conf->{cloudinit}->{cipassword}) {
|
my $res = {};
|
||||||
$conf->{cipassword} = '********** ';
|
my $added = delete($ci->{added}) // '';
|
||||||
} elsif (defined($conf->{cipassword})) {
|
for my $key (PVE::Tools::split_list($added)) {
|
||||||
$conf->{cipassword} = '**********';
|
$res->{$key} = { new => $conf->{$key} };
|
||||||
}
|
}
|
||||||
|
|
||||||
$conf->{cloudinit}->{cipassword} = '**********' if defined($conf->{cloudinit}->{cipassword});
|
for my $key (keys %$ci) {
|
||||||
|
if (!exists($conf->{$key})) {
|
||||||
|
$res->{$key} = { old => $ci->{$key} };
|
||||||
|
} else {
|
||||||
|
$res->{$key} = {
|
||||||
|
old => $ci->{$key},
|
||||||
|
new => $conf->{$key},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
my $res = PVE::QemuServer::Cloudinit::get_pending_config($conf, $vmid);
|
if (defined(my $pw = $res->{cipassword})) {
|
||||||
|
$pw->{old} = '**********' if exists $pw->{old};
|
||||||
|
$pw->{new} = '**********' if exists $pw->{new};
|
||||||
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}});
|
}});
|
||||||
|
@ -627,82 +627,4 @@ sub dump_cloudinit_config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_pending_config {
|
|
||||||
my ($conf, $vmid) = @_;
|
|
||||||
|
|
||||||
my $newconf = dclone($conf);
|
|
||||||
|
|
||||||
my $cloudinit_current = $newconf->{cloudinit};
|
|
||||||
my @cloudinit_opts = keys %{PVE::QemuServer::cloudinit_config_properties()};
|
|
||||||
push @cloudinit_opts, 'name';
|
|
||||||
|
|
||||||
#add cloud-init drive
|
|
||||||
my $drives = {};
|
|
||||||
PVE::QemuConfig->foreach_volume($newconf, sub {
|
|
||||||
my ($ds, $drive) = @_;
|
|
||||||
$drives->{$ds} = 1 if PVE::QemuServer::drive_is_cloudinit($drive);
|
|
||||||
});
|
|
||||||
|
|
||||||
PVE::QemuConfig->foreach_volume($cloudinit_current, sub {
|
|
||||||
my ($ds, $drive) = @_;
|
|
||||||
$drives->{$ds} = 1 if PVE::QemuServer::drive_is_cloudinit($drive);
|
|
||||||
});
|
|
||||||
for my $ds (keys %{$drives}) {
|
|
||||||
push @cloudinit_opts, $ds;
|
|
||||||
}
|
|
||||||
|
|
||||||
$newconf->{name} = "VM$vmid" if !$newconf->{name};
|
|
||||||
$cloudinit_current->{name} = "VM$vmid" if !$cloudinit_current->{name};
|
|
||||||
|
|
||||||
#only mac-address is used in cloud-init config.
|
|
||||||
#We don't want to display other pending net changes.
|
|
||||||
my $print_cloudinit_net = sub {
|
|
||||||
my ($conf, $opt) = @_;
|
|
||||||
|
|
||||||
if (defined($conf->{$opt})) {
|
|
||||||
my $net = PVE::QemuServer::parse_net($conf->{$opt});
|
|
||||||
$conf->{$opt} = "macaddr=".$net->{macaddr} if $net->{macaddr};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
my $cloudinit_options = {};
|
|
||||||
for my $opt (@cloudinit_opts) {
|
|
||||||
if ($opt =~ m/^ipconfig(\d+)/) {
|
|
||||||
my $netid = "net$1";
|
|
||||||
|
|
||||||
next if !defined($newconf->{$netid}) && !defined($cloudinit_current->{$netid}) &&
|
|
||||||
!defined($newconf->{$opt}) && !defined($cloudinit_current->{$opt});
|
|
||||||
|
|
||||||
&$print_cloudinit_net($newconf, $netid);
|
|
||||||
&$print_cloudinit_net($cloudinit_current, $netid);
|
|
||||||
$cloudinit_options->{$netid} = 1;
|
|
||||||
}
|
|
||||||
$cloudinit_options->{$opt} = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $res = [];
|
|
||||||
|
|
||||||
for my $opt (keys %{$cloudinit_options}) {
|
|
||||||
|
|
||||||
my $item = {
|
|
||||||
key => $opt,
|
|
||||||
};
|
|
||||||
if ($cloudinit_current->{$opt}) {
|
|
||||||
$item->{value} = $cloudinit_current->{$opt};
|
|
||||||
if (defined($newconf->{$opt})) {
|
|
||||||
$item->{pending} = $newconf->{$opt}
|
|
||||||
if $newconf->{$opt} ne $cloudinit_current->{$opt};
|
|
||||||
} else {
|
|
||||||
$item->{delete} = 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$item->{pending} = $newconf->{$opt} if $newconf->{$opt}
|
|
||||||
}
|
|
||||||
|
|
||||||
push @$res, $item;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user