Import commit 32fbe661230e6f8328b962559350efcc20a88b2d from xen-api-libs

Originally by Euan Harris

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>