]> git.proxmox.com Git - pve-guest-common.git/commitdiff
PVE::AbstractMigrate - new helpers to handle replication jobs
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 21 Jun 2017 10:24:57 +0000 (12:24 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 21 Jun 2017 10:24:57 +0000 (12:24 +0200)
PVE/AbstractMigrate.pm

index a0096fa7fdbdb77b157fb475b5c07031bffccf09..1efd502462d43c2ebe1f2fa69bc1112017cb4dd3 100644 (file)
@@ -3,8 +3,10 @@ package PVE::AbstractMigrate;
 use strict;
 use warnings;
 use POSIX qw(strftime);
+use JSON;
 use PVE::Tools;
 use PVE::Cluster;
+use PVE::ReplicationState;
 
 my $msg2text = sub {
     my ($level, $msg) = @_;
@@ -296,4 +298,40 @@ sub final_cleanup {
     die "abstract method - implement me";
 }
 
+# transfer replication state helper - call this before moving the guest config
+# - just log the error is something fails
+sub transfer_replication_state {
+    my ($self) = @_;
+
+    my $local_node = PVE::INotify::nodename();
+
+    eval {
+       my $stateobj = PVE::ReplicationState::read_state();
+       my $vmstate = PVE::ReplicationState::extract_vmid_tranfer_state($stateobj, $self->{vmid}, $self->{node}, $local_node);
+       # This have to be quoted when it run it over ssh.
+       my $state = PVE::Tools::shellquote(encode_json($vmstate));
+       my $cmd = [ @{$self->{rem_ssh}}, 'pvesr', 'set-state', $self->{vmid}, $state];
+       $self->cmd($cmd);
+    };
+    if (my $err = $@) {
+       $self->log('err', "transfer replication state failed - $err");
+       $self->{errors} = 1;
+    }
+}
+
+# switch replication job target - call this after moving the guest config
+# - does nothing if there is no relevant replication job
+# - just log the error is something fails
+sub switch_replication_job_target {
+    my ($self) = @_;
+
+    my $local_node = PVE::INotify::nodename();
+
+    eval { PVE::ReplicationConfig::switch_replication_job_target($self->{vmid}, $self->{node}, $local_node); };
+    if (my $err = $@) {
+       $self->log('err', "switch replication job target failed - $err");
+       $self->{errors} = 1;
+    }
+}
+
 1;