]> git.proxmox.com Git - pve-container.git/commitdiff
clone: randomize network MAC HW address of clone
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 20 Mar 2018 14:28:46 +0000 (15:28 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 21 Mar 2018 09:31:24 +0000 (10:31 +0100)
adapt code from qemu-servers clone API path and generate a new
randomized network hardware address (MAC) for the new clone to avoid
address collisions

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/API2/LXC.pm

index 0c9ee40c7834369b902dd4fe03d8ebe533b69531..0c834d41fbb3262a87be78bca7105ae267bd25ef 100644 (file)
@@ -1350,6 +1350,12 @@ __PACKAGE__->register_method({
                            # TODO: allow bind mounts?
                            die "unable to clone mountpint '$opt' (type $mp->{type})\n";
                        }
+                   } elsif ($opt =~ m/^net(\d+)$/) {
+                       # always change MAC! address
+                       my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
+                       my $net = PVE::LXC::Config->parse_lxc_network($value);
+                       $net->{hwaddr} = PVE::Tools::random_ether_addr($dc->{mac_prefix});
+                       $newconf->{$opt} = PVE::LXC::Config->print_lxc_network($net);
                    } else {
                        # copy everything else
                        $newconf->{$opt} = $value;