VMware {code} Community
Fozzi
Enthusiast
Enthusiast

VixJob_Wait() never returns after VixHost_Connect() with VMware Server 2 beta/beta2/RC1

I have programmed a Windows service to automate backups for our VMware GSX, VMware Server 1.x Hosts. Since VMware Server beta is available i tried to do the same with the new version, but i even can't connect to the host. The program is written in Power Basic, the vix.h is translated to an include file. It all works with VMware Server 1.0.x, but VMware Server 2 released new DLL's for the clients. After exchanging the DLL's the program hooks up with call VixJob_Wait(), though calling conventions (according to documentation) didn't change since VMware Server 1.x.

Here is a part of the code:

LOCAL VErr AS QUAD

LOCAL jobHandle AS DWORD

LOCAL vmHandle AS DWORD

LOCAL hostHandle AS DWORD

LOCAL lState AS LONG

jobHandle = VixHost_Connect(%VIX_API_VERSION, _

%VIX_SERVICEPROVIDER_VMWARE_SERVER, _

BYVAL 0, _ 'host

0, _ 'port

BYVAL 0, _ 'user

BYVAL 0, _ 'password

0, _ 'options

%VIX_INVALID_HANDLE, _ 'propertyListHandle,

BYVAL 0, _ 'callbackProc

BYVAL 0) 'clientData

VErr = VixJob_Wait(jobHandle, _

%VIX_PROPERTY_JOB_RESULT_HANDLE, _

hostHandle, _

%VIX_PROPERTY_NONE)

IF VErr = %VIX_OK THEN

.....program continues here with normal operation

Except of the variable definition you can treat the code like C.

The program gets a jobhandle (=63) but not host handle, VixJob_Wait does not return, no value calculated for VErr...

0 Kudos
11 Replies
lemke
VMware Employee
VMware Employee

You need to modify your VixHost_Connect() parameters to work with Server 2.

http://vmware.com/products/beta/vmware_server/vix_api/ReferenceGuide/ has the updated documentation.

There may be other issues if you're directly linking to libvix.dll instead of using vixAllProducts.lib.

Fozzi
Enthusiast
Enthusiast

Thanks for your answer. I tried a little with the calling parameters, but it's still the same: VixHost_Connect() delivers value=63 (looks OK for me), VixHost_Disconnect() is also working, hook-up with VixJob_Wait()

lVersion= %VIX_API_VERSION

vmHost = "[https://localhost:8333/sdk/]"

vmUser = "Administrator"

vmPass = "mypass"

PBOUT "connecting to: "vmHost" API:"+STR$(lVersion)

jobHandle = VixHost_Connect(lVersion, _

%VIX_SERVICEPROVIDER_VMWARE_SERVER, _

vmHost, 0, vmUser, vmPass, 0, _ 'host,user,password,options

%VIX_INVALID_HANDLE, _ 'propertyListHandle,

BYVAL 0, _ 'callbackProc

BYVAL 0) 'clientData

PBOut "disconnecting..., jobHandle:"+STR$(jobHandle)

WAITKEY$

VixHost_Disconnect( jobHandle )

pbout "waiting..., jobHandle:"+STR$(jobHandle)

VErr = VixJob_Wait( jobHandle, _

%VIX_PROPERTY_JOB_RESULT_HANDLE, _

hostHandle, %VIX_PROPERTY_NONE)

Besides: i tried the PowerOn.c example with VisualStudio 2005, static linking VixAllProducts.lib, compiles and links without any error. After starting/debugging it hooks-up after VixHost_Connect(). Here is the code:

/* *********************************************************************

  • Copyright (c) 2007 VMware, Inc.

  • All rights not expressly granted to you by VMware, Inc. are reserved.

  • *********************************************************************/

/* This demonstrates how to open a virtual machine,

  • power it on, and power it off.

*

  • This uses the VixJob_Wait function to block after starting each

  • asynchronous function. This effectively makes the asynchronous

  • functions synchronous, because VixJob_Wait will not return until the

  • asynchronous function has completed.

*/

#include <stdio.h>

#include <stdlib.h>

#include "vix.h"

/*

  • Certain arguments differ when using VIX with VMware Server 2.0

  • and VMware Workstation.

*

  • Comment out this definition to use this code with VMware Server 2.0.

*/

/*

  • For VMware Server 2.0

*/

#define CONNTYPE VIX_SERVICEPROVIDER_VMWARE_SERVER

/*#define HOSTNAME "[https://localhost:8333/ui]"

#define HOSTPORT 0

#define USERNAME "Administrator"

#define PASSWORD "mypass"*/

#define HOSTNAME ""

#define HOSTPORT 0

#define USERNAME ""

#define PASSWORD ""

#define VMPOWEROPTIONS VIX_VMPOWEROP_NORMAL

#define VMXPATH_INFO "where vmxpath is a datastore-relative path to the " \

".vmx file for the virtual machine, such as " \

"\"[standard] ubuntu/ubuntu.vmx\"."

/*

  • Global variables.

*/

static char *progName;

/*

  • Local functions.

*/

////////////////////////////////////////////////////////////////////////////////

static void

usage()

{

fprintf(stderr, "Usage: %s <vmxpath>\n", progName);

fprintf(stderr, "%s\n", VMXPATH_INFO);

}

////////////////////////////////////////////////////////////////////////////////

int

main(int argc, char **argv)

{

VixError err;

char *vmxPath;

VixHandle hostHandle = VIX_INVALID_HANDLE;

VixHandle jobHandle = VIX_INVALID_HANDLE;

VixHandle vmHandle = VIX_INVALID_HANDLE;

progName = argv[0];

if (argc > 1) {

vmxPath = argv[1];

} else {

usage();

exit(EXIT_FAILURE);

}

fprintf(stderr, "connect to host:%s\n", HOSTNAME);

jobHandle = VixHost_Connect(VIX_API_VERSION,

CONNTYPE,

HOSTNAME, // *hostName,

HOSTPORT, // hostPort,

USERNAME, // *userName,

PASSWORD, // *password,

0, // options,

VIX_INVALID_HANDLE, // propertyListHandle,

NULL, // *callbackProc,

NULL); // *clientData);

fprintf(stderr, "wait...\n");

err = VixJob_Wait(jobHandle,

VIX_PROPERTY_JOB_RESULT_HANDLE,

&hostHandle,

VIX_PROPERTY_NONE);

if (VIX_FAILED(err)) {

fprintf(stderr, "can't connect: %s\n", vmxPath);

goto abort;

}

Vix_ReleaseHandle(jobHandle);

jobHandle = VixVM_Open(hostHandle,

vmxPath,

NULL, // VixEventProc *callbackProc,

NULL); // void *clientData);

err = VixJob_Wait(jobHandle,

VIX_PROPERTY_JOB_RESULT_HANDLE,

&vmHandle,

VIX_PROPERTY_NONE);

if (VIX_FAILED(err)) {

goto abort;

}

Vix_ReleaseHandle(jobHandle);

jobHandle = VixVM_PowerOn(vmHandle,

VMPOWEROPTIONS,

VIX_INVALID_HANDLE,

NULL, // *callbackProc,

NULL); // *clientData);

err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);

if (VIX_FAILED(err)) {

goto abort;

}

Vix_ReleaseHandle(jobHandle);

jobHandle = VixVM_PowerOff(vmHandle,

VIX_VMPOWEROP_NORMAL,

NULL, // *callbackProc,

NULL); // *clientData);

err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);

if (VIX_FAILED(err)) {

goto abort;

}

abort:

Vix_ReleaseHandle(jobHandle);

Vix_ReleaseHandle(vmHandle);

VixHost_Disconnect(hostHandle);

return 0;

}

0 Kudos
Fozzi
Enthusiast
Enthusiast

If i change the provider to VIX_SERVICEPROVIDER_VMWARE_WORKSTATION it works without error.

Hey VMware guys, this is a joke, isn't it???

0 Kudos
lemke
VMware Employee
VMware Employee

For Server 2.0, you need to use the hostType VIX_SERVICEPROVIDER_VMWARE_VI_SERVER. The currently posted docs are too vague on that, but its been fixed for the next beta cycle.

And it works fine with WORKSTATION because all its doing in that case is initializing the API. For remote cases we need to connect to the services, but WORKSTATION is local.

Fozzi
Enthusiast
Enthusiast

I'll get connected with WORKSTATION, but if a guest ist started by my program i can't access it through WebUI. I think this is, what you meant.

I tried VI_SERVER also, but got many errors, looked like XML code.

0 Kudos
Fozzi
Enthusiast
Enthusiast

Connecting with VIX_SERVICEPROVIDER_VMWARE_VI_SERVER connects to the host, but the following VixJob_Wait() does not deliver a hosthandle (=0).

host, user, password and port are set to NUL, because local connect, but i think the VI_SERVER needs more.

0 Kudos
Fozzi
Enthusiast
Enthusiast

Got the connect to the VMware Server 2 RC1 now as VI_SERVER, changed the parameters to:

Provider= %VIX_SERVICEPROVIDER_VMWARE_VI_SERVER

vmHost = "https://localhost:8333/sdk"

vmUser = "Administrator"

vmPass = "mypassword"

Now trying to open an existing machine (connect as WORKSTATION => OK) with

jobHandle = VixVM_Open(hostHandle, _

vmPath, _ 'enter your path to the desired vm

BYVAL 0, _ 'callbackProc

BYVAL 0)

Received error 4000 (The virtual machine cannot be found). If i lookup with the WebUI, i'll get an error for "Find Virtual Machine by Datastore Path".

0 Kudos
lemke
VMware Employee
VMware Employee

Connecting with VIX_SERVICEPROVIDER_VMWARE_VI_SERVER connects to the host, but the following VixJob_Wait() does not deliver a hosthandle (=0).

host, user, password and port are set to NUL, because local connect, but i think the VI_SERVER needs more.

Yes, username and password are required for Server 2.

0 Kudos
lemke
VMware Employee
VMware Employee

Got the connect to the VMware Server 2 RC1 now as VI_SERVER, changed the parameters to:

Provider= %VIX_SERVICEPROVIDER_VMWARE_VI_SERVER

vmHost = "https://localhost:8333/sdk"

vmUser = "Administrator"

vmPass = "mypassword"

Now trying to open an existing machine (connect as WORKSTATION => OK) with

jobHandle = VixVM_Open(hostHandle, _

vmPath, _ 'enter your path to the desired vm

BYVAL 0, _ 'callbackProc

BYVAL 0)

Received error 4000 (The virtual machine cannot be found). If i lookup with the WebUI, i'll get an error for "Find Virtual Machine by Datastore Path".

Has the VM been registered? Are you using Server 2 style datastores for the path name, eg storage1 path/to/my.vmx ?

0 Kudos
lemke
VMware Employee
VMware Employee

Connecting with VIX_SERVICEPROVIDER_VMWARE_VI_SERVER connects to the host, but the following VixJob_Wait() does not deliver a hosthandle (=0).

host, user, password and port are set to NUL, because local connect, but i think the VI_SERVER needs more.

You can init the API with WORKSTATION mode, but that means you're not talking to the instance of Server, so its probably not what you want.

0 Kudos
Fozzi
Enthusiast
Enthusiast

With the release version of VMware Server 2 this code (part of it, which is of interest) works well:

Provider= %VIX_SERVICEPROVIDER_VMWARE_VI_SERVER

vmHost = "http://localhost:8222/sdk"

vmUser = "Administrator"

vmPass = "Kallisto.2000"

vmPath = "K:\VMmachines\Win2000\Win2000.VMX"

lVersion= %VIX_API_VERSION

vmPort = 0

IF LEN( vmHost )>0 THEN

PBOUT "connecting to: "vmHost" API:"STR$(lVersion)" provider:"+STR$(Provider)

ELSE

PBOut "connecting to local host, API:"STR$(lVersion)" provider:"+STR$(Provider)

END IF

jobHandle = VixHost_Connect(lVersion, Provider, _

vmHost, vmPort, vmUser, vmPass, vmOptions, _ 'host,user,password,options

%VIX_INVALID_HANDLE, _ 'propertyListHandle,

BYVAL 0, _ 'callbackProc

BYVAL 0) 'clientData

pbout "waiting..., jobHandle:"+STR$(jobHandle)

VErr = VixJob_Wait( jobHandle, %VIX_PROPERTY_JOB_RESULT_HANDLE, hostHandle, %VIX_PROPERTY_NONE )

PBOut "HostHandle="STR$(hostHandle)" VErr="STR$(VErr)"("STR$(%VIX_OK)")"

Vix_ReleaseHandle(jobHandle)

0 Kudos