Sorry, I forgot to attach the file.
From: Cindy Zhu
Sent: February-02-11 9:34 AM
To: 'staf-users@lists.sourceforge.net'
Subject: Use STAF and STAX to boot and shutdown VMWare images on my test
machines
Hi,
I am new to STAF.
I got the xml code from your web site to do the above job. The VM was able to
boot from the code, but the VM couldn't shut down.
I don't know why. Can you please help?
Thanks,
Cindy
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "D:\DistributionTesting\STAF\stax.dtd">
<stax>
<defaultcall function="main" />
<function name="main" scope="local">
<parallel>
<block name="'Boot up VMWare image'">
<call function="'startvmware'">{ 'image': 'E:/vmw1693-w72/vmw1693-w72.vmx', 'timeout' : '5m', 'imagehostname' : '10.0.7.229', 'imagename' : 'With SilkTest,STAF' }</call>
</block>
<block name="'Release this block to shutdown the VMWare image'">
<sequence>
<hold />
<call function="'stopvmware'">{ 'imagehostname' : '10.0.7.229', 'shutdown' : 'shutdown -s -f -t 0' }</call>
</sequence>
</block>
</parallel>
</function>
<function name="startvmware" scope="local">
<function-prolog>Starts a VMWare image, and attempts to do a STAF PING to the VMWare image. Your VMWare image needs to be configured so that there are no popups displayed when the VMWare image starts (for example, messages about Disk Drive warnings, etc), and that the image is set up to automatically log in. Also, the machine must be configured to start STAF automatically. Also, you must have the following 2 lines in your VMWare image's .vmx file: gui.exitOnCLIHLT = "TRUE" gui.exitAtPowerOff = "TRUE" Note that you should avoid terminating any blocks that are running a VMWare image, as that will kill the VMWare image without it being shutdown. Instead, you should manually shutdown and power off the VMWare image, or call the "terminatevmware" [not yet implemented] function. You should use Bridged network connections for VMWare images to work correctly with this function.</function-prolog>
<function-map-args>
<function-optional-arg name="machine" default="'local'">The machine on which the VMWare image is to be started. The default is 'local'.</function-optional-arg>
<function-optional-arg name="vmwarebin" default="'C:/Program Files (x86)/VMware/VMware Workstation/vmware.exe'">The VMWare executable file. If the VMWare executable is not in the VMWare system's PATH, then the file must be fully qualified. The default is 'c:/Program Files/Vmware/VMware Workstation/vmware.exe'.</function-optional-arg>
<function-required-arg name="image">The fully qualified VMWare .vmx file for the VMWare image. Note that the VMWare executable does not permit spaces in the file name of the vmx file.</function-required-arg>
<function-required-arg name="imagehostname">The hostname for the VMWare image.</function-required-arg>
<function-optional-arg name="timeout" default="'10m'">The timeout value for when the function should stop attempting to STAF PING the VMWare image. The default is 10 minutes. The STAF PING to the VMWare image will be attempted every 30 seconds, up to the timeout value.</function-optional-arg>
<function-optional-arg name="imagename" default='image'>The name of the VMWare image. The default is the argument specified for image.</function-optional-arg>
</function-map-args>
<parallel>
<process name="'VMWare Image %s ' % imagename">
<location>machine</location>
<command>vmwarebin</command>
<parms>'-x -q %s' % image</parms>
<!-- -x powers on automatically, -q exits at power off -->
<stdout>'out.txt'</stdout>
<stderr mode="'stdout'" />
<returnstdout />
</process>
<sequence>
<script>
contacted = 0
</script>
<timer duration='timeout'>
<loop while="contacted == 0">
<sequence>
<stafcmd name="'Delaying for 30 seconds'">
<location>'local'</location>
<service>'delay'</service>
<request>'delay 30000'</request>
</stafcmd>
<stafcmd name="'Attempt to ping %s' % imagehostname">
<location>imagehostname</location>
<service>'ping'</service>
<request>'ping'</request>
</stafcmd>
<if expr="RC == 0">
<sequence>
<script>
contacted = 1
</script>
<message>'Machine %s is up and running with VMWare image %s' % (imagehostname, imagename)</message>
<log>'Machine %s is up and running with VMWare image %s' % (imagehostname, imagename)</log>
</sequence>
</if>
</sequence>
</loop>
</timer>
<if expr="RC != 0">
<sequence>
<message>'Machine %s with VMWare image %s was not successfully started RC: %s' % (imagehostname, imagename, RC)</message>
<log>'Machine %s with VMWare image %s was not successfully started RC: %s' % (imagehostname, imagename, RC)</log>
</sequence>
</if>
</sequence>
</parallel>
</function>
<function name="stopvmware" scope="local">
<function-prolog>Stops a VMWare image</function-prolog>
<function-map-args>
<function-required-arg name="imagehostname">The hostname for the VMWare image.</function-required-arg>
<function-required-arg name="shutdown">The command used to shut down the OS.</function-required-arg>
</function-map-args>
<sequence>
<script>
from com.ibm.staf import STAFUtil
</script>
<stafcmd>
<location>imagehostname</location>
<service>'process'</service>
<request>'start async shell command %s' % STAFUtil.wrapData(shutdown)</request>
</stafcmd>
</sequence>
</function>
</stax>
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users