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...
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.
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:
/* *********************************************************************
/* This demonstrates how to open a virtual machine,
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "vix.h"
/*
*
*/
/*
*/
#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\"."
/*
*/
static char *progName;
/*
*/
////////////////////////////////////////////////////////////////////////////////
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;
}
If i change the provider to VIX_SERVICEPROVIDER_VMWARE_WORKSTATION it works without error.
Hey VMware guys, this is a joke, isn't it???
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.
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.
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.
This document was generated from the following thread: VixJob_Wait() never returns after VixHost_Connect() with VMware Server 2 beta/beta2/RC1