CA-227285 Better error when migrating non-resident VM
CA-227285 Better error when migrating non-resident VM

Return a more helpful error message when trying to migrate a VM that is
not resident on any host because it is not running.

The error message previously just complained about an invalid host
object reference, because Db.VM.get_resident_on returned Ref.null.
The new error message looks like this:

$ xe vm-migrate vm=a890044e-6503-2c38-e330-e4e0e749b857 host=dt14
You attempted an operation on a VM that was not in an appropriate power
state at the time; for example, you attempted to start a VM that was
already running.  The parameters returned are the VM's handle, and the
expected and actual VM state at the time of the call.
vm: a890044e-6503-2c38-e330-e4e0e749b857 (vm-1)
expected: running
actual: halted

The problem was that Db.VM.get_resident_on returned a null reference for
a VM that is not resident because it is not running. I moved the
affected code into the function passed to "with_vm_operation", which
checks that the VM is in the correct (Running) state, among many other
things. Since a running VM must be resident somewhere, the
Db.VM.get_resident_on call should always return a non-null reference.

I think the with_vm_operation function shouldn't swallow the exceptions
thrown by the function passed to it, because it calls the function with
Pervasiveext.finally, which seems to rethrow all the exceptions.

Signed-off-by: Gabor Igloi <7535f5501fd71876c93d896691e178fd3a11cfbb@citrix.com>

thomassa/xen-api,euanh/xen-api,Frezzle/xen-api,euanh/xen-api,euanh/xen-api,Frezzle/xen-api,thomassa/xen-api,thomassa/xen-api,srowe/xen-api,thomassa/xen-api,Frezzle/xen-api,euanh/xen-api,srowe/xen-api,srowe/xen-api,euanh/xen-api,euanh/xen-api,Frezzle/xen-api,thomassa/xen-api,srowe/xen-api,srowe/xen-api,Frezzle/xen-api,thomassa/xen-api