[libvirt] VMware: Map vpx:// to dcPath

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=MyFolder/MyDatacenter&dsName=datastore 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. So: (1) Is there something I'm missing here? Maybe the libvirt VMware driver presents this information already and I'm just missing it? (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. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top

2015-09-07 12:18 GMT+02:00 Richard W.M. Jones <rjones@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:
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

On Mon, Sep 07, 2015 at 02:29:22PM +0200, Matthias Bolte wrote:
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.
Yup, was simplifying for the sake of keeping the email short :-)
(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.
Yup, current code is here (which doesn't include connecting to VMware or getting the domain XML - that is done elsewhere): https://github.com/libguestfs/libguestfs/blob/master/v2v/input_libvirt_vcent...
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.
Absolutely this would be brilliant. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html

2015-09-07 22:04 GMT+02:00 Richard W.M. Jones <rjones@redhat.com>:
On Mon, Sep 07, 2015 at 02:29:22PM +0200, Matthias Bolte wrote:
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.
Absolutely this would be brilliant.
Okay, here's patch that does this. It's only tested using the test suite, as I don't have an ESX setup at hand at the moment. Do you have the possibility to test this properly? -- Matthias Bolte http://photron.blogspot.com

On Fri, Sep 11, 2015 at 03:55:03PM +0200, Matthias Bolte wrote:
2015-09-07 22:04 GMT+02:00 Richard W.M. Jones <rjones@redhat.com>:
On Mon, Sep 07, 2015 at 02:29:22PM +0200, Matthias Bolte wrote:
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.
Absolutely this would be brilliant.
Okay, here's patch that does this. It's only tested using the test suite, as I don't have an ESX setup at hand at the moment. Do you have the possibility to test this properly?
I tried it against two vCenter instances, and I see the additional XML like this: <domain type='vmware' xmlns:vmware='http://libvirt.org/schemas/domain/vmware/1.0'> ... <vmware:datacenterpath>Folder/Datacenter</vmware:datacenterpath> </domain> That seems fine and it's something we can use in libguestfs. Looks good to me, so ACK. Minor comment on the patch below.
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 21cf333..f3cbbf5 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -145,6 +145,9 @@ vmwareLoadDomains(struct vmware_driver *driver) virCommandPtr cmd;
ctx.parseFileName = vmwareCopyVMXFileName; + ctx.formatFileName = NULL; + ctx.autodetectSCSIControllerModel = NULL; + ctx.datacenterPath = NULL;
cmd = virCommandNewArgList(driver->vmrun, "-T", vmwareDriverTypeToString(driver->type), diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index ec74fe3..e228aaa 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -381,7 +381,10 @@ vmwareDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla if (flags & VIR_DOMAIN_DEFINE_VALIDATE) parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE;
+ ctx.parseFileName = NULL; ctx.formatFileName = vmwareCopyVMXFileName; + ctx.autodetectSCSIControllerModel = NULL; + ctx.datacenterPath = NULL;
vmwareDriverLock(driver); if ((vmdef = virDomainDefParseString(xml, driver->caps, driver->xmlopt, @@ -671,7 +674,10 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml, if (flags & VIR_DOMAIN_START_VALIDATE) parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE;
+ ctx.parseFileName = NULL; ctx.formatFileName = vmwareCopyVMXFileName; + ctx.autodetectSCSIControllerModel = NULL; + ctx.datacenterPath = NULL;
vmwareDriverLock(driver);
@@ -1022,6 +1028,9 @@ vmwareConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat, }
ctx.parseFileName = vmwareCopyVMXFileName; + ctx.formatFileName = NULL; + ctx.autodetectSCSIControllerModel = NULL; + ctx.datacenterPath = NULL;
This appears to be an unrelated fix? Perhaps it should go in a separate commit. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/

On Fri, Sep 11, 2015 at 03:55:03PM +0200, Matthias Bolte wrote:
2015-09-07 22:04 GMT+02:00 Richard W.M. Jones <rjones@redhat.com>:
On Mon, Sep 07, 2015 at 02:29:22PM +0200, Matthias Bolte wrote:
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.
Absolutely this would be brilliant.
Okay, here's patch that does this. It's only tested using the test suite, as I don't have an ESX setup at hand at the moment. Do you have the possibility to test this properly?
From 489e2d5dd29dd4b11716897ca52b14f6666ec141 Mon Sep 17 00:00:00 2001 From: Matthias Bolte <matthias.bolte@googlemail.com> Date: Fri, 11 Sep 2015 12:00:47 +0200 Subject: [PATCH] vmx: Expose datacenter path in domain XML
If you're happy with this patch, I'd like to push it to the libvirt repo. I didn't see any later version on the list. Let me know if this is the final version. Also I have opened a BZ for the problem so the fix can be included in RHEL 7.3: https://bugzilla.redhat.com/show_bug.cgi?id=1263574 Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/

2015-09-16 10:47 GMT+02:00 Richard W.M. Jones <rjones@redhat.com>:
On Fri, Sep 11, 2015 at 03:55:03PM +0200, Matthias Bolte wrote:
2015-09-07 22:04 GMT+02:00 Richard W.M. Jones <rjones@redhat.com>:
On Mon, Sep 07, 2015 at 02:29:22PM +0200, Matthias Bolte wrote:
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.
Absolutely this would be brilliant.
Okay, here's patch that does this. It's only tested using the test suite, as I don't have an ESX setup at hand at the moment. Do you have the possibility to test this properly?
From 489e2d5dd29dd4b11716897ca52b14f6666ec141 Mon Sep 17 00:00:00 2001 From: Matthias Bolte <matthias.bolte@googlemail.com> Date: Fri, 11 Sep 2015 12:00:47 +0200 Subject: [PATCH] vmx: Expose datacenter path in domain XML
If you're happy with this patch, I'd like to push it to the libvirt repo. I didn't see any later version on the list. Let me know if this is the final version.
Also I have opened a BZ for the problem so the fix can be included in RHEL 7.3:
Regarding your question about the changes to the VMware driver: The only required change is the addition for "ctx.datacenterPath = NULL" where virVMXParseConfig is called. The other additions are not really necessary. I made them for the sake of completeness and to match the usage in the ESX driver. Overall I'm happy with this patch. The only concern I have is that the domain XML might not be quite the right place to expose this information. But there are not many other places to expose this without adding new public API. But I assume that the domain XML is the most convenient was for libguestfs to get this information, isn't it? Anyway, there is no later version of this patch. I'm okay with you pushing it to the libvirt repo. -- Matthias Bolte http://photron.blogspot.com

On Thu, Sep 17, 2015 at 10:28:02AM +0200, Matthias Bolte wrote:
2015-09-16 10:47 GMT+02:00 Richard W.M. Jones <rjones@redhat.com>:
On Fri, Sep 11, 2015 at 03:55:03PM +0200, Matthias Bolte wrote:
2015-09-07 22:04 GMT+02:00 Richard W.M. Jones <rjones@redhat.com>:
On Mon, Sep 07, 2015 at 02:29:22PM +0200, Matthias Bolte wrote:
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.
Absolutely this would be brilliant.
Okay, here's patch that does this. It's only tested using the test suite, as I don't have an ESX setup at hand at the moment. Do you have the possibility to test this properly?
From 489e2d5dd29dd4b11716897ca52b14f6666ec141 Mon Sep 17 00:00:00 2001 From: Matthias Bolte <matthias.bolte@googlemail.com> Date: Fri, 11 Sep 2015 12:00:47 +0200 Subject: [PATCH] vmx: Expose datacenter path in domain XML
If you're happy with this patch, I'd like to push it to the libvirt repo. I didn't see any later version on the list. Let me know if this is the final version.
Also I have opened a BZ for the problem so the fix can be included in RHEL 7.3:
Regarding your question about the changes to the VMware driver: The only required change is the addition for "ctx.datacenterPath = NULL" where virVMXParseConfig is called. The other additions are not really necessary. I made them for the sake of completeness and to match the usage in the ESX driver.
Overall I'm happy with this patch. The only concern I have is that the domain XML might not be quite the right place to expose this information. But there are not many other places to expose this without adding new public API. But I assume that the domain XML is the most convenient was for libguestfs to get this information, isn't it?
We can get it from anywhere as long as it's in the XML. Let's wait for a second review, and if that is ACKed then I will push it. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org

On Fri, Sep 11, 2015 at 03:55:03PM +0200, Matthias Bolte wrote:
2015-09-07 22:04 GMT+02:00 Richard W.M. Jones <rjones@redhat.com>:
On Mon, Sep 07, 2015 at 02:29:22PM +0200, Matthias Bolte wrote:
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.
Absolutely this would be brilliant.
Okay, here's patch that does this. It's only tested using the test suite, as I don't have an ESX setup at hand at the moment. Do you have the possibility to test this properly?
-- Matthias Bolte http://photron.blogspot.com
From 489e2d5dd29dd4b11716897ca52b14f6666ec141 Mon Sep 17 00:00:00 2001 From: Matthias Bolte <matthias.bolte@googlemail.com> Date: Fri, 11 Sep 2015 12:00:47 +0200 Subject: [PATCH] vmx: Expose datacenter path in domain XML
Tool such as libguestfs need the datacenter path to get access to disk images. The ESX driver knows the correct datacenter path, but this information cannot be accessed using libvirt API yet. Also, it cannot be deduced from the connection URI in a robust way.
Expose the datacenter path in the domain XML as <vmware:datacenterpath> node similar to the way the <qemu:commandline> node works. The new node is ignored while parsing the domain XML. In contrast to <qemu:commandline> it is output only. --- src/esx/esx_driver.c | 4 ++ src/vmware/vmware_conf.c | 3 ++ src/vmware/vmware_driver.c | 9 ++++ src/vmx/vmx.c | 68 +++++++++++++++++++++++----- src/vmx/vmx.h | 10 ++-- tests/vmx2xmldata/vmx2xml-datacenterpath.vmx | 2 + tests/vmx2xmldata/vmx2xml-datacenterpath.xml | 19 ++++++++ tests/vmx2xmltest.c | 5 ++ tests/xml2vmxdata/xml2vmx-datacenterpath.vmx | 10 ++++ tests/xml2vmxdata/xml2vmx-datacenterpath.xml | 9 ++++ tests/xml2vmxtest.c | 3 ++ 11 files changed, 126 insertions(+), 16 deletions(-) create mode 100644 tests/vmx2xmldata/vmx2xml-datacenterpath.vmx create mode 100644 tests/vmx2xmldata/vmx2xml-datacenterpath.xml create mode 100644 tests/xml2vmxdata/xml2vmx-datacenterpath.vmx create mode 100644 tests/xml2vmxdata/xml2vmx-datacenterpath.xml
ACK, I think this is acceptable given the current requirements of libguestfs Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (3)
-
Daniel P. Berrange
-
Matthias Bolte
-
Richard W.M. Jones