use strict;
use warnings;
+use Cwd 'abs_path';
use PVE::Cluster;
use PVE::SafeSyslog;
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;
+
+ if ($archive eq '-') {
+ die "pipe requires cli environment\n"
+ && $rpcenv->{type} ne 'cli';
+ } else {
+ if (PVE::Storage::parse_volume_id($archive, 1)) {
+ $archive = PVE::Storage::path($storecfg, $archive);
+ } else {
+ raise_param_exc({ archive => "Only root can pass arbitrary paths." })
+ if $user ne 'root@pam';
- # fixme: archive eq '-' (read from stdin)
+ $archive = abs_path($archive);
+ }
+ die "can't find file '$archive'\n" if ! -f $archive;
+ }
+ }
my $restorefn = sub {
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);