Previous page

Next page

Locate page in Contents

Removing an Existing Virtual Machine

If a virtual machine is no longer needed, it can be removed. There are two options for removing a virtual machine:

  • Un-register the virtual machine without deleting its files. You can re-register the virtual machine later if needed.
  • Delete the virtual machine from the host completely. The virtual machine files will be permanently deleted and cannot be recovered if this option is used.

Example

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.

"""

    Remove an existing virtual machine.

    @param vm: An instance of prlsdkapi.Vm class identifying

               the virtual machine.

    @param delete: A boolean value indicating whether the

                   virtual machine files should be permanently deleted

                   from the host.

"""

def remove_vm(vm, delete):

  

    if delete == False:

        # Unregister the virtual machine but don't delete its files.

        try:

            vm.unreg()

        except prlsdkapi.PrlSDKError, e:

            print "Error: %s" % e

            return

    else:

        # Unregister the machine and delete its files from the hard drive.

        try:

            vm.delete()

        except prlsdkapi.PrlSDKError, e:

            print "Error: %s" % e

            return

  

    print vm.get_config().get_name() + " has been removed."