Previous page

Next page

Locate page in Contents

Obtaining Virtual Machine Configuration Data

The virtual machine configuration information includes the machine name, guest operating system type and version, RAM size, disk drive and network adapter information, and other settings. To obtain this information, a prlsdkapi.VmConfig object must be obtained from the prlsdkapi.Vm object (the object that identifies the virtual machine). 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. To obtain the object, you can use the helper function search_vm() that we've created in the Searching for a Virtual Machine section.

Obtaining the RAM size

def get_vm_ram_size(vm):

  

    # Obtain the VmConfig object containing the virtual machine

    # configuration information.

    vm_config = vm.get_config()

  

    # Get the virtual machine RAM size.

    ram_size = vm_config.get_ram_size()

    print "RAM size: " + str(ram_size)

Obtaining the OS type and version

def get_vm_os_info(vm):

  

    print ""

    

    # Virtual machine name.

    print "Virtual machine name: " + vm.get_name()

  

    # Obtain the VmConfig object containing the virtual machine

    # configuration information.

    vm_config = vm.get_config()

  

    # Obtain the guest OS type and version.

    # OS types are defined as PVS_GUEST_TYPE_xxx constants.

    # For the complete list, see the documentation for

    # the prlsdkapi.prlsdk.consts module or

    # the Parallels Python API Reference guide.

    os_type = vm_config.get_os_type()

    if os_type == consts.PVS_GUEST_TYPE_WINDOWS:

        osType = "Windows"

    elif os_type == consts.PVS_GUEST_TYPE_LINUX:

        osType = "Linux"

    else:

        osType = "Other type (" + str(os_type) + ")"

        

    # OS versions are defined as PVS_GUEST_VER_xxx constants.

    os_version = vm_config.get_os_version()

    if os_version == consts.PVS_GUEST_VER_WIN_XP:

        osVersion = "XP"

    elif os_version == consts.PVS_GUEST_VER_WIN_2003:

        osVersion = "2003"

    elif os_version == consts.PVS_GUEST_VER_LIN_FEDORA_5:

        osVersion = "Fedora 5"

    else:

        osVersion = "Other version (" + str(os_version) + ")"

        

    print "Guest OS: " + osType + " " + osVersionRAM size

Obtaining optical disk drive information

def get_optical_drive_info(vm):

  

    # Obtain the VmConfig object containing the virtual machine

    # configuration information.

    vm_config = vm.get_config()

  

    print ""

    print "Optical Drives:"

    print "-------------------"

  

    # Iterate through the existing optical drive devices.

    count = vm_config.get_optical_disks_count()

    for i in range(count):

        print ""

        print "Drive " + str(i)

  

        # Obtain an instance of VmDevice containing the optical drive info.

        device = vm_config.get_optical_disk(i)

  

        # Get the device emulation type.

        # In case of optical disks, this value specifies whether the virtual device

        # is using a real disk drive or an image file.

        emulated_type = device.get_emulated_type()

        

        if emulated_type == consts.PDT_USE_REAL_DEVICE:

            print "Uses physical device"

        elif emulated_type == consts.PDT_USE_IMAGE_FILE:

            print "Uses image file " + '"' + device.get_image_path() + '"'

        else:

            print "Unknown emulation type"

  

        if device.is_enabled():

            print "Enabled"

        else:

            print "Disabled"

            

        if device.is_connected():

            print "Connected"

        else:

            print "Disconnected"

Obtaining hard disk information

def get_hdd_info(vm):

  

    # Obtain the VmConfig object containing the virtual machine

    # configuration information.

    vm_config = vm.get_config()

    

    print ""

    print "Virtual Hard Disks:"

    print "-------------------"

  

    count = vm_config.get_hard_disks_count()

    for i in range(count):

        print ""

        print "Disk " + str(i)

  

        hdd = vm_config.get_hard_disk(i)    

        emulated_type = hdd.get_emulated_type()

        

        if emulated_type == consts.PDT_USE_REAL_DEVICE:

            print "Uses Boot Camp: Disk " + hdd.get_friendly_name()

        elif emulated_type == consts.PDT_USE_IMAGE_FILE:

            print "Uses image file " + '"' + hdd.get_image_path() + '"'

  

        if hdd.get_disk_type() == consts.PHD_EXPANDING_HARD_DISK:

            print "Expanding disk"

        elif hdd.get_disk_type() == consts.PHD_PLAIN_HARD_DISK:

            print "Plain disk"

  

        print "Disk size:" + str(hdd.get_disk_size()) + " Mbyte"

        print "Size on physical disk: " + str(hdd.get_size_on_disk()) + " Mbyte"

Obtaining network adapter information

def get_net_adapter_info(vm):

    

    # Obtain the VmConfig object containing the virtual machine

    # configuration information.

    vm_config = vm.get_config()    

  

    # Obtain the network interface info.

    # The vm.net_adapters sequence contains objects of type VmNetDev.

    print ""

    print "Network Adapters:"

  

    count = vm_config.get_net_adapters_count()

    for i in range(count):

        print ""

        print "Adapter " + str(i)

  

        net_adapter = vm_config.get_net_adapter(i)

        

        emulated_type = net_adapter.get_emulated_type()

        

        if emulated_type == consts.PNA_HOST_ONLY:

            print "Uses host-only networking"

        elif emulated_type == consts.PNA_SHARED:

            print "Uses shared networking"

        elif emulated_type == consts.PNA_BRIDGED_ETHERNET:

            print "Uses bridged ethernet (bound to " + net_adapter.get_bound_adapter_name() + ")"

    print "MAC address " + str(net_adapter.get_mac_address())