[pve-devel] [PATCH v2 qemu-server 8/9] ipam : add create vm support
Alexandre Derumier
aderumier at odiso.com
Mon Jul 12 00:47:06 CEST 2021
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/API2/Qemu.pm | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index aaefcec..66a21ba 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -703,7 +703,31 @@ __PACKAGE__->register_method({
my $arch = PVE::QemuServer::get_vm_arch($conf);
my $vollist = [];
+ my $nets = {};
eval {
+ foreach my $opt (keys %{$conf}) {
+ next if $opt !~ m/^net(\d+)$/;
+ my $hostname = $conf->{name};
+ my $description = "vm:$vmid net:$opt";
+ my $net = PVE::QemuServer::parse_net($conf->{$opt});
+ PVE::QemuServer::Ipam::add_net_ip(4,$net, $hostname, $description);
+ PVE::QemuServer::Ipam::update_net_gateway(4, $net);
+ $nets->{$opt} = PVE::QemuServer::print_net($net);
+ PVE::QemuServer::Ipam::add_net_ip(6,$net, $hostname, $description);
+ PVE::QemuServer::Ipam::update_net_gateway(6, $net);
+ $nets->{$opt} = PVE::QemuServer::print_net($net);
+ $conf->{$opt} = PVE::QemuServer::print_net($net);
+ if($opt =~ m/net(\d+)$/) {
+ my $ipconfigid = "ipconfig$1";
+ 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};
+ $conf->{$ipconfigid} = PVE::QemuServer::print_ipconfig($ipconfig);
+ }
+ }
+
$vollist = &$create_disks($rpcenv, $authuser, $conf, $arch, $storecfg, $vmid, $pool, $param, $storage);
if (!$conf->{boot}) {
@@ -738,6 +762,14 @@ __PACKAGE__->register_method({
eval { PVE::Storage::vdisk_free($storecfg, $volid); };
warn $@ if $@;
}
+ foreach my $opt (keys %{$nets}) {
+ my $net = PVE::QemuServer::parse_net($nets->{$opt});
+ my $hostname = $conf->{name};
+ eval { PVE::QemuServer::Ipam::delete_net_ip(6, $net, $hostname); };
+ warn $@ if $@;
+ eval { PVE::QemuServer::Ipam::delete_net_ip(4, $net, $hostname); };
+ warn $@ if $@;
+ }
die "$emsg $err";
}
--
2.30.2
More information about the pve-devel
mailing list