use PVE::QemuConfig;
use PVE::QMPClient;
use PVE::RPCEnvironment;
+use PVE::GuestHelpers;
use PVE::QemuServer::PCI qw(print_pci_addr print_pcie_addr);
use PVE::QemuServer::Memory;
use PVE::QemuServer::USB qw(parse_usb_device);
default => "1 (autogenerated)",
optional => 1,
},
+ hookscript => {
+ type => 'string',
+ format => 'pve-volume-id',
+ optional => 1,
+ description => "Script that will be executed during various steps in the vms lifetime.",
+ },
};
my $confdesc_cloudinit = {
if ($d->{'x-vga'}) {
$xvga = ',x-vga=on';
$kvm_off = 1;
- $vga->{type} = 'none';
+ $vga->{type} = 'none' if !defined($conf->{vga});
$gpu_passthrough = 1;
if ($conf->{bios} && $conf->{bios} eq 'ovmf') {
'description' => 1,
'protection' => 1,
'vmstatestorage' => 1,
+ 'hookscript' => 1,
};
# hotplug changes in [PENDING]
}
}
+ PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'pre-start', 1);
+
my ($cmd, $vollist, $spice_port) = config_to_command($storecfg, $vmid, $conf, $defaults, $forcemachine);
my $migrate_port = 0;
PVE::Storage::activate_volumes($storecfg, $vollist);
- if (!check_running($vmid, 1)) {
+ if (-d "/sys/fs/cgroup/systemd/qemu.slice/$vmid.scope") {
eval {
run_command(['/bin/systemctl', 'stop', "$vmid.scope"],
outfunc => sub {}, errfunc => sub {});
property => "guest-stats-polling-interval",
value => 2) if (!defined($conf->{balloon}) || $conf->{balloon});
+ PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-start');
});
}
}
sub vm_commandline {
- my ($storecfg, $vmid) = @_;
+ my ($storecfg, $vmid, $snapname) = @_;
my $conf = PVE::QemuConfig->load_config($vmid);
+ if ($snapname) {
+ my $snapshot = $conf->{snapshots}->{$snapname};
+ die "snapshot '$snapname' does not exist\n" if !defined($snapshot);
+
+ $snapshot->{digest} = $conf->{digest}; # keep file digest for API
+
+ $conf = $snapshot;
+ }
+
my $defaults = load_defaults();
my $cmd = config_to_command($storecfg, $vmid, $conf, $defaults);
my $opts = PVE::JSONSchema::pve_parse_startup_order($conf->{startup});
$timeout = $opts->{down} if $opts->{down};
}
+ PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'pre-stop');
}
$timeout = 60 if !defined($timeout);