All TKB Articles in VIX API

Hello, everybody      I am Chinese,English is not good,I use C# developers.           My code ---------------------------------------------------------------------------------------------------... See more...
Hello, everybody      I am Chinese,English is not good,I use C# developers.           My code ------------------------------------------------------------------------------------------------------------Start----          /// <summary>          ///  克隆虚拟机 · Clone vm          /// </summary>          /// <param name="ivm">虚拟机·vm</param>          /// <param name="Path"> vmx file Path</param>          /// <returns></returns>          public IVM Clone(IVM2 ivm, string Path)          {              IJob jobHandle = ivm.Clone(null, VixCOM.Constants.VIX_CLONETYPE_LINKED, Path, 0, null, null);              int[] lookForProperties = new int[1] { VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE };              object foundProperties = new object();              ulong vix_res = jobHandle.Wait(lookForProperties, ref foundProperties);              if (vixLib.ErrorIndicatesFailure(vix_res))              {                  return null;              }              object[] properties = (object[])foundProperties;              IVM vmHandle = (IVM)properties[0];              return vmHandle;          }          ------------------I call the          Clone(ivm,"[LS_2_DISK] 192.168.88.11/192.168.88.11.vmx")          My code ----------------------------------------------------------------------------------------------------------------end----       I execute the code Returns an error(6 – VIX_E_NOT_SUPPORTED The operation is not supported.)       Remark:api documentation say “VixCOM.h, since VMware Workstation 6.5 (not supported on VMware Server)”       I use vmware esxi, My IVM2.close() and IVM2.CreateSnapshot() is Success(ok).       Powerful heroes to help look             thank
Hi all, My C++ program was using VIX API 1.7 to access remote machine(ESX 4.0) from Windows PC. Recently I found VIX API 1.8.1 has been released and it is suppoting new function VixHost_O... See more...
Hi all, My C++ program was using VIX API 1.7 to access remote machine(ESX 4.0) from Windows PC. Recently I found VIX API 1.8.1 has been released and it is suppoting new function VixHost_OpenVM API instead of VixVM_Open API. So, I replaced VixVM_Open() to VixHost_OpenVM() and I compiled my program under VIX API 1.8.1 but the following link error occurred. error LNK2019: Undefined symbol VixHostOpenVM. For compile, I'm including Vix.lib of "C:\Program Files\VMware\VMware VIX\VSphere-4.0\32bit" folder. Could anyone advise me? Shigemi,
I have a question how a remote program can monitor VM is normally running or not on VMware. My environment is VMware ESX 4.0 and VIX API 1.7. My C++ program can successfully access VMware... See more...
I have a question how a remote program can monitor VM is normally running or not on VMware. My environment is VMware ESX 4.0 and VIX API 1.7. My C++ program can successfully access VMware from remote workstation, monitor power state of VM, power on or shutdown VM. And I want to monitor VM health state in order to confirm VM is normally running, that is power state of VM is running and also VM is not in hang condition. In case of Hyper-V of Microsoft, VM object, Msvm_ComputerSystem, has HealthState and OperationStatus properties. So it is possible to monitor VM is normally running by periodically monitoring those properties, I think. In case of VMware, VM object has not such a property. So if anyone has an idea to know health state of VM, please let me know. I have an idea to confirm VM health by periodically writing and reading variable to VM as follows, but I don't know this is effective or not. ############################################################################ BOOL writeReadPropertiesToVM(VixHandle vmHandle, BOOL* vmOK) { BOOL status = FALSE; VixError err = VIX_OK; VixHandle jobHandle = VIX_INVALID_HANDLE; char *readValue = NULL; jobHandle = VixVM_WriteVariable(vmHandle, VIX_VM_GUEST_VARIABLE, "myTestVariable", "newValue", 0, // options NULL, // callbackProc NULL); // clientData); err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE); if (VIX_OK != err) { // Handle the error... const char* errorString = Vix_GetErrorText(err, NULL); printf("VixVM_WriteVariable, status = 0x0%x(%s).\n", err, errorString); goto abort; } printf("VixVM_WriteVariable succeeded.n"); jobHandle = VixVM_ReadVariable(vmHandle, VIX_VM_GUEST_VARIABLE, "myTestVariable", 0, // options NULL, // callbackProc NULL); // clientData); err = VixJob_Wait(jobHandle, VIX_PROPERTY_JOB_RESULT_VM_VARIABLE_STRING, &readValue, VIX_PROPERTY_NONE); if (VIX_OK != err) { // Handle the error... const char* errorString = Vix_GetErrorText(err, NULL); printf("VixVM_ReadVariable, status = 0x0%x(%s).\n", err, errorString); goto abort; } printf("VixVM_ReadVariable succeeded.\n"); *vmOK = TRUE; status = TRUE; abort: Vix_FreeBuffer(readValue); Vix_ReleaseHandle(jobHandle); return status; } Thanks and regards, Shigemi
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 eve... See more...
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: /* ********************************************************************* 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; } 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
ID: LAB07 Session: VIX Programming to Automate Virtual Machine Operations Presenter: VMware The VIX Programming Lab for VMware Workstation and VMware Server will detail techniques for automa... See more...
ID: LAB07 Session: VIX Programming to Automate Virtual Machine Operations Presenter: VMware The VIX Programming Lab for VMware Workstation and VMware Server will detail techniques for automating common virtual machines operations in test and development environments including power state, snapshots, file copy and command execution. A logical series of hands-on programming exercises reinforces concepts presented in short lectures. The session will progress through overview, installation, common operations in test / development and advanced concepts in the VIX API. Participants should be familiar with batch scripting, Perl, Visual Basic or C. The instructor presentation, student lab manual and the completed code examples are included in the zip archive. Note: For the C examples on Windows, please statically link with the following libraries: kernel32.lib VixAllProducts.lib (or VixAllProductsd.lib for debug) user32.lib ws2_32.lib advapi32.lib Exercise 1 - Find Running VMs using vmrun, Perl and C This example shows how easy it is to list and count the running VMs on Workstation 6 using the vmrun command line as well introduce the concepts of establishing a host connection, error checking and retrieving a list of running virtual machines. Please see FindRunningVMs.bat, FindRunningVMs.pl and FindRunningVMs.cpp Exercise 2 - Common Operations These examples show how to affect power state changes, snapshots, file copies and command execution using vmrun, Perl, VBscript and C. For VM power operations, please see Power.bat, Power.pl, Power.cpp and Power.vbs. For snapshot operations, please see Snapshot.bat, Snapshot.pl, Snapshot.cpp and Snapshot.vbs For file copy and command execution, please see UpdateBuild.bat, UpdateBuild.pl, UpdateBuild.cpp and UpdateBuild.vbs Exercise 3 - Virtual Debugger This lab demonstrated the VIX virtual integrated debugger using a simple C++ program with VisualStudio 2005. Please see the IDE Demo project. This project is included for completeness only as it contains no VIX code. Exercise 4 - Advanced Concepts This example shows how to start and restart FreeCell in a virtual machine using vmrun, Perl, C and VBscript. FreeCell will restart if the user exits the game and the VM will power on if powered off. FreeCell starts again as soon as the user is logged in. Please use control C to stop the program. Please see MonitorGuest.bat, MonitorGuest.pl, MonitorGuest.cpp and MonitorGuest.vbs