Since 'pvesm import' uses a new volume ID if the requested one is already present, callers should have a way to get the new volume ID.
Signed-off-by: Fabian Ebner <f.eb...@proxmox.com> --- PVE/CLI/pvesm.pm | 2 +- PVE/Storage.pm | 41 +++++++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/PVE/CLI/pvesm.pm b/PVE/CLI/pvesm.pm index 7d8547b..74294b4 100755 --- a/PVE/CLI/pvesm.pm +++ b/PVE/CLI/pvesm.pm @@ -779,7 +779,7 @@ our $cmddef = { export => [ __PACKAGE__, 'export', ['volume', 'format', 'filename']], import => [ __PACKAGE__, 'import', ['volume', 'format', 'filename'], {}, sub { my $volid = shift; - print "successfully imported '$volid'\n"; + print PVE::Storage::volume_imported_message($volid); }], }; diff --git a/PVE/Storage.pm b/PVE/Storage.pm index 2b292f6..57d723d 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -615,6 +615,21 @@ sub storage_migrate { push @$recv, '-base', $base_snapshot; } + my $new_volid; + my $match_volid_and_log = sub { + my $line = shift; + my $pattern = volume_imported_message(undef, 1); + + if ($line =~ m!$pattern!) { + $new_volid = $1; + } + + if ($logfunc) { + chomp($line); + $logfunc->($line); + } + }; + volume_snapshot($cfg, $volid, $snapshot) if $migration_snapshot; eval { if ($insecure) { @@ -632,13 +647,8 @@ sub storage_migrate { shutdown($socket, 1); # wait for the remote process to finish - if ($logfunc) { - while (my $line = <$info>) { - chomp($line); - $logfunc->("[$target_sshinfo->{name}] $line"); - } - } else { - 1 while <$info>; + while (my $line = <$info>) { + $match_volid_and_log->("[$target_sshinfo->{name}] $line"); } # now close the socket @@ -648,8 +658,11 @@ sub storage_migrate { die "import failed: exit code ".($?>>8)."\n"; } } else { - run_command([$send, @cstream, $recv], logfunc => $logfunc); + run_command([$send, @cstream, $recv], logfunc => $match_volid_and_log); } + + die "unable to get ID of the migrated volume\n" + if !defined($new_volid); }; my $err = $@; warn "send/receive failed, cleaning up snapshot(s)..\n" if $err; @@ -658,6 +671,8 @@ sub storage_migrate { warn "could not remove source snapshot: $@\n" if $@; } die $err if $err; + + return $new_volid; } sub vdisk_clone { @@ -1447,6 +1462,16 @@ sub volume_transfer_formats { return @common; } +sub volume_imported_message { + my ($volid, $want_pattern) = @_; + + if ($want_pattern) { + return "^successfully imported '([^']*)'\$"; + } else { + return "successfully imported '$volid'\n"; + } +} + # bash completion helper sub complete_storage { -- 2.20.1 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel