[libvirt] [PATCH 1/2] VMware: Support more than 2 driver backends

Currently the VMware version check code only supports two types of VMware backends, Workstation and Player. But in the near future we will have an additional one so we need to support more. Additionally, we discover and cache the path to the vmrun binary so we should use that path when using the cooresponding binary from the VMware VIX SDK. --- src/vmware/vmware_conf.c | 23 ++++++++++++++++++++--- src/vmware/vmware_driver.c | 20 ++++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 261a4f6..d7ea8c4 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -257,10 +257,25 @@ vmwareExtractVersion(struct vmware_driver *driver) { unsigned long version = 0; int ret = -1; - virCommandPtr cmd; + virCommandPtr cmd = NULL; char * outbuf = NULL; - const char * bin = (driver->type == VMWARE_DRIVER_PLAYER) ? - "vmplayer" : "vmware"; + char *bin = NULL; + char *vmwarePath = NULL; + + if ((vmwarePath = mdir_name(driver->vmrun)) == NULL) + goto cleanup; + + switch (driver->type) { + case VMWARE_DRIVER_PLAYER: + if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmplayer")) + goto cleanup; + break; + + case VMWARE_DRIVER_WORKSTATION: + if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmware")) + goto cleanup; + break; + } cmd = virCommandNewArgList(bin, "-v", NULL); virCommandSetOutputBuffer(cmd, &outbuf); @@ -276,6 +291,8 @@ vmwareExtractVersion(struct vmware_driver *driver) cleanup: virCommandFree(cmd); VIR_FREE(outbuf); + VIR_FREE(bin); + VIR_FREE(vmwarePath); return ret; } diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 4e56971..01d65ed 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -93,6 +93,7 @@ vmwareConnectOpen(virConnectPtr conn, { struct vmware_driver *driver; size_t i; + char *tmp; virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); @@ -144,8 +145,23 @@ vmwareConnectOpen(virConnectPtr conn, if (virMutexInit(&driver->lock) < 0) goto cleanup; - driver->type = STRNEQ(conn->uri->scheme, "vmwareplayer") ? - VMWARE_DRIVER_WORKSTATION : VMWARE_DRIVER_PLAYER; + if ((tmp = STRSKIP(conn->uri->scheme, "vmware")) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to parse URI " + "scheme '%s'"), conn->uri->scheme); + goto cleanup; + } + + driver->type = -1; + for (i = 0; i < VMWARE_DRIVER_LAST; i++) { + if (STREQ(tmp, vmwareDriverTypeToString(i))) + driver->type = i; + } + + if (driver->type == -1) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to find valid " + "requested VMware backend '%s'"), tmp); + goto cleanup; + } if (!(driver->domains = virDomainObjListNew())) goto cleanup; -- 1.8.1.5

Add support for VMware Fusion in the existing VMware driver. Connect via the URI vmwarefusion:///session --- docs/drvvmware.html.in | 15 +++++++++++---- src/vmware/vmware_conf.c | 8 +++++++- src/vmware/vmware_conf.h | 1 + src/vmware/vmware_driver.c | 3 +++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/docs/drvvmware.html.in b/docs/drvvmware.html.in index 9ee0ebd..240afd0 100644 --- a/docs/drvvmware.html.in +++ b/docs/drvvmware.html.in @@ -2,10 +2,11 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <body> - <h1>VMware Workstation / Player hypervisors driver</h1> + <h1>VMware Workstation / Player / Fusion hypervisors driver</h1> <p> - The libvirt VMware Workstation driver should be able to manage any Workstation and - Player version supported by the VMware VIX API. See the compatibility list + The libvirt VMware driver should be able to manage any Workstation, + Player, Fusion version supported by the VMware VIX API. See the + compatibility list <a href="http://www.vmware.com/support/developer/vix-api/vix110_reference/">here</a>. </p> <p> @@ -21,17 +22,22 @@ The <a href="http://www.vmware.com/">VMware Workstation and Player</a> hypervisors </li> + <li> + The <a href="http://www.vmware.com/fusion">VMware Fusion</a> + hypervisor + </li> </ul> <h2>Connections to VMware driver</h2> <p> The libvirt VMware driver provides per-user drivers (the "session" instance). - Two uris are available: + Three uris are available: </p> <ul> <li>"vmwareplayer" for VMware Player</li> <li>"vmwarews" for VMware Workstation</li> + <li>"vmwarefusion" for VMware Fusion</li> </ul> <p> Some example connection URIs for the driver are: @@ -40,6 +46,7 @@ <pre> vmwareplayer:///session (local access to VMware Player per-user instance) vmwarews:///session (local access to VMware Workstation per-user instance) +vmwarefusion:///session (local access to VMware Fusion per-user instance) vmwarews+tcp://user@example.com/session (remote access to VMware Workstation, SASl/Kerberos) vmwarews+ssh://user@example.com/session (remote access to VMware Workstation, SSH tunnelled) </pre> diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index d7ea8c4..6d5b11b 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -37,7 +37,8 @@ VIR_ENUM_IMPL(vmwareDriver, VMWARE_DRIVER_LAST, "player", - "ws"); + "ws", + "fusion"); /* Free all memory associated with a vmware_driver structure */ void @@ -275,6 +276,11 @@ vmwareExtractVersion(struct vmware_driver *driver) if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmware")) goto cleanup; break; + + case VMWARE_DRIVER_FUSION: + if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmware-vmx")) + goto cleanup; + break; } cmd = virCommandNewArgList(bin, "-v", NULL); diff --git a/src/vmware/vmware_conf.h b/src/vmware/vmware_conf.h index a4fd855..b9fca6c 100644 --- a/src/vmware/vmware_conf.h +++ b/src/vmware/vmware_conf.h @@ -33,6 +33,7 @@ enum vmwareDriverType { VMWARE_DRIVER_PLAYER = 0, /* VMware Player */ VMWARE_DRIVER_WORKSTATION = 1, /* VMware Workstation */ + VMWARE_DRIVER_FUSION = 2, /* VMware Fusion */ VMWARE_DRIVER_LAST, /* required last item */ }; diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 01d65ed..abedacf 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -40,6 +40,8 @@ */ static const char * const vmrun_candidates[] = { "vmrun", + "/Applications/VMware Fusion.app/Contents/Library/vmrun", + "/Library/Application Support/VMware Fusion/vmrun", }; static void @@ -103,6 +105,7 @@ vmwareConnectOpen(virConnectPtr conn, } else { if (conn->uri->scheme == NULL || (STRNEQ(conn->uri->scheme, "vmwareplayer") && + STRNEQ(conn->uri->scheme, "vmwarefusion") && STRNEQ(conn->uri->scheme, "vmwarews"))) return VIR_DRV_OPEN_DECLINED; -- 1.8.1.5

On Fri, Sep 20, 2013 at 03:06:51PM -0500, Doug Goldstein wrote:
Add support for VMware Fusion in the existing VMware driver. Connect via the URI vmwarefusion:///session --- docs/drvvmware.html.in | 15 +++++++++++---- src/vmware/vmware_conf.c | 8 +++++++- src/vmware/vmware_conf.h | 1 + src/vmware/vmware_driver.c | 3 +++ 4 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/docs/drvvmware.html.in b/docs/drvvmware.html.in index 9ee0ebd..240afd0 100644 --- a/docs/drvvmware.html.in +++ b/docs/drvvmware.html.in @@ -2,10 +2,11 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <body> - <h1>VMware Workstation / Player hypervisors driver</h1> + <h1>VMware Workstation / Player / Fusion hypervisors driver</h1> <p> - The libvirt VMware Workstation driver should be able to manage any Workstation and - Player version supported by the VMware VIX API. See the compatibility list + The libvirt VMware driver should be able to manage any Workstation, + Player, Fusion version supported by the VMware VIX API. See the + compatibility list <a href="http://www.vmware.com/support/developer/vix-api/vix110_reference/">here</a>. </p> <p> @@ -21,17 +22,22 @@ The <a href="http://www.vmware.com/">VMware Workstation and Player</a> hypervisors </li> + <li> + The <a href="http://www.vmware.com/fusion">VMware Fusion</a> + hypervisor + </li> </ul>
<h2>Connections to VMware driver</h2>
<p> The libvirt VMware driver provides per-user drivers (the "session" instance). - Two uris are available: + Three uris are available: </p> <ul> <li>"vmwareplayer" for VMware Player</li> <li>"vmwarews" for VMware Workstation</li> + <li>"vmwarefusion" for VMware Fusion</li> </ul> <p> Some example connection URIs for the driver are: @@ -40,6 +46,7 @@ <pre> vmwareplayer:///session (local access to VMware Player per-user instance) vmwarews:///session (local access to VMware Workstation per-user instance) +vmwarefusion:///session (local access to VMware Fusion per-user instance) vmwarews+tcp://user@example.com/session (remote access to VMware Workstation, SASl/Kerberos) vmwarews+ssh://user@example.com/session (remote access to VMware Workstation, SSH tunnelled) </pre> diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index d7ea8c4..6d5b11b 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -37,7 +37,8 @@
VIR_ENUM_IMPL(vmwareDriver, VMWARE_DRIVER_LAST, "player", - "ws"); + "ws", + "fusion");
/* Free all memory associated with a vmware_driver structure */ void @@ -275,6 +276,11 @@ vmwareExtractVersion(struct vmware_driver *driver) if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmware")) goto cleanup; break; + + case VMWARE_DRIVER_FUSION: + if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmware-vmx")) + goto cleanup; + break; }
cmd = virCommandNewArgList(bin, "-v", NULL); diff --git a/src/vmware/vmware_conf.h b/src/vmware/vmware_conf.h index a4fd855..b9fca6c 100644 --- a/src/vmware/vmware_conf.h +++ b/src/vmware/vmware_conf.h @@ -33,6 +33,7 @@ enum vmwareDriverType { VMWARE_DRIVER_PLAYER = 0, /* VMware Player */ VMWARE_DRIVER_WORKSTATION = 1, /* VMware Workstation */ + VMWARE_DRIVER_FUSION = 2, /* VMware Fusion */
VMWARE_DRIVER_LAST, /* required last item */ }; diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 01d65ed..abedacf 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -40,6 +40,8 @@ */ static const char * const vmrun_candidates[] = { "vmrun", + "/Applications/VMware Fusion.app/Contents/Library/vmrun", + "/Library/Application Support/VMware Fusion/vmrun", };
Are these two paths standard on OS-X, or is this just a default that is user customizable ? They don't add these dirs to $PATH ? Should we surround these in #if OSX (or whatever the right symbol is) ?
static void @@ -103,6 +105,7 @@ vmwareConnectOpen(virConnectPtr conn, } else { if (conn->uri->scheme == NULL || (STRNEQ(conn->uri->scheme, "vmwareplayer") && + STRNEQ(conn->uri->scheme, "vmwarefusion") && STRNEQ(conn->uri->scheme, "vmwarews"))) return VIR_DRV_OPEN_DECLINED;
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 :|

On Mon, Sep 23, 2013 at 5:28 AM, Daniel P. Berrange <berrange@redhat.com> wrote:
On Fri, Sep 20, 2013 at 03:06:51PM -0500, Doug Goldstein wrote:
Add support for VMware Fusion in the existing VMware driver. Connect via the URI vmwarefusion:///session --- docs/drvvmware.html.in | 15 +++++++++++---- src/vmware/vmware_conf.c | 8 +++++++- src/vmware/vmware_conf.h | 1 + src/vmware/vmware_driver.c | 3 +++ 4 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/docs/drvvmware.html.in b/docs/drvvmware.html.in index 9ee0ebd..240afd0 100644 --- a/docs/drvvmware.html.in +++ b/docs/drvvmware.html.in @@ -2,10 +2,11 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <body> - <h1>VMware Workstation / Player hypervisors driver</h1> + <h1>VMware Workstation / Player / Fusion hypervisors driver</h1> <p> - The libvirt VMware Workstation driver should be able to manage any Workstation and - Player version supported by the VMware VIX API. See the compatibility list + The libvirt VMware driver should be able to manage any Workstation, + Player, Fusion version supported by the VMware VIX API. See the + compatibility list <a href="http://www.vmware.com/support/developer/vix-api/vix110_reference/">here</a>. </p> <p> @@ -21,17 +22,22 @@ The <a href="http://www.vmware.com/">VMware Workstation and Player</a> hypervisors </li> + <li> + The <a href="http://www.vmware.com/fusion">VMware Fusion</a> + hypervisor + </li> </ul>
<h2>Connections to VMware driver</h2>
<p> The libvirt VMware driver provides per-user drivers (the "session" instance). - Two uris are available: + Three uris are available: </p> <ul> <li>"vmwareplayer" for VMware Player</li> <li>"vmwarews" for VMware Workstation</li> + <li>"vmwarefusion" for VMware Fusion</li> </ul> <p> Some example connection URIs for the driver are: @@ -40,6 +46,7 @@ <pre> vmwareplayer:///session (local access to VMware Player per-user instance) vmwarews:///session (local access to VMware Workstation per-user instance) +vmwarefusion:///session (local access to VMware Fusion per-user instance) vmwarews+tcp://user@example.com/session (remote access to VMware Workstation, SASl/Kerberos) vmwarews+ssh://user@example.com/session (remote access to VMware Workstation, SSH tunnelled) </pre> diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index d7ea8c4..6d5b11b 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -37,7 +37,8 @@
VIR_ENUM_IMPL(vmwareDriver, VMWARE_DRIVER_LAST, "player", - "ws"); + "ws", + "fusion");
/* Free all memory associated with a vmware_driver structure */ void @@ -275,6 +276,11 @@ vmwareExtractVersion(struct vmware_driver *driver) if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmware")) goto cleanup; break; + + case VMWARE_DRIVER_FUSION: + if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmware-vmx")) + goto cleanup; + break; }
cmd = virCommandNewArgList(bin, "-v", NULL); diff --git a/src/vmware/vmware_conf.h b/src/vmware/vmware_conf.h index a4fd855..b9fca6c 100644 --- a/src/vmware/vmware_conf.h +++ b/src/vmware/vmware_conf.h @@ -33,6 +33,7 @@ enum vmwareDriverType { VMWARE_DRIVER_PLAYER = 0, /* VMware Player */ VMWARE_DRIVER_WORKSTATION = 1, /* VMware Workstation */ + VMWARE_DRIVER_FUSION = 2, /* VMware Fusion */
VMWARE_DRIVER_LAST, /* required last item */ }; diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 01d65ed..abedacf 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -40,6 +40,8 @@ */ static const char * const vmrun_candidates[] = { "vmrun", + "/Applications/VMware Fusion.app/Contents/Library/vmrun", + "/Library/Application Support/VMware Fusion/vmrun", };
Are these two paths standard on OS-X, or is this just a default that is user customizable ? They don't add these dirs to $PATH ?
They're hardcoded in the VMware Fusion installer so its only ever possible to install to those two paths. Version 4 and lower used the path /Library/Application Support/ for the command line tools while version 5 and newer used /Applications VMware Fusion.app/ No they don't add anything in /Library or /Applications to PATH. Its actually frowned upon in Mac world.
Should we surround these in #if OSX (or whatever the right symbol is) ?
Sure I can do that.
static void @@ -103,6 +105,7 @@ vmwareConnectOpen(virConnectPtr conn, } else { if (conn->uri->scheme == NULL || (STRNEQ(conn->uri->scheme, "vmwareplayer") && + STRNEQ(conn->uri->scheme, "vmwarefusion") && STRNEQ(conn->uri->scheme, "vmwarews"))) return VIR_DRV_OPEN_DECLINED;
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 :|
-- Doug Goldstein

On Fri, Sep 20, 2013 at 03:06:50PM -0500, Doug Goldstein wrote:
Currently the VMware version check code only supports two types of VMware backends, Workstation and Player. But in the near future we will have an additional one so we need to support more. Additionally, we discover and cache the path to the vmrun binary so we should use that path when using the cooresponding binary from the VMware VIX SDK. --- src/vmware/vmware_conf.c | 23 ++++++++++++++++++++--- src/vmware/vmware_driver.c | 20 ++++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 261a4f6..d7ea8c4 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -257,10 +257,25 @@ vmwareExtractVersion(struct vmware_driver *driver) { unsigned long version = 0; int ret = -1; - virCommandPtr cmd; + virCommandPtr cmd = NULL; char * outbuf = NULL; - const char * bin = (driver->type == VMWARE_DRIVER_PLAYER) ? - "vmplayer" : "vmware"; + char *bin = NULL; + char *vmwarePath = NULL; + + if ((vmwarePath = mdir_name(driver->vmrun)) == NULL) + goto cleanup; + + switch (driver->type) { + case VMWARE_DRIVER_PLAYER: + if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmplayer")) + goto cleanup; + break; + + case VMWARE_DRIVER_WORKSTATION: + if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmware")) + goto cleanup; + break; + }
I think we should have a 'default' in here, otherwise we could end up passing 'NULL' for the 'bin' parameter below in the future.
cmd = virCommandNewArgList(bin, "-v", NULL); virCommandSetOutputBuffer(cmd, &outbuf); @@ -276,6 +291,8 @@ vmwareExtractVersion(struct vmware_driver *driver) cleanup: virCommandFree(cmd); VIR_FREE(outbuf); + VIR_FREE(bin); + VIR_FREE(vmwarePath); return ret; }
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 (2)
-
Daniel P. Berrange
-
Doug Goldstein