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.
The following sample function demonstrates how to register an existing virtual machine. The function takes a Server
object identifying the Parallels Service (essentially a host) and a string specifying the name and path of the virtual machine directory. It registers the virtual machine and then modifies the MAC address of every virtual network adapter installed in it.
def reg_vm(server, path):
try:
vm = server.register_vm(path, False)
except prlsdkapi.PrlSDKAsyncError, e:
print "Error: %s" % e
return
print vm.name + " was registered."
# Generate new MAC addresses for network adapters.
# Begin the virtual machine editing operation.
try:
vm.begin_edit()
except prlsdkapi.PrlSDKAsyncError, e:
print "Unable to modify vm configuration: %s" % e
return
# Iterate through the adapters and
# generate a new MAC address.
# The vm.net_adapters is an sequence of VmNetDev.
for netdev in vm.net_adapters:
netdev.generate_mac_addr()
# Commit the changes.
try:
vm.commit().wait()
except prlsdkapi.PrlSDKAsyncError, e:
print "Unable to commit vm config changes: %s" % e
return