我发现了一个难看的方法来完成它,但至少它不需要在VM主机上安装或配置任何东西。
首先,我得到了一个名为winexe的实用程序,它可以让您打开与Windows机器的终端连接。
然后我写了一个很长的丑的Perl脚本管一些PowerShell代码到本机暂停所有正在运行的机器:
sub hv_suspend_host {
my $host = $_[0];
my $code = <<'END';
echo '===BEGIN'
$query = "SELECT * FROM Msvm_ComputerSystem WHERE EnabledState != 3 AND EnabledState != 32769" #Exclude off and saved VMs
$VMs = get-wmiobject -query $query -namespace "root\virtualization" -computername "."
foreach ($VM in $VMs) {
if ($VM.name -ne $VM.ElementName) { # Exclude the host itself
if ($VM.RequestStateChange(32769).ReturnValue -eq 4096) { # Put the VM in a saved state
# It worked, log success
} else {
# It didn't, log failure
}
}
}
echo '===END'
exit
END
my $recv;
run(["winexe", '-U', "DOMAIN/$win_user%$win_pass", '--interactive=0', "//$host", 'powershell -command -'], \$code, \$recv);
$recv =~ tr/\r//d; # Convert to UNIX line endings
$recv =~ /===BEGIN\n(.+)===END/s; # Now recv contains anything you logged
}
您可能必须惹这一点得到它的工作。我不得不破解一些特定于实现的东西,但是我留下了部分输出捕获代码。这需要全局变量$ win_user和$ win_pass包含目标VM主机的管理员帐户登录信息。它也需要你use IPC::Run
。
我认为在开发中有一个针对libvirt的Hyper-V驱动程序。不知道该项目是否完成,但它可能值得一看。 –