The virtual machine name, description, and RAM size modifications are simple. They are performed by modifying a corresponding property of a Vm
object. To modify the boot options (boot device priority), obtain a reference to a VmBootDev
object representing each device. This step is performed using the Vm.boot_devs
property which is an iterator/sequence. To place a device at the specified position in the boot device priority list, use the VmBootDev.sequence_index
property assigning 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 the VmBootDev.index
property.
The following sample function illustrates how to make the above modifications.
def vm_edit(vm):
# Begin the virtual machine editing operation.
try:
vm.begin_edit()
except prlsdkapi.PrlSDKAsyncError, e:
print "Unable to modify vm configuration: %s" % e
return
# Change name, description, RAM size.
vm.name = "Windows XP"
vm.description = "Windows test machine"
vm.ram_size = 256
# Modify boot options.
# Set the following order:
# CD/DVD, HDD, Network, FDD.
# Remove all other devices from
# the boot list (if any).
# The vm.boot_devs is a sequence of VmBootDev.
for dev in vm.boot_devs:
# Enable the device (in case it is disabled).
# You can also disable a particular device if needed.
dev.in_use = True
# Set sequence index.
if dev.type == consts.PDE_OPTICAL_DISK:
dev.sequence_index = 0
elif dev.type == consts.PDE_HARD_DISK:
dev.sequence_index = 1
elif dev.type == consts.PDE_GENERIC_NETWORK_ADAPTER:
dev.sequence_index = 2
elif dev.type == consts.PDE_FLOPPY_DISK:
dev.sequence_index = 3
else:
dev.remove()
# Commit the changes.
try:
vm.commit().wait()
except prlsdkapi.PrlSDKAsyncError, e:
print "Unable to commit vm config changes: %s" % e
return