If a virtual machine is no longer needed, it can be removed. There are two options for removing a virtual machine:
The following sample function illustrates how to implement both options. The function takes a Vm
object identifying the virtual machine and a boolean value indicating whether the virtual machine files should be deleted from the host computer.
def remove_vm(vm, delete):
if delete == False:
# Unregister the virtual machine but don't delete its files.
try:
vm.unreg()
except prlsdkapi.PrlSDKAsyncError, e:
print "Error: %s" % e
return
else:
# Unregister the machine and delete its files from the hard drive.
try:
vm.delete()
except prlsdkapi.PrlSDKAsyncError, e:
print "Error: %s" % e
return
print "Virtual machine " + vm.name + " has been removed."