Relocate VM to different host, datastore and network

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Relocate VM to different host, datastore and network

Litty Preeth
I am trying to do a relocate VM to a different host without shared storage and the portgroup name is different on the target host. I tried the following:

        vm = get_obj(content, [vim.VirtualMachine], inputs['vm_name'])
        destination_host = get_obj(content, [vim.HostSystem], inputs['destination_host'])

        destination_datastore = get_obj(content,[vim.Datastore],
                                        inputs['destination_datastore'])
        destination_network = get_obj(content,[vim.Network],
                                      inputs['destination_network'])

        nic_dev = None
        for device in vm.config.hardware.device:
            if isinstance(device, vim.VirtualEthernetCard):
                nic_dev = device
                break
        print "NetDevice %s" % (str(nic_dev))

        destination_cluster = get_obj(content, [vim.ClusterComputeResource], inputs['destination_cluster'])
        resource_pool = destination_cluster.resourcePool

        print "Migrating %s to destination host %s" % (inputs['vm_name'], inputs['destination_host'])

        virtual_dev = vim.vm.device.VirtualEthernetCard(key=nic_dev.key,
                        backing=vim.vm.device.VirtualEthernetCard.NetworkBackingInfo(network=destination_network))
       
        nic_dev_spec = vim.vm.device.VirtualDeviceSpec(device=virtual_dev, operation=vim.vm.device.VirtualDeviceSpec.Operation.edit)

        relocate_spec = vim.vm.RelocateSpec(
                datastore= destination_datastore, host=destination_host, deviceChange=[nic_dev_spec], pool=resource_pool)
        print "ReslocateSpec %s" % relocate_spec
        task = vm.Relocate(relocate_spec, vim.VirtualMachine.MovePriority.defaultPriority)

But that the request is not including the deviceChange field:

<RelocateVM_Task xmlns="urn:vim25"><_this type="VirtualMachine">vm-1077</_this><spec><datastore type="Datastore">datastore-1141</datastore><pool type="ResourcePool">resgroup-1139</pool><host type="HostSystem">host-1140</host></spec><priority>defaultPriority</priority></RelocateVM_Task>

And then the task is failing with Caught vmodl fault: Currently connected network interface 'Network adapter 1' uses network 'VM Network', which is not accessible.

Please guide me in the right usage of the relocateVM API.

- Litty