]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/API2/Qemu.pm
use split_args from PVE::Tools
[qemu-server.git] / PVE / API2 / Qemu.pm
index eaaa7533c7dcd16f01c324226160f5451070cb27..cd63cfba4c07a3177259adad326a2d2517d4c627 100644 (file)
@@ -2,6 +2,7 @@ package PVE::API2::Qemu;
 
 use strict;
 use warnings;
+use Cwd 'abs_path';
 
 use PVE::Cluster;
 use PVE::SafeSyslog;
@@ -89,6 +90,13 @@ __PACKAGE__->register_method({
                    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',
                },
            }),
     },
@@ -110,6 +118,10 @@ __PACKAGE__->register_method({
 
        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(); 
@@ -130,15 +142,31 @@ __PACKAGE__->register_method({
            }
 
            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);
@@ -148,7 +176,9 @@ __PACKAGE__->register_method({
            }
 
            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);