zoukankan      html  css  js  c++  java
  • API控制VM虚拟机(VM Workstation or VM Server)

    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 Generally, we can use VMRUN to implement software automation testing.

    6 one issue

    vmrun quotes each argument it passes to the guest

    so if you want to install msi in guest OS, you can use below workaround:

    echo C:\Windows\system32\msiexec.exe /i C:\app.msi > C:\sourcebatch.bat
    vmrun -T ws -gu USERNAME -gp PASSWORD copyFileFromHostToGuest "C:\VMs\VM1\VM1.vmx" "C:\sourcebatch.bat" "C:\destbatch.bat"

    vmrun -T ws -gu USERNAME -gp PASSWORD runProgramInGuest "C:\VMs\VM1\VM1.vmx" cmd.exe "/c C:\destbatch.bat"

    vmrun -T ws -gu USERNAME -gp PASSWORD deleteFileInGuest "C:\VMs\VM1\VM1.vmx" "C:\destbatch.bat"

    Reference (Using vmrun runProgramInGuest with Windows Installer (MSI) packages) (http://communities.vmware.com/blogs/vmroyale/2009/04/23/using-vmrun-runprograminguest-with-windows-installer-msi-packages )

     

    完!



    作者:iTech
    微信公众号: cicdops
    出处:http://itech.cnblogs.com/
    github:https://github.com/cicdops/cicdops

  • 相关阅读:
    JetBrains全系列破解
    BZOJ 4817: [Sdoi2017]树点涂色 LCT + DFS序 + 线段树
    LOJ #6041. 「雅礼集训 2017 Day7」事情的相似度 LCT + SAM + 线段树
    Uoj 52. 【UR #4】元旦激光炮 交互题
    Uoj #218. 【UNR #1】火车管理 可持久化线段树+思维
    luoguP3979 遥远的国度 LCT + multiset维护子树信息
    BZOJ 4999: This Problem Is Too Simple! DFS序 + LCA + 树状数组 + 离线
    BZOJ 1787: [Ahoi2008]Meet 紧急集合
    BZOJ 2959: 长跑 LCT + 并查集 + 点双
    BZOJ 4259: 残缺的字符串 FFT
  • 原文地址:https://www.cnblogs.com/itech/p/1616164.html
Copyright © 2011-2022 走看看