Previous page

Next page

Locate page in Contents

Name, Description, Boot Options, RAM size

The virtual machine name, description, and RAM size modifications are simple. They are performed by invoking a corresponding method of a Vm object. To modify the boot options (boot device priority), obtain an instance of the prlsdkapi.BootDevice class representing each device. This step is performed using the VmConfig.get_boot_dev_count method to determine the total number of boot devices, then iterating through the list and obtaining a BootDevice object using the VmConfig.get_boot_dev method. To place a device at the specified position in the boot device priority list, use the BootDevice.set_sequence_index method passing a value of 0 to the first device, 1 to the second device, and so forth. If you have more than one instance of a particular device type in the boot list (i.e. more than one CD/DVD drive), you will have to set a sequence index for each instance individually. An instance is identified by an index that can be obtained using the VmBootDev.get_index method. A device in the boot priority list can be enabled or disabled using the BootDevice.set_in_use method. Disabling the device does not remove it from the boot device list. To remove a device from the list, use the BootDevice.remove method.

Example

"""

Modify the vrtual machine name, RAM size, and boot options.

"""

def vm_edit(vm):

# Begin the virtual machine editing operation.

try:

vm.begin_edit().wait()

except prlsdkapi.PrlSDKError, e:

print "Error: %s" % e

return

# Obtain the VmConfig object containing the virtual machine

# configuration information.

vm_config = vm.get_config()

vm.set_name(vm.get_name() + "_modified")

vm.set_ram_size(256)

vm.set_description("SDK Test Machine")

# Modify boot device priority using the following order:.

# CD > HDD > Network > FDD.

# Remove all other devices from the boot priority list (if any).

count = vm_config.get_boot_dev_count()

for i in range(count):

# Obtain an instance of the prlsdkapi.BootDevice class

# containing the boot device information.

boot_dev = vm_config.get_boot_dev(i)

# Enable the device.

boot_dev.set_in_use(True)

# Set the device sequence index.

dev_type = boot_dev.get_type()

if dev_type == consts.PDE_OPTICAL_DISK:

boot_dev.set_sequence_index(0)

elif dev_type == consts.PDE_HARD_DISK:

boot_dev.set_sequence_index(1)

elif dev_type == consts.PDE_GENERIC_NETWORK_ADAPTER:

boot_dev.set_sequence_index(2)

elif dev_type == consts.PDE_FLOPPY_DISK:

boot_dev.set_sequence_index(3)

else:

boot_dev.remove()

# Commit the changes.

try:

vm.commit().wait()

except prlsdkapi.PrlSDKError, e:

print "Error: %s" % e

return