S.l.e!ep.¢%

像打了激速一样,以四倍的速度运转,开心的工作
简单、开放、平等的公司文化;尊重个性、自由与个人价值;
posts - 1098, comments - 335, trackbacks - 0, articles - 1
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

API控制VM虚拟机(VM Workstation or VM Server)

Posted on 2010-03-02 12:54 S.l.e!ep.¢% 阅读(1012) 评论(0)  编辑 收藏 引用 所属分类: test

API控制VM虚拟机(VM Workstation or VM Server)

作者:iTech  来源:博客园  发布时间:2009-12-03 13:55  阅读:326 次  原文链接   [收藏]  
<!--[endif]-->

Controlling VM by Script

1 VMRun

VMRun is a command line tool which is delivered with VM workstation or VM server. the tool have many sub commands to control VM, such as starting and stopping VM, creating and reverting to snapshot, run programs or scripts in VM, setting shared folder and setting environment variables in VM, creating and deleting folder and file in VM, checking and killing process in VM, taking record and capturing screen.

 

Of course you also can find other language wrapper for VMRun, such as VMRun-Python.

 

2 VIX API

The VIX API allows you to do the same things with VMRun, and you needn't install VM workstation or VM server, just need install VIX SDK. The VIX API allows you to automate virtual machine operations on VMware Server or VMware Workstation.

The VIX API can be accessed by C, Perl and COM.

 

3 VMRun command usage

Vmrun /?

 

4 examples

@echo off

 

echo setting the path of vmrun.exe into the system path.

rem set path="C:\Program Files\VMware\VMware Workstation";%path%

set path="C:\Program Files\VMware\VMware VIX";%path%

 

set vmImage="D:\VMRun\VMrun_Test\Windows XP Professional.vmx"

set vmtype=ws

 

set guestuser=AAA

set guestpassword=AAA

 

set snapshotname=snapshot1

 

set hostsharedfolder=d:\share

set guestnewfolder=c:\share

 

echo revert to snapshot

vmrun -t %vmtype% revertToSnapshot %vmimage% %snapshotname%

 

echo start vm without gui

vmrun -t %vmtype% -gu %guestuser% -gp %guestpassword% start %vmImage% nogui

 

echo run notpad.exe in vm

rem vmrun -t %vmtype% -gu %guestuser% -gp %guestpassword% runprograminguest %vmimage% -activeWindow "c:\windows\system32\notepad.exe"

 

echo set the host shared folder %hostsharedfolder% for accessing in VM, you can access the shared folder by \\.host\****

vmrun -t %vmtype% -gu %guestuser% -gp %guestpassword% addSharedFolder %vmimage% hostsharedfolder %hostsharedfolder%

 

echo create one new folder in VM

vmrun -t %vmtype% -gu %guestuser% -gp %guestpassword% createDirectoryInGuest %vmimage% %guestnewfolder%

 

echo copy files from the host to VM

vmrun -t %vmtype% -gu %guestuser% -gp %guestpassword% copyFileFromHostToGuest %vmimage% %hostsharedfolder%\* %guestnewfolder%

 

echo check whether the file is exist in VM

vmrun -t %vmtype% -gu %guestuser% -gp %guestpassword% fileExistsInGuest %vmimage% %guestnewfolder%\test.bat

 

echo run script in VM

vmrun -t %vmtype% -gu %guestuser% -gp %guestpassword% runProgramInGuest %vmimage% %guestnewfolder%\test.bat

 

echo copy files from VM to the host

vmrun -t %vmtype% -gu %guestuser% -gp %guestpassword% copyFileFromguestTohost %vmimage% %guestnewfolder%\test2.txt %hostsharedfolder%

 

echo capture VM screen

vmrun -t %vmtype% -gu %guestuser% -gp %guestpassword% captureScreen %vmimage% %hostsharedfolder%\resultscreen.png

 

5 一般地,我们可以通过API来控制VM,实现软件测试的全自动化。


6 reference

使用runprograminVM来在VM中自动安装软件时注意:http://communities.vmware.com/blogs/vmroyale/2009/04/23/using-vmrun-runprograminguest-with-windows-installer-msi-packages

Using vmrun runProgramInGuest with Windows Installer (MSI) packages

 

完!


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理