On 4/1/19 5:45 PM, Christian Ebner wrote: > Signed-off-by: Christian Ebner <c.eb...@proxmox.com> > --- > src/PVE/API2/LXC.pm | 9 ++++++++- > src/PVE/LXC/Create.pm | 9 ++++++++- > 2 files changed, 16 insertions(+), 2 deletions(-)
applied, thanks. Maybe a small note that this is mirroring the behavior of qemu-server would've been great. Additional, could you try to integrate this in the WebUI? For the case where we restore to a new VMID it would make sense, to have as checkbox, IMO, neither VMs nor CTs can set it from there, currently. > > diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm > index 6de121f..3d5460c 100644 > --- a/src/PVE/API2/LXC.pm > +++ b/src/PVE/API2/LXC.pm > @@ -144,6 +144,12 @@ __PACKAGE__->register_method({ > type => 'boolean', > description => "Mark this as restore task.", > }, > + unique => { > + optional => 1, > + type => 'boolean', > + description => "Assign a unique random ethernet address.", > + requires => 'restore', > + }, > pool => { > optional => 1, > type => 'string', format => 'pve-poolid', > @@ -197,6 +203,7 @@ __PACKAGE__->register_method({ > # 'unprivileged' is read-only, so we can't pass it to update_pct_config > my $unprivileged = extract_param($param, 'unprivileged'); > my $restore = extract_param($param, 'restore'); > + my $unique = extract_param($param, 'unique'); > > if ($restore) { > # fixme: limit allowed parameters > @@ -397,7 +404,7 @@ __PACKAGE__->register_method({ > PVE::LXC::Create::restore_archive($archive, $rootdir, > $conf, $ignore_unpack_errors, $bwlimit); > > if ($restore) { > - PVE::LXC::Create::restore_configuration($vmid, > $rootdir, $conf, !$is_root); > + PVE::LXC::Create::restore_configuration($vmid, > $rootdir, $conf, !$is_root, $unique); > } else { > my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir); > # detect OS > PVE::LXC::Config->write_config($vmid, $conf); # safe > config (after OS detection) > diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm > index 564d6db..39827a6 100644 > --- a/src/PVE/LXC/Create.pm > +++ b/src/PVE/LXC/Create.pm > @@ -159,7 +159,7 @@ sub recover_config { > } > > sub restore_configuration { > - my ($vmid, $rootdir, $conf, $restricted) = @_; > + my ($vmid, $rootdir, $conf, $restricted, $unique) = @_; > > # restore: try to extract configuration from archive > > @@ -184,6 +184,13 @@ sub restore_configuration { > warn "--------------------------------\n"; > next; > } > + if (($unique && $key =~ /^net\d+/)) { > + my $net = PVE::LXC::Config->parse_lxc_network($oldconf->{$key}); > + my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg'); > + $net->{hwaddr} = > PVE::Tools::random_ether_addr($dc->{mac_prefix}); > + $conf->{$key} = PVE::LXC::Config->print_lxc_network($net); > + next; > + } > $conf->{$key} = $oldconf->{$key} if !defined($conf->{$key}); > } > unlink($pct_cfg_fn); > _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel