The virtual machine configuration information includes the machine name, guest operating system type and version, RAM size, disk drive and network adapter information, and some other settings. To obtain this information, a prlsdkapi.Vm
object identifying the virtual machine must first be obtained. The object methods can then be used to extract the data. The examples in this section show how to obtain the most commonly used configuration data. We will talk about modifying configuration parameters in the Modifying Virtual Machine Configuration section.
All sample functions below accept a single parameter -- an instance of prlsdkapi,Vm
class identifying the virtual machine. To obtain the object, you can use helper function search_vm()
that we've created in the Obtaining the Virtual Machine List section.
OS type and version
def get_vm_os_info(vm):
# Virtual machine name.
print "Virtual machine name: " + vm.name
# Obtain guest OS type and version.
# OS types are defined as PVS_GUEST_TYPE_xxx constants.
# For a complete list, see Parallels Python API Reference.
if vm.os_type == consts.PVS_GUEST_TYPE_WINDOWS:
osType = "Windows"
elif vm.os_type == consts.PVS_GUEST_TYPE_LINUX:
osType = "Linux"
else:
osType = str(vm.os_type)
# OS versions are defined as PVS_GUEST_VER_xxx constants.
if vm.os_version == consts.PVS_GUEST_VER_WIN_XP:
osVersion = "XP"
elif vm.os_version == consts.PVS_GUEST_VER_FEDORA_5:
osVersion = "Fedora 5"
else:
osVersion = str(vm.os_version)
print "Guest OS: " + osType + " " + osVersion
RAM size
def get_ram_size(vm):
# Get RAM size
print "RAM size: " + str(vm.ram_size)
CD drive information
def get_cd_drive_info(vm):
# CD/DVD drive info.
# The vm.optical_devs sequence contains objects of type VmOpticalDev.
print ""
print "CD/DVD DRIVE INFO:"
i = 1
for opt_dev in vm.optical_devs:
print ""
print "Drive " + str(i)
i = i + 1
if opt_dev.emulated_type == consts.PDT_USE_REAL_DEVICE:
print "Uses physical device"
elif opt_dev.emulated_type == consts.PDT_USE_IMAGE_FILE:
print "Uses image file " + '"' + opt_dev.image_path + '"'
if opt_dev.enabled:
print "Enabled - yes"
else:
print "Enabled - no"
if opt_dev.connected:
print "Connected - yes"
else:
print "Connected - no"
Hard disk drive information
def get_hdd_info(vm):
# Obtain hard disk info.
# The vm.hdd_devs sequence contains objects of type VmHddDev.
print ""
print "HARD DISK INFO:"
i = 1
for hdd_dev in vm.hdd_devs:
print ""
print "Disk " + str(i)
i = i + 1
if hdd_dev.emulated_type == consts.PDT_USE_REAL_DEVICE:
print "Uses Boot Camp: Disk " + hdd_dev.friendly_name
elif hdd_dev.emulated_type == consts.PDT_USE_IMAGE_FILE:
print "Uses image file " + '"' + hdd_dev.image_path + '"'
if hdd_dev.disk_type == consts.PHD_EXPANDING_HARD_DISK:
print "Expanding disk"
elif hdd_dev.disk_type == consts.PHD_PLAIN_HARD_DISK:
print "Plain disk"
print "Total size: " + str(hdd_dev.disk_size) + " MB"
print "Occupied space: " + str(hdd_dev.size_on_disk) + " MB"
Network adapter information
def get_net_adapter_info(vm):
# Obtain network interface info.
# The vm.net_adapters sequence contains objects of type VmNetDev.
print ""
print "NET ADAPTER INFO:"
i = 1
for net_dev in vm.net_adapters:
print ""
print "Adapter " + str(i)
i = i + 1
if net_dev.emulated_type == consts.PNA_HOST_ONLY:
print "Uses host-only networking"
elif net_dev.emulated_type == consts.PNA_SHARED:
print "Uses shared networking"
elif net_dev.emulated_type == consts.PNA_BRIDGED_ETHERNET:
print "Uses bridged ethernet (" + net_dev.bound_adapter_name + ")"
print "MAC address " + str(net_dev.mac_address)