Signed-off-by: Alexandre Derumier <aderum...@odiso.com> --- PVE/QemuServer.pm | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 8d1f177..d1507d6 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -4709,6 +4709,8 @@ sub vmconfig_hotplug_pending { # some changes can be done without hotplug vmconfig_update_net($storecfg, $conf, $hotplug_features->{network}, $vmid, $opt, $value, $arch, $machine_type); + + vmconfig_update_net_ip($conf, $vmid, $1); } elsif (is_valid_drivename($opt)) { die "skip\n" if $opt eq 'efidisk0'; # some changes can be done without hotplug @@ -4820,6 +4822,10 @@ sub vmconfig_apply_pending { if (defined($conf->{$opt}) && is_valid_drivename($opt)) { vmconfig_register_unused_drive($storecfg, $vmid, $conf, parse_drive($opt, $conf->{$opt})) } + + if($opt =~ m/net(\d+)$/) { + vmconfig_update_net_ip($conf, $vmid, $1); + } }; if (my $err = $@) { $add_apply_error->($opt, $err); @@ -4832,6 +4838,32 @@ sub vmconfig_apply_pending { PVE::QemuConfig->write_config($vmid, $conf); } +sub vmconfig_update_net_ip { + my ($conf, $vmid, $id) = @_; + + my $netid = "net$id"; + my $ipconfigid = "ipconfig$id"; + my $net = PVE::QemuServer::parse_net($conf->{pending}->{$netid}); + my $oldnet = PVE::QemuServer::parse_net($conf->{$netid}) if $conf->{$netid}; + my $hostname = $conf->{name}; + my $oldhostname = "pending.".$hostname; + + PVE::QemuServer::Ipam::update_net_ip($net, $net, $hostname, $oldhostname, "vm:$vmid net:$netid"); + eval { + PVE::QemuServer::Ipam::delete_net_ip($hostname, $oldnet, undef, "vm:$vmid net:$netid") if $oldnet; + }; + + #set ip info as pending in cloud-init config + my $ipconfig = {}; + $ipconfig->{ip} = $net->{ip} if $net->{ip}; + $ipconfig->{ip6} = $net->{ip6} if $net->{ip6}; + $ipconfig->{gw} = $net->{gw} if $net->{gw}; + $ipconfig->{gw6} = $net->{gw6} if $net->{gw6}; + my $value = PVE::QemuServer::print_ipconfig($ipconfig); + $conf->{pending}->{$ipconfigid} = $value; + +} + sub vmconfig_update_net { my ($storecfg, $conf, $hotplug, $vmid, $opt, $value, $arch, $machine_type) = @_; -- 2.20.1 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel