]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/API2/Qemu.pm
followup: refactor loop to use perls values
[qemu-server.git] / PVE / API2 / Qemu.pm
index 788db9392dfb0418fc5cfdd870655f3eec969510..027bbf6fdcf49a4c597fa94d38170b9b752149e6 100644 (file)
@@ -404,7 +404,7 @@ __PACKAGE__->register_method({
 my $parse_restore_archive = sub {
     my ($storecfg, $archive) = @_;
 
-    my ($archive_storeid, $archive_volname) = PVE::Storage::parse_volume_id($archive);
+    my ($archive_storeid, $archive_volname) = PVE::Storage::parse_volume_id($archive, 1);
 
     if (defined($archive_storeid)) {
        my $scfg =  PVE::Storage::storage_config($storecfg, $archive_storeid);
@@ -2024,11 +2024,7 @@ __PACKAGE__->register_method({
                optional => 1,
            },
            machine => get_standard_option('pve-qemu-machine'),
-           targetstorage => {
-               description => "Target storage for the migration. (Can be '1' to use the same storage id as on the source node.)",
-               type => 'string',
-               optional => 1
-           },
+           targetstorage => get_standard_option('pve-targetstorage'),
            timeout => {
                description => "Wait maximal timeout seconds.",
                type => 'integer',
@@ -2067,8 +2063,15 @@ __PACKAGE__->register_method({
        my $migration_network = $get_root_param->('migration_network');
        my $targetstorage = $get_root_param->('targetstorage');
 
-       raise_param_exc({ targetstorage => "targetstorage can only by used with migratedfrom." })
-           if $targetstorage && !$migratedfrom;
+       my $storagemap;
+
+       if ($targetstorage) {
+           raise_param_exc({ targetstorage => "targetstorage can only by used with migratedfrom." })
+               if !$migratedfrom;
+           $storagemap = eval { PVE::JSONSchema::parse_idmap($targetstorage, 'pve-storage-id') };
+           raise_param_exc({ targetstorage => "failed to parse targetstorage map: $@" })
+               if $@;
+       }
 
        # read spice ticket from STDIN
        my $spice_ticket;
@@ -2119,7 +2122,7 @@ __PACKAGE__->register_method({
                    spice_ticket => $spice_ticket,
                    network => $migration_network,
                    type => $migration_type,
-                   targetstorage => $targetstorage,
+                   storagemap => $storagemap,
                    nbd_proto_version => $nbd_protocol_version,
                    replicated_volumes => $replicated_volumes,
                };
@@ -3385,9 +3388,7 @@ __PACKAGE__->register_method({
                description => "Enable live storage migration for local disk",
                optional => 1,
            },
-            targetstorage => get_standard_option('pve-storage-id', {
-               description => "Default target storage.",
-               optional => 1,
+            targetstorage => get_standard_option('pve-targetstorage', {
                completion => \&PVE::QemuServer::complete_migration_storage,
             }),
            bwlimit => {
@@ -3451,8 +3452,34 @@ __PACKAGE__->register_method({
 
        my $storecfg = PVE::Storage::config();
 
-       if( $param->{targetstorage}) {
-           PVE::Storage::storage_check_node($storecfg, $param->{targetstorage}, $target);
+       if (my $targetstorage = $param->{targetstorage}) {
+           my $check_storage = sub {
+               my ($target_sid) = @_;
+               PVE::Storage::storage_check_node($storecfg, $target_sid, $target);
+               $rpcenv->check($authuser, "/storage/$target_sid", ['Datastore.AllocateSpace']);
+               my $scfg = PVE::Storage::storage_config($storecfg, $target_sid);
+               raise_param_exc({ targetstorage => "storage '$target_sid' does not support vm images"})
+                   if !$scfg->{content}->{images};
+           };
+
+           my $storagemap = eval { PVE::JSONSchema::parse_idmap($targetstorage, 'pve-storage-id') };
+           raise_param_exc({ targetstorage => "failed to parse targetstorage map: $@" })
+               if $@;
+
+           $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.Disk'])
+               if !defined($storagemap->{identity});
+
+           foreach my $source (values %{$storagemap->{entries}}) {
+               $check_storage->($source);
+           }
+
+           $check_storage->($storagemap->{default})
+               if $storagemap->{default};
+
+           PVE::QemuServer::check_storage_availability($storecfg, $conf, $target)
+               if $storagemap->{identity};
+
+           $param->{storagemap} = $storagemap;
         } else {
            PVE::QemuServer::check_storage_availability($storecfg, $conf, $target);
        }