Previous page

Next page

Locate page in Contents

Adding an Existing Virtual Machine

A host may have virtual machines that are not registered with the Parallels Service. This can happen if a virtual machine was previously removed from the Parallels Service registry or if the virtual machine files were manually copied from a different location. If you know the location of such a virtual machine, you can easily register it with the Parallels Service.

Note: When adding an existing virtual machine, the MAC addresses of its virtual network adapters are kept unchanged. If the machine is a copy of another virtual machine, then you should set new MAC addresses for its network adapters after you register it. The example below demonstrates how this can be accomplished.

Example:

The following sample function demonstrates how to register an existing virtual machine. The function takes a Server object identifying the Parallels Service and a string specifying the name and path of the virtual machine directory (on Mac OS X it is the name of a bundle). It registers the virtual machine and then modifies the MAC address of every virtual network adapter installed in it.

"""

    Add an existing virtual machine.

    @param path: Name and path of the virtual machine directory or bundle.

                 The name normally has the .PVM extension.

"""

def register_vm(server, path):

  

    try:

        result = server.register_vm(path, False).wait()

    except prlsdkapi.PrlSDKError, e:

            print "Error: %s" % e

            return

  

    vm = result.get_param()

    vm_config = vm.get_config()

    print vm_config.get_name() + " was registered."

  

    # Generate a new MAC addresses for all virtual network adapters.

    # This should be done when a virtual machine was copied from another host.

    try:

        vm.begin_edit()

    except prlsdkapi.PrlSDKError, e:

        print "Error: %s" % e

        return

  

    # Iterate through the network adapter list and

    # generate a new MAC address.

    # The get_net_adapter(i) method returns an instance of the VmNet class.

    for i in range(vm_config.get_net_adapters_count()):

        net_adapter = vm_config.get_net_adapter(i)

        net_adapter.generate_mac_addr()

  

    # Commit the changes.

    try:

       vm.commit().wait()

    except prlsdkapi.PrlSDKError, e:

        print "Error: %s" % e

        return