.. _`scripting.demo2`: ######### Demo 2 ######### This script shows how an admin can run a progam on a guest OS and check the results of that program. There are two functions defined, :py:func:`use_tools` and :py:func:`cleanup`. The admin can pick one of the two. A possible use case is this. .. parsed-literal:: >>> import demo2 >>> demo2.use_tools() Some Overheads :: """Demo script 2.""" from __future__ import print_function import logging from pyvix2 import Host, Error, VIX_ERROR_CODE, VIX_E_TIMEOUT_WAITING_FOR_TOOLS, VIX_E_TOOLS_NOT_RUNNING import sys #guest_os= r"G:\VMplanet-openSUSE11.3\[VMplanet] openSUSE 11.3.vmx" guest_os= r"C:\Fedora14\Fedora.vmx" .. py:function:: use_tools :: def use_tools(): host= Host() host.connect() vm= host.openVM(guest_os) vm.power_on() try: vm.wait_for_tools_in_guest() vm.login( "slott", "slott" ) pprint.pprint( vm.process_list() ) pid, et, exit = vm.script_run( "/bin/bash", "date >/home/slott/hostfile" ) time_string= time.asctime( time.localtime(et)) print( "PID=", pid, "Time=", time_string, "Exit=", exit ) vm.file_copy_from_guest( "/home/slott/hostfile", "hostfile" ) print( "Get File:" ) with open("hostfile","r") as hostfile: print( hostfile.read() ) vm.logout() except Error as e: if VIX_ERROR_CODE(e.errorCode) in ( VIX_E_TIMEOUT_WAITING_FOR_TOOLS, VIX_E_TOOLS_NOT_RUNNING ): # No tools. Get out of the pool. print( e ) else: # Other more serious problem. raise .. py:function:: cleanup :: def cleanup(): host= Host() host.connect() vm= host.openVM(guest_os) vm.power_off() Here's a main program switch that simply runs both steps. :: if __name__ == "__main__": logging.basicConfig( stream=sys.stderr, level=logging.DEBUG ) use_tools() cleanup()