测试到一定规模后,不免会用到虚拟机,针对VMware esx,列出几条常用的命令:
1. 列出esx server上的vm的存储路径(仅列出正在运行的vm)
vmrun -T esx -h https://ServerIP/sdk -u ServerUserName -p ServerPassword list
2. 启动某一个vm
vmrun -T esx -h https://ServerIP/sdk -u ServerUserName -p ServerPassword start "[datastore1] vmname/vmname.vmx"
3. 停止某一个vm
vmrun -T esx -h https://ServerIP/sdk -u ServerUserName -p ServerPassword stop "[datastore1] vmname/vmname.vmx"
4. 列出某个vm上的所有snapshot
vmrun -T esx -h https://ServerIP/sdk -u ServerUserName -p ServerPassword listsnapshots "[datastore1] vmname/vmname.vmx"
5. revert到指定vm上的指定snapshot
vmrun -T esx -h https://ServerIP/sdk -u ServerUserName -p ServerPassword revertToSnapshot "[datastore1] vmname/vmname.vmx" snapshotname
注意:此条命令对于esx 3.5版本无效,ref: http://www.vmware.com/support/developer/vix-api/VIX-1.6.2-ReleaseNotes.html
6. 执行vm上的某个程序
vmrun -T esx -h https://ServerIP/sdk -u ServerUserName -p ServerPassword -gu VMUserName -gp VMPassword runProgramInGuest "[datastore1] vmname/vmname.vmx" -interactive "c:/windows/system32/cmd.exe"
7. 执行vm上的某个bat
vmrun -T esx -h https://ServerIP/sdk -u ServerUserName -p ServerPassword -gu VMUserName -gp VMPassword runScriptInGuest "[datastore1] vmname/vmname.vmx" "" "cmd.exe /k /"C://Program Files//Microsoft Visual Studio//VC//vcvarsall.bat/" x86"
注意:设置bat的解释器为""
8. Copy file from guest to host
vmrun -T esx -h https://ServerIP/sdk -u ServerUserName -p ServerPassword -gu VMUserName -gp VMPassword copyFileFromGuestToHost "[datastore1] vmname/vmname.vmx" "c:/temp/test.xml" "//192.168.0.1/Shared/test.xml"
9. Copy file from host to guest
vmrun -T esx -h https://ServerIP/sdk -u ServerUserName -p ServerPassword -gu VMUserName -gp VMPassword copyFileFromHostToGuest "[datastore1] vmname/vmname.vmx" "//192.168.0.1/Shared/test.xml" "c:/temp/test.xml"
其他命令还有:
listProcessInGuest, killProcessInGuest, stop(power off vm), reset (reboot vm),