running a script after cloning

Solved. The patch adds post-clone and post-template for the hookscript.

save the code to Qemu.patch and apply the patch with the command
patch /usr/share/perl5/PVE/API2/Qemu.pm Qemu.patch

then restart the pvedaemon service


Code:
--- Qemu.pm    2020-01-09 23:15:58.500566385 +0100
+++ Qemu.pm.patch    2020-01-10 07:00:16.794454214 +0100
@@ -2941,6 +2941,9 @@
 
             PVE::QemuConfig->write_config($newid, $newconf);
 
+            my $conf = PVE::QemuConfig->load_config($newid);
+            PVE::GuestHelpers::exec_hookscript($conf, $newid, 'post-clone');
+
                     if ($target) {
             # always deactivate volumes - avoid lvm LVs to be active on several nodes
             PVE::Storage::deactivate_volumes($storecfg, $vollist, $snapname) if !$running;
@@ -4051,6 +4054,8 @@
         $conf->{template} = 1;
         PVE::QemuConfig->write_config($vmid, $conf);
 
+        PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-template');
+
         return $rpcenv->fork_worker('qmtemplate', $vmid, $authuser, $realcmd);
     };
 
Last edited:
Will this be made available in a next release? I am looking for a way to automatically install an agent (configuration management) to a newly cloned lxc container or vm. Thanks
 
Hello,

could somebody make an other patch, that fires a status event (like post-stop), when the VM was shutdown from itself?
I have seen that you created a 'post-clone' hookscript event, I would need something that...

Thanks