[pve-devel] [PATCH v2 pve-docs 1/3] Add pre/post-migrate events to hookscript example

Stefan Hanreich s.hanreich at proxmox.com
Thu Oct 6 14:44:43 CEST 2022


Also added an example on how to use the passed environment variable to
discern between target/source

Signed-off-by: Stefan Hanreich <s.hanreich at proxmox.com>
---
 examples/guest-example-hookscript.pl | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/examples/guest-example-hookscript.pl b/examples/guest-example-hookscript.pl
index adeed59..96b0ff2 100755
--- a/examples/guest-example-hookscript.pl
+++ b/examples/guest-example-hookscript.pl
@@ -54,6 +54,26 @@ if ($phase eq 'pre-start') {
 
     print "$vmid stopped. Doing cleanup.\n";
 
+} elsif ($phase eq 'pre-migrate') {
+    # The environment variable PVE_MIGRATED_FROM will contain the name of the
+    # source node, if this script is run on the target node.
+    my $node_type = ($ENV{PVE_MIGRATED_FROM}) ? 'target' : 'source';
+
+    # Phase 'pre-migrate' will be run before a migration on the source/target
+    # node of the VM/CT
+
+    print "preparing $vmid for migration on $node_type.\n";
+
+} elsif ($phase eq 'post-migrate') {
+    # The environment variable PVE_MIGRATED_FROM will contain the name of the
+    # source node, if this script is run on the target node.
+    my $node_type = ($ENV{PVE_MIGRATED_FROM}) ? 'target' : 'source';
+
+    # Phase 'post-migrate' will be run after a migration on the source/target
+    # node of the VM/CT
+
+    print "finished migrating $vmid on $node_type.\n";
+
 } else {
     die "got unknown phase '$phase'\n";
 }
-- 
2.30.2





More information about the pve-devel mailing list