2015-09-07 12:18 GMT+02:00 Richard W.M. Jones <rjones(a)redhat.com>:
vpx:// paths looks like this:
vpx://vcenter.example.com/MyFolder/MyDatacenter/MyCluster/esxi
but to connect to the datastore to read the underlying disk image,
libguestfs must form a URL like this:
https://vcenter.example.com/folder/data/guest/guest-flat.vmdk?dcPath=MyFo...
All parts of this URL can be worked out from the URL or the libvirt
XML *except* the ?dcPath=... parameter.
The problem is that dcPath isn't a straight mapping from the vpx://
path. The particular problem is that if there is a cluster name in
the path (eg 'MyCluster') it appears that we have to remove it. ie:
dcPath=MyFolder/MyDatacenter/MyCluster - does not work
dcPath=MyFolder/MyDatacenter - works
That would be OK if there was always a cluster name at the end of the
path, but there isn't. Clusters are completely optional, and AFAIK
you can't tell if something is a cluster path element just by
examining the name, since clusters can be given arbitrary names by the
vCenter admin.
It's even more complex than that, you can have another level of
folders in there. The path can have this format for a vpx:// URI:
[<folder>/...]<datacenter>/[<folder>/...]<computeresource>[/<hostsystem>]
IIRC datacenter and computeresource name cannot contain slashes. At
leat libvirt assumes that it can't.
You cannot tell what is what in the path just by looking at the path
alone. libvirt handles this by asking the vCenter about this in
esxVI_Context_LookupManagedObjectsByPath.
The path is split at the slashes. Then the first part of the path is
looked up. As long as the part is a folder libvirt continues to look
into that folder for the next part of the path. Once the datacenter
was found this folder lookup logic continues to find a
(cluster-)computeresource. Once the computeresource was found the
hostsystem is looked up in it. If the computeresource is a cluster
then the hostsystem name has to be given in the path. if the
computeresource isn't a cluster then the computeresource and
hostsystem name are identical. Along this lookup libvirt build the
datacenter path and computeresource path and stores it for later use.
So:
(1) Is there something I'm missing here? Maybe the libvirt VMware
driver presents this information already and I'm just missing it?
The information is stored internally in the datacenterPath in the
esxVI_Context, but it is not accessible via libvirt API.
(2) Can we add some way to more easily map from vpx:// paths to
datastore URLs? The whole process is very complex even without the
ambiguity - it takes a couple of pages of code to do the mapping.
I assume you already connect to the vpx:// URI to get the dsName for a
given disk image anyway. I think the datacenter path could be exposed
as part of the domain XML as
<vmware:datacenterpath>/path/to/dc</vmware:datacenterpath> similar to
the way <qemu:commandline> works. But it would be ignored on parsing.
Would that work for you? If yes, I can propose a patch that does this.
--
Matthias Bolte
http://photron.blogspot.com