Good job! I have also written a wrapper for Vix API, but not nearly as thorough as yours.
Daniel, great stuff, I've posted an example of using it from PowerShell.
I noticed one strange thing, when I ran notepad like in your example it didn't return until I killed the process. Is that a VIX-side thing or something in your library?
Thanks! The library is synchronous, so Execute runs notepad and returns only when it's done. My example might have been not so clever - if you run a GUI application without a remote desktop you're not going to be able to do much
dB - Thanks for this. It is going to make using VIX a lot easier now. I was able to use it against Workstation on my machine and a remote Server 2.0 machine. I tried it against ESXi 3.5, but was unable to connect. I think it has to do with the ESX server not being at 3.5 U3 per the VIX documents, so I will have to wait and see.
Carter - Thanks for the PowerShell example. I usually try to keep all of my programming inside of PowerShell and you gave me a good start.
It should work against U2 and up, I'm not sure if the notes say U3.
Anyway, VIX will connect even against ESX 3.0, it's just that nothing you do after that will actually work. Make sure you're connecting to https://server/sdk rather than just the server name or IP.
Here is the code block I am using that works for server 2.0. I am able to connect to the ESXi 3.5 server via VI API and PowerShell, but not with VIX
add-type -path " Vestris.VMWareLib.dll"
add-type -path “Interop.VixCOM.dll"
$myHost= new-object vestris.vmwarelib.vmwarevirtualhost
$myHost.ConnectToVMWareVIServer("https://<IP>/sdk",0, “<login>”, “<pw>”)
$vm = $myHost.Open(<VMX Location>)
In Workstation and Server, Notepad will launch. With ESX, I get a failed to connect to host message.
Wow, looks like we were working on the same thing the last weeks, since I published my VIX API C# library to Codeplex one day after you wrote your CodeProject article
My library basically does the same as yours, it simplifies dealing with the VIX API and makes common tasks (powering on/off, copying files) a lot easier.
I also took the time and fully commented the functions (using the official documentation), so you get hints from IntelliSense while coding, which I find really helpful.
Although your library implements less functions than mine (I wrapped them all...), it seems like you have the better concept when dealing with IJobs.
If you want to take a look at my approach, visit http://www.codeplex.com/VixCOMWrapper and download the library
I've been adding features while you were away! I really think the VMWare development team should produce something like this, so hopefuly seeing multiple implementations will give them the right object model to start with. A library that is not a wrapper on top of the COM API is really the right answer, there's no need to have a COM object registered to talk to VMWare. You wouldn't need to package the VIX COM DLLs if you were to distribute anything that talks to VMWare. Heck, VMWare should give us a million bucks to share for designing it for them
If I may allow some criticism of the stuff on CodePlex: I think that your library needs to be more consistent with constructs like snapshots or shared folders: those are all objects and should be manipulated as collections. I chose not to implement methods like AddSharedFolder(name, description) - from the object model perspective you want VirtualMachine.SharedFolders.Add(new VMWareSharedFolder(name, description)), then VirtualMachine.SharedFolders reflects the changes. This also applies to snapshots and all other things that belong to the VM. Other important aspects include an active timeout - VMWare won't timeout in blocking operations.
I also wanted to thank you - I learned something from your implementation - I was wondering what the right way of implementing things like Snapshot.Name is - your code helped. I also added Snapshot.Path - post]]].
Some competition is a good thing! People should use whatever they think is best. Of course, you're welcome to give up the CodePlex library and contribute to VMWareTasks
I totally agree that an implementation on top of the COM API shouldn't be necessary, cause this just adds another layer of complexity. It would also be nice if there was a way to use our library on Linux systems (e.g. by leveraging the capabilites of the Mono framework).
Of course I also looked at your source-code and I have to admit that your implementation follows the concept of OOP much better
My intention was to just have a library that looks similar to the original VIX API, but uses C#-style parameters and return values and hides me from dealing with handles, blocking, etc.
I'll have to look at implementing a timeout for the Wait() function, thanks for that !
As you've said, we can only benefit from having seperate approaches and maybe the VMware developement team benefits too
I have now tried both COM Wrappers and receive the same error when trying to connect to my ESXi host. This leads me to believe that something is missing on the host itself, since it works on my Server 2.0 and Workstation installs.
I have now tested against two different ESXi 3.5 hosts and receive the error "Unable to Connect to Host". Is there anything I need to check on the host? Does VIX have to be installed locally on the host or is it on by default?
I just tried it against my ESXi host (3.5.0 build-123629) and it works without problems. Remember that you need at least ESX Update 2 for VIX to work, the default port for connection is 443. Basically, VIX needs the same credentials/IP that you would enter when you connect with the VMware Infrastructure Client.
You don't need to install VIX on the host, just on the machine from where you want to connect to the ESXi server.
If that doesn't help, please let me know
I think I am going to wait for the server admin to come back after the new year and apply at least U2. The server I am connecting to is ESXi 3.5 110271. I am using root to login, so that shouldn't be the problem.
I'll try after I get the server updated and let you know the results.
I tried downloading the documentation file for your wrapper, but it did not seem to want to open... I was wondering if your wrapper supports copying files located in a guest VM to and from a datastore on an ESX 3.5 server. I have been researching the VIX documentation and the various VI API documentation and can't seem to get a definitive answer whether or not this is possible. I have tried various ways of inputting the path to the file on the datastore (for example "\[datastore1\] folder/folder/file.extension" as well as "/vmfs/volumes/(long hex string)/folder/folder/file.extension") but nothing seems to work. Do you have any experience with copying files to and from datastores? Any help would be greatly appreciated!
The documentation is a standard CHM-helpfile, it should open on any Windows system since Windows 98 There may be problems if you try to open it from a network location, so store it locally on your computer.
To answer your question: the wrapper doesn't support copying files directly from a ESX datastore to a guest VM and vice versa. There are functions that copy files (CopyFileFromHostToGuest and CopyFileFromGuestToHost) but they copy only to/from the system where the Vix client is running, not the ESX host itself.
You could copy the file to your local machine first, and then upload the file to the datastore (which should be possible with the VI API, I guess).