Package: vmrunPacked
vmrunPackedInstallationpip install vmrunPackedAboutpython vmrun commands and actions executepoweractions.snapshotactions.recoardactions.guest os controlactions.vprobeactions.general commandsactionsImport PkgimportvmrunPackedvmobj=vmrunPacked.Pack("/vmx_file_path/vm.vmx",userName="admin",passWord="admin@123")# "product" this prams defualt "ws" options ["fusion", "player"]Power CommandsIn this Power command supportstartstopresetsuspendpauseunpausestartimportvmrunPackedvmobj=vmrunPacked.Pack("/vmx_file_path/vm.vmx",userName="admin",passWord="admin@123")vmobj.start()Starts a virtual machine (.vmx file) or team (.vmtm file). The default gui option starts the machine interactively, including startup dialog box, to allow noninteractive scripting.stopstop command Parameters twosoftandhardvmobj.stop()#that call normalvmobj.stop(soft=True)#that call soft "quick close" vmvmobj.stop(hard=True)#that call hard "force close" vm# Exception# vmobj.stop(soft=True,hard=True)# tha case defualt "soft" parms callreset (reboot)vmobj.reset()#that call normalvmobj.reset(soft=True)#that call soft "quick close" vmvmobj.reset(hard=True)#that call hard "force close" vm# Exception# vmobj.reset(soft=True,hard=True)# tha case defualt "soft" parms callsuspendvmobj.suspend()#that call normalvmobj.suspend(soft=True)#that call soft "quick close" vmvmobj.suspend(hard=True)#that call hard "force close" vm# Exception# vmobj.suspend(soft=True,hard=True)# tha case defualt "soft" parms callpausevmobj.pause()Pauses a virtual machine (.vmx file). You can use this either to pause replay, or to pause normal operation.unpausevmobj.unpause()Resumes operation of a virtual machine (.vmx file) from where you paused replay or normal operation.Snapshot Commandssupport actionslistSnapshotssnapshotdeleteSnapshotrevertToSnapshotlistSnapshotsview list of snap shotsval=vmobj.list_snap_shots()print(val)#return value type "list"snapshottake snap shots vmwaresnap_shot_name="demo"val=vmobj.snapshot(snap_shot_name)print(val)# retun valus type "list". success when empty listCreates a snapshot of a virtual machine (.vmx file). For products such as Workstation that support multiple snapshots, you must provide the snapshot name.deleteSnapshotremove snap shots vmwaresnap_shot_name="demo"val=vmobj.delete_snapshot(snap_shot_name)print(val)# retun valus type "list". success when empty listRemoves a snapshot from a virtual machine (.vmx file). For products such as Workstation that support multiple snapshots, you must provide the snapshot name.revertToSnapshotsnap_shot_name="demo"val=vmobj.revert_to_snap_shot(snap_shot_name)print(val)# retun valus type "list". success when empty listSets the virtual machine to its state at snapshot time. If a snapshot has a unique name within a virtual machine, revert to that snapshot by specifying the path to the virtual machine’s configuration file and the unique snapshot name.Record and Replay Commandssupport actionsbeginRecordingendRecordingbeginReplayendReplaybeginRecordingsnap_name="rec_demo"val=vmobj.begin_recording(snap_name)print(val)# retun valus type "list". success when empty listBegins recording a running virtual machine (.vmx file), storing activity in the specified snapshot object, with optional description.endRecordingval=vmobj.end_recording()print(val)# retun valus type "list". success when empty listEnds the recording of a virtual machine (.vmx file) that is in progress, and close its snapshot object.beginReplaysnap_name="rec_demo"val=vmobj.begin_replay(snap_name)print(val)# retun valus type "list". success when empty listBegins replaying the recorded activity of a powered off virtual machine (.vmx file) from a snapshot object, powering off if necessary.endReplayval=vmobj.end_replay()print(val)# retun valus type "list". success when empty listEnds the replaying of a virtual machine (.vmx file) that is currently underway.Guest Operating System Commandssupport commandswriteVariablereadVariablerunProgramInGuestrunScriptInGuestsetSharedFolderStateaddSharedFolderremoveSharedFolderlistProcessesInGuestkillProcessInGuestfileExistsInGuestdeleteFileInGuestrenameFileInGuestcreateDirectoryInGuestdeleteDirectoryInGuestlistDirectoryInGuestcopyFileFromHostToGuestcopyFileFromGuestToHostcaptureScreenwriteVariablevar_name="todo"var_value="todo_value"vmobj.write_variable(var_name,var_value,runtimeConfig=True)# "runtimeConfig" parms or "guestEnv"readVariableval_name="todo"vmobj.read_variable(var_name,runtimeConfig=True)# "runtimeConfig" parms or "guestEnv"runProgramInGuestfile_path="D:\\new\\todo.bat"vmobj.run_program_in_guest(file_path,activeWindow=True,interactive=True)# "noWait" , "activeWindow" , "interactive" - bool value parmsrunScriptInGuestinterpreter_path="C:\\Program Files\\Ruby\\ruby.exe"file_path="D:\\new\\init.rb"vmobj.run_script_in_guest(interpreter_path,file_path)Runs a command script in the guest operating system. VMware Tools and a valid guest login are required.setSharedFolderStateshare_name="vm"new_path="D:\\path"vmobj.set_shared_folder_state(share_name,new_path,writable=True)# "readonly" or "writable" -> bool any one pramsModifies the writability state of a folder shared between the host and a guest virtual machine (.vmx file).addSharedFoldershare_name="vm"host_path="D:\\new_path"vmobj.add_shared_folder(share_name,host_path)Adds a folder to be shared between the host and guest. The share name is a mount point in the guest file system. The path to folder is the exported directory on the host.removeSharedFoldershare_name="D:\\new_path"vmobj.remove_shared_folder(share_name)Removes a guest virtual machine’s access to a shared folder on the host. The share name is a mount point in the guest file system.listProcessesInGuestval=vmobj.list_processes_in_guest()print(val)# return value "list"Lists all processes running in the guest operating system. VMware Tools and a valid guest login are required.killProcessInGuestpid="<pid>"val=vmobj.kill_process_in_guest(pid)print(val)# return value "list"fileExistsInGuestfile_path="D:\\new\\t.mp3"val=vmobj.file_exists_in_guest(file_path)print(val)# return value "list"Checks whether the specified file exists in the guest operating system. VMware Tools and a valid guest login are required.deleteFileInGuestfile_path="D:\\new\\t.mp3"val=vmobj.delete_file_in_guest(file_path)print(val)# return value "list"renameFileInGuestold_file_name="D:\\new\\todo.png"new_file_name="D:\\new\\work.png"vmobj.rename_file_in_guest(old_file_name,new_file_name)Renames or moves a file in the guest operating system. VMware Tools and a valid guest login are required.createDirectoryInGuestvar="C:\\new\\ownvmobj.create_directory_in_guest(var)Creates the specified directory in the guest operating system. VMware Tools and a valid guest login are required.deleteDirectoryInGuestvar="C:\\new\\ownvmobj.delete_directory_in_guest(var)Deletes a directory from the guest operating system. VMware Tools and a valid guest login are required.listDirectoryInGuestvar="D:\\new"val=vmobj.list_directory_in_guest(var)print(val)# return value "list"Lists directory contents in the guest operating system. VMware Tools and a valid guest login are required.copyFileFromHostToGuesthost_file_path="/home/<user>/h.txt"guest_file_path="D:\\h.txt"vmobj.copy_file_from_host_to_guest(host_file_path,guest_file_path)copyFileFromGuestToHostguest_file_path="D:\\h.txt"host_file_path="/home/<user>/h.txt"vmobj.copy_file_from_guest_to_host(guest_file_path,host_file_path)captureScreenhost_path="/home/<user>/Pic/hub.png"vmobj.capture_screen(host_path)VProbes Commandssupport commandsvprobeVersionvprobeLoadvprobeResetvprobeListProbesvprobeListGlobalsvprobeVersionvmobj.vprobe_version()vprobeLoadscript_path="<path>"vmobj.vprobe_load(script_path)vprobeResetvmobj.vprobe_reset()vprobeListProbesval=vmobj.vprobe_list_probes()print(val)vprobeListGlobalsval=vmobj.vprobe_list_globals()print(val)GENERAL COMMANDSsupport commandslistupgradevminstalltoolsregisterunregisterclonedeleteVMlistRegisteredVMgetGuestIpAddresslistval=vmobj.list_vm()print(val)upgradevmvmobj.upgrade_vm()installtoolsvmobj.install_tools()registervmobj.register()unregistervmobj.un_register()clonedest_vmx_file="D:\\new\\clone.vmx"snap_name="<name>"vmobj.clone(dest_vmx_file,snap_name,full=True)# parms "full" or "linked" -> boollistRegisteredVMval=vmobj.list_registered_vm()print(val)deleteVMvmobj.delete_vm()getGuestIpAddressval=vmobj.get_guest_ip_address()print(val)