optional => 1,
type => 'boolean',
description => "Allow to overwrite existing VM.",
+ requires => 'archive',
+ },
+ unique => {
+ optional => 1,
+ type => 'boolean',
+ description => "Assign a unique random ethernet address.",
+ requires => 'archive',
},
}),
},
my $storage = extract_param($param, 'storage');
+ my $force = extract_param($param, 'force');
+
+ my $unique = extract_param($param, 'unique');
+
my $filename = PVE::QemuServer::config_file($vmid);
my $storecfg = PVE::Storage::config();
}
PVE::QemuServer::add_random_macs($param);
+ } else {
+ my $keystr = join(' ', keys %$param);
+ raise_param_exc({ archive => "option conflicts with other options ($keystr)"}) if $keystr;
}
# fixme: archive eq '-' (read from stdin)
if (-f $filename) {
die "unable to restore vm $vmid: config file already exists\n"
- if !$param->{force};
+ if !$force;
die "unable to restore vm $vmid: vm is running\n"
if PVE::QemuServer::check_running($vmid);
}
my $realcmd = sub {
- PVE::QemuServer::restore_archive($archive, $vmid, { storage => $storage});
+ PVE::QemuServer::restore_archive($archive, $vmid, {
+ storage => $storage,
+ unique => $unique });
};
return $rpcenv->fork_worker('qmrestore', $vmid, $user, $realcmd);
my $outfd = new IO::File ($tmpfn, "w") ||
die "unable to write config for VM $vmid\n";
+ my $netcount = 0;
+
while (defined (my $line = <$srcfd>)) {
next if $line =~ m/^\#vzdump\#/;
next if $line =~ m/^lock:/;
next if $line =~ m/^unused\d+:/;
- if (($line =~ m/^((vlan)\d+):(.*)$/) && ($opts->{unique})) {
- my ($id,$ethcfg) = ($1,$3);
- $ethcfg =~ s/^\s+//;
- my ($model, $mac) = split(/\=/,$ethcfg);
- my $printvlan = PVE::QemuServer::print_vlan(PVE::QemuServer::parse_vlan($model));
- print $outfd "$id: $printvlan\n";
- } elsif ($line =~ m/^((ide|scsi|virtio)\d+):(.*)$/) {
+ if (($line =~ m/^(vlan(\d+)):\s*(\S+)\s*$/)) {
+ # try to convert old 1.X settings
+ my ($id, $ind, $ethcfg) = ($1, $2, $3);
+ foreach my $devconfig (PVE::Tools::split_list($ethcfg)) {
+ my ($model, $macaddr) = split(/\=/, $devconfig);
+ $macaddr = PVE::Tools::random_ether_addr() if !$macaddr || $opts->{unique};
+ my $net = {
+ model => $model,
+ bridge => "vmbr$ind",
+ macaddr => $macaddr,
+ };
+ my $netstr = print_net($net);
+ print $outfd "net${netcount}: $netstr\n";
+ $netcount++;
+ }
+ } elsif (($line =~ m/^(net\d+):\s*(\S+)\s*$/) && ($opts->{unique})) {
+ my ($id, $netstr) = ($1, $2);
+ my $net = parse_net($netstr);
+ $net->{macaddr} = PVE::Tools::random_ether_addr() if $net->{macaddr};
+ $netstr = print_net($net);
+ print $outfd "$id: $netstr\n";
+ } elsif ($line =~ m/^((ide|scsi|virtio)\d+):\s*(\S+)\s*$/) {
my $virtdev = $1;
my $value = $2;
if ($line =~ m/backup=no/) {