Using vmrun to Control Virtual Machines. VmWare-vmrun execute actions use python
Project description
vmrunPacked
Installation
pip install vmrunPacked
About
python vmrun commands and actions execute power
actions. snapshot
actions. recoard
actions. guest os control
actions. vprobe
actions. general commands
actions
Import Pkg
import vmrunPacked
vmobj = vmrunPacked.Pack("/vmx_file_path/vm.vmx",userName="admin",passWord="admin@123")
# "product" this prams defualt "ws" options ["fusion", "player"]
Power Commands
In this Power command support
- start
- stop
- reset
- suspend
- pause
- unpause
start
import vmrunPacked
vmobj = 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.
stop
stop command Parameters two soft
and hard
vmobj.stop() #that call normal
vmobj.stop(soft=True) #that call soft "quick close" vm
vmobj.stop(hard=True) #that call hard "force close" vm
# Exception
# vmobj.stop(soft=True,hard=True)
# tha case defualt "soft" parms call
reset (reboot)
vmobj.reset() #that call normal
vmobj.reset(soft=True) #that call soft "quick close" vm
vmobj.reset(hard=True) #that call hard "force close" vm
# Exception
# vmobj.reset(soft=True,hard=True)
# tha case defualt "soft" parms call
suspend
vmobj.suspend() #that call normal
vmobj.suspend(soft=True) #that call soft "quick close" vm
vmobj.suspend(hard=True) #that call hard "force close" vm
# Exception
# vmobj.suspend(soft=True,hard=True)
# tha case defualt "soft" parms call
pause
vmobj.pause()
Pauses a virtual machine (.vmx file). You can use this either to pause replay, or to pause normal operation.
unpause
vmobj.unpause()
Resumes operation of a virtual machine (.vmx file) from where you paused replay or normal operation.
Snapshot Commands
support actions
- listSnapshots
- snapshot
- deleteSnapshot
- revertToSnapshot
listSnapshots
view list of snap shots
val = vmobj.list_snap_shots()
print(val)
#return value type "list"
snapshot
take snap shots vmware
snap_shot_name = "demo"
val = vmobj.snapshot(snap_shot_name)
print(val)
# retun valus type "list". success when empty list
Creates a snapshot of a virtual machine (.vmx file). For products such as Workstation that support multiple snapshots, you must provide the snapshot name.
deleteSnapshot
remove snap shots vmware
snap_shot_name = "demo"
val = vmobj.delete_snapshot(snap_shot_name)
print(val)
# retun valus type "list". success when empty list
Removes a snapshot from a virtual machine (.vmx file). For products such as Workstation that support multiple snapshots, you must provide the snapshot name.
revertToSnapshot
snap_shot_name = "demo"
val = vmobj.revert_to_snap_shot(snap_shot_name)
print(val)
# retun valus type "list". success when empty list
Sets 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 Commands
support actions
- beginRecording
- endRecording
- beginReplay
- endReplay
beginRecording
snap_name = "rec_demo"
val = vmobj.begin_recording(snap_name)
print(val)
# retun valus type "list". success when empty list
Begins recording a running virtual machine (.vmx file), storing activity in the specified snapshot object, with optional description.
endRecording
val = vmobj.end_recording()
print(val)
# retun valus type "list". success when empty list
Ends the recording of a virtual machine (.vmx file) that is in progress, and close its snapshot object.
beginReplay
snap_name = "rec_demo"
val = vmobj.begin_replay(snap_name)
print(val)
# retun valus type "list". success when empty list
Begins replaying the recorded activity of a powered off virtual machine (.vmx file) from a snapshot object, powering off if necessary.
endReplay
val = vmobj.end_replay()
print(val)
# retun valus type "list". success when empty list
Ends the replaying of a virtual machine (.vmx file) that is currently underway.
Guest Operating System Commands
support commands
- writeVariable
- readVariable
- runProgramInGuest
- runScriptInGuest
- setSharedFolderState
- addSharedFolder
- removeSharedFolder
- listProcessesInGuest
- killProcessInGuest
- fileExistsInGuest
- deleteFileInGuest
- renameFileInGuest
- createDirectoryInGuest
- deleteDirectoryInGuest
- listDirectoryInGuest
- copyFileFromHostToGuest
- copyFileFromGuestToHost
- captureScreen
writeVariable
var_name = "todo"
var_value = "todo_value"
vmobj.write_variable(var_name,var_value,runtimeConfig=True)
# "runtimeConfig" parms or "guestEnv"
readVariable
val_name = "todo"
vmobj.read_variable(var_name,runtimeConfig=True)
# "runtimeConfig" parms or "guestEnv"
runProgramInGuest
file_path = "D:\\new\\todo.bat"
vmobj.run_program_in_guest(file_path,activeWindow=True,interactive=True)
# "noWait" , "activeWindow" , "interactive" - bool value parms
runScriptInGuest
interpreter_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.
setSharedFolderState
share_name = "vm"
new_path = "D:\\path"
vmobj.set_shared_folder_state(share_name, new_path,writable=True)
# "readonly" or "writable" -> bool any one prams
Modifies the writability state of a folder shared between the host and a guest virtual machine (.vmx file).
addSharedFolder
share_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.
removeSharedFolder
share_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.
listProcessesInGuest
val = 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.
killProcessInGuest
pid = "<pid>"
val = vmobj.kill_process_in_guest(pid)
print(val)
# return value "list"
fileExistsInGuest
file_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.
deleteFileInGuest
file_path = "D:\\new\\t.mp3"
val = vmobj.delete_file_in_guest(file_path)
print(val)
# return value "list"
renameFileInGuest
old_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.
createDirectoryInGuest
var = "C:\\new\\own
vmobj.create_directory_in_guest(var)
Creates the specified directory in the guest operating system. VMware Tools and a valid guest login are required.
deleteDirectoryInGuest
var = "C:\\new\\own
vmobj.delete_directory_in_guest(var)
Deletes a directory from the guest operating system. VMware Tools and a valid guest login are required.
listDirectoryInGuest
var = "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.
copyFileFromHostToGuest
host_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)
copyFileFromGuestToHost
guest_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)
captureScreen
host_path = "/home/<user>/Pic/hub.png"
vmobj.capture_screen(host_path)
VProbes Commands
support commands
- vprobeVersion
- vprobeLoad
- vprobeReset
- vprobeListProbes
- vprobeListGlobals
vprobeVersion
vmobj.vprobe_version()
vprobeLoad
script_path = "<path>"
vmobj.vprobe_load(script_path)
vprobeReset
vmobj.vprobe_reset()
vprobeListProbes
val = vmobj.vprobe_list_probes()
print(val)
vprobeListGlobals
val = vmobj.vprobe_list_globals()
print(val)
GENERAL COMMANDS
support commands
- list
- upgradevm
- installtools
- register
- unregister
- clone
- deleteVM
- listRegisteredVM
- getGuestIpAddress
list
val = vmobj.list_vm()
print(val)
upgradevm
vmobj.upgrade_vm()
installtools
vmobj.install_tools()
register
vmobj.register()
unregister
vmobj.un_register()
clone
dest_vmx_file = "D:\\new\\clone.vmx"
snap_name = "<name>"
vmobj.clone(dest_vmx_file, snap_name, full=True)
# parms "full" or "linked" -> bool
listRegisteredVM
val = vmobj.list_registered_vm()
print(val)
deleteVM
vmobj.delete_vm()
getGuestIpAddress
val = vmobj.get_guest_ip_address()
print(val)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for vmrunPacked-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f886c6a07cefdda60719832821fda2ce165221cc2943df75c13e02f0180f8428 |
|
MD5 | c6a6a38e9506ca02aa1deea310b47901 |
|
BLAKE2b-256 | 572371be105a6bd8db95b0f5d5e41e6ca2f0ce42e04385061c122a79b3c56a08 |