Moin Moin,
nachdem ich bereits einiges mit AutoIT lösen konnte wollte ich nun mehr mit VMware (konkret ESX Host's) machen. Natürlich könnte ich die schon diversen Kommandozeilenbefehle wie z.B. "vmrun.exe" einfach fernsteuern - aber für kompliziertere Abfragen und Prüfungen taugt das nichts.
VMware stellt für alle Produkte die "VMware VIX API" zur Verfügung: http://www.vmware.com/support/developer/vix-api/
Die API stellt einige DLL Dateien zur Verfügung - und die Funktionen darin sind scheinbar gut Dokumentiert.
Ich habe versucht mir das ganze bei anderen UDF's ab zu schauen (GDIPlus z.B.) ... aber im Moment stürzt die AutoIT Engine beim Testen einfach ab ...
Was habe ich bisher gemacht:
- In der API ist eine "vix.dll" in der die Funktionen sind
- in der "vix.h" stehen die Aufrufe dazu
- die ganzen Konstanten aus der "vix.h" habe ich einfach übernommen:
vorher:
Spoiler anzeigen
typedef int VixServiceProvider;
enum {
VIX_SERVICEPROVIDER_DEFAULT = 1,
VIX_SERVICEPROVIDER_VMWARE_SERVER = 2,
VIX_SERVICEPROVIDER_VMWARE_WORKSTATION = 3,
VIX_SERVICEPROVIDER_VMWARE_PLAYER = 4,
VIX_SERVICEPROVIDER_VMWARE_VI_SERVER = 10,
};
nacher (also in AutoIT)
Spoiler anzeigen
;typedef int VixServiceProvider;
Dim Const $VIX_SERVICEPROVIDER_DEFAULT = 1
Dim Const $VIX_SERVICEPROVIDER_VMWARE_SERVER = 2
Dim Const $VIX_SERVICEPROVIDER_VMWARE_WORKSTATION = 3
Dim Const $VIX_SERVICEPROVIDER_VMWARE_PLAYER = 4
Dim Const $VIX_SERVICEPROVIDER_VMWARE_VI_SERVER = 10
Nun wollte ich die DLL Funktionen in eine AutoIT Funktion packen:
vorher:
Spoiler anzeigen
VixHandle VixHost_Connect(int apiVersion,
VixServiceProvider hostType,
const char *hostName,
int hostPort,
const char *userName,
const char *password,
VixHostOptions options,
VixHandle propertyListHandle,
VixEventProc *callbackProc,
void *clientData);
Die Beschreibung hierzu laut Hilfe:
Spoiler anzeigen
Parameters
apiVersion Must be VIX_API_VERSION.
hostType With vCenter Server, ESX/ESXi hosts, and VMware Server 2.0, use VIX_SERVICEPROVIDER_VMWARE_VI_SERVER.
With VMware Workstation, use VIX_SERVICEPROVIDER_VMWARE_WORKSTATION.
With VMware Player, use VIX_SERVICEPROVIDER_VMWARE_PLAYER.
With VMware Server 1.0.x, use VIX_SERVICEPROVIDER_VMWARE_SERVER.
hostName Varies by product platform.
With vCenter Server, ESX/ESXi hosts, and VMware Server 2.0, use a URL of the
form "https://<hostName>:<port>/sdk" where <hostName> is either the DNS name or IP address.
If missing, <port> may default to 443 (see Remarks below).
In VIX API 1.10 and later, you can omit "https://" and "/sdk" specifying just the DNS name or IP address.
Credentials are required even for connections made locally.
With Workstation, use NULL to connect to the local host.
With VMware Server 1.0.x, use the DNS name or IP address for remote connections, or the same as Workstation for local connections.
hostPort TCP/IP port on the remote host. With VMware Workstation and VMware Player, use zero for the local host.
With ESX/ESXi hosts and VMware Server 2.0 you specify port number within the hostName parameter, so this parameter is ignored (see Remarks below).
login Username for authentication on the remote machine. With VMware Workstation, VMware Player, and VMware Server 1.0.x, use NULL to authenticate as the current user on local host.
With vCenter Server, ESX/ESXi hosts, and VMware Server 2.0, you must use a valid login.
password Password for authentication on the remote machine. With VMware Workstation, VMware Player, and VMware Server 1.0.x, use NULL to authenticate as the current user on local host.
With ESX/ESXi and VMware Server 2.0, you must use a valid login.
options Should be zero. The option VIX_HOSTOPTION_USE_EVENT_PUMP has been deprecated and may be removed from future versions of the VIX API.
[/autoit] [autoit][/autoit] [autoit]propertyListHandle Must be VIX_INVALID_HANDLE.
[/autoit] [autoit][/autoit] [autoit]callbackProc Optional callback of type VixEventProc.
[/autoit] [autoit][/autoit] [autoit]clientData Optional user supplied opaque data to be passed to optional callback.
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Return Value A job handle. When the job completes, retrieve the Host handle from the job handle using the VIX_PROPERTY_JOB_RESULT_HANDLE property.
[/autoit]In einem Funktionsaufruf habe ich es so versucht: (2 Funktionen)
Spoiler anzeigen
Dim Const $VIX_PROPERTY_NONE = 0
Dim Const $VIX_API_VERSION = -1
Dim Const $VIX_INVALID_HANDLE = 0
Dim Const $VIX_PROPERTY_JOB_RESULT_HANDLE = 3010
Func _vmware_VixHost_Connect($hostType, $hostName, $hostPort, $userName, $password, $options)
Local $HostHandle = DllCall("vix.dll","INT_PTR","VixHost_Connect", "INT_PTR", $VIX_API_VERSION, "int", $hostType, "str", $hostName, "int", $hostPort, "str", $userName, "str", $password, "int", 0, "int", $VIX_INVALID_HANDLE, "int", 0, "int", 0)
If @error Then Return SetError(-65535)
Return SetExtended(0,$hostHandle)
EndFunc
Func _vmware_VixJob_Wait($jobHandle,$hostHandle)
Local $VixError = DllCall("vix.dll","INT_PTR","VixJob_Wait","INT_PTR",$jobHandle,"INT",$VIX_PROPERTY_JOB_RESULT_HANDLE,"INT_PTR",$hostHandle,"int",$VIX_PROPERTY_NONE)
If @error Then Return SetError(-65535)
Return SetExtended(0,$VixError)
EndFunc
Im Beispiel von denen sieht der Aufruf so aus:
Spoiler anzeigen
Example
#include "vix.h"
int main(int argc, char * argv[])
{
VixHandle hostHandle = VIX_INVALID_HANDLE;
VixHandle jobHandle = VIX_INVALID_HANDLE;
VixError err;
// Connect as current user on local host.
jobHandle = VixHost_Connect(VIX_API_VERSION,
VIX_SERVICEPROVIDER_VMWARE_VI_SERVER,
"https://viserver.example.com/sdk", // hostName
0, // hostPort
"Administrator", // userName
"adminpass", // password,
0, // options
VIX_INVALID_HANDLE, // propertyListHandle
NULL, // callbackProc
NULL); // clientData
err = VixJob_Wait(jobHandle,
VIX_PROPERTY_JOB_RESULT_HANDLE,
&hostHandle,
VIX_PROPERTY_NONE);
if (VIX_OK != err) {
// Handle the error...
goto abort;
}
Vix_ReleaseHandle(jobHandle);
// Other code goes here...
abort:
Vix_ReleaseHandle(jobHandle);
VixHost_Disconnect(hostHandle);
}
ich versuche nun es so:
Spoiler anzeigen
Dim $ESXHostHandle = $VIX_INVALID_HANDLE
Dim $ESXjobHandle = $VIX_INVALID_HANDLE
Dim $fehler
$ESXjobHandle = _vmware_VixHost_Connect($VIX_SERVICEPROVIDER_VMWARE_VI_SERVER, "https://vcenter.testdom.local/sdk", 443, "administrator", "passwort", 0)
$fehler = _vmware_VixJob_Wait($ESXjobHandle,$ESXHostHandle)
und scheitere nun .... ich bräuchte einfach mal einen Denkansatz oder einen Stoß in die richtige Richtung. Um C / C++ /C# hatte ich mich bisher immer gedrückt. Die API kann ich zwar auch mit VB nutzen - aber ich will nichts bauen was hinter her ein ganzes .NET Framework braucht.
Mit besten Dank im vorraus,
BLinz