virt-v2v can import guests directly from vCenter. It uses all sorts of tricks to make this fast and efficient, but the basic technique uses plain https
range requests.
Making it all work was not so easy and involved a lot of experimentation and bug fixing, and I don’t think it has been documented up to now. So this post describes how we do it. As usual the code is the ultimate repository of our knowledge so you may want to consult that after reading this introduction.
Note this is read-only access. Write access is possible, but you’ll have to use ssh instead.
VMware ESXi hypervisor has a web server but doesn’t support range requests, so although you can download an entire disk image in one go from the ESXi hypervisor, to random-access the image using libguestfs you will need VMware vCenter. You should check that virsh dumpxml works against your vCenter instance by following these instructions. If that doesn’t work, it’s unlikely the rest of the instructions will work.
You will need to know:
- The hostname or IP address of your vCenter server,
- the username and password for vCenter,
- the name of your datacenter (probably
Datacenter
), - the name of the datastore containing your guest (could be
datastore1
), - .. and of course the name of your guest.
Tricky step 1 is to construct the vCenter https URL of your guest.
This looks like:
https://root:password@vcenter/folder/guest/guest-flat.vmdk?dcPath=Datacenter&dsName=datastore1
where:
- root:password
- username and password
- vcenter
- vCenter hostname or IP address
- guest
- guest name (repeated twice)
- Datacenter
- datacenter name
- datastore1
- datastore
Once you’ve got a URL that looks right, try to fetch the headers using curl. This step is important! not just because it checks the URL is good, but because it allows us to get a cookie which is required else vCenter will break under the load when we start to access it for real.
$ curl --insecure -I https://.... HTTP/1.1 200 OK Date: Wed, 5 Nov 2014 19:38:32 GMT Set-Cookie: vmware_soap_session="52a3a513-7fba-ef0e-5b36-c18d88d71b14"; Path=/; HttpOnly; Secure; Accept-Ranges: bytes Connection: Keep-Alive Content-Type: application/octet-stream Content-Length: 8589934592
The cookie is the vmware_soap_session=...
part including the quotes.
Now let’s make a qcow2 overlay which encodes our https URL and the cookie as the backing file. This requires a reasonably recent qemu, probably 2.1 or above.
$ qemu-img create -f qcow2 /tmp/overlay.qcow2 \ -b 'json: { "file.driver":"https", "file.url":"https://..", "file.cookie":"vmware_soap_session=\"...\"", "file.sslverify":"off", "file.timeout":1000 }'
You don’t need to include the password in the URL here, since the cookie acts as your authentication. You might also want to play with the "file.readahead"
parameter. We found it makes a big difference to throughput.
Now you can open the overlay file in guestfish as usual:
$ export LIBGUESTFS_BACKEND=direct $ guestfish ><fs> add /tmp/overlay.qcow2 copyonread:true ><fs> run ><fs> list-filesystems /dev/sda1: ext4 ><fs> mount /dev/sda1 /
… and so on.