VMware

This Question is Possibly Answered

1 "correct" answer available (10 pts) 2 "helpful" answers available (6 pts)
25 Replies Last post: Aug 4, 2009 10:24 AM by wila   1 2 Previous Next

VMWareTasks: A VIX API C# Library (let's reinvent less wheels) posted: Jan 3, 2009 6:33 AM

Click to view dblock's profile Enthusiast 110 posts since
Dec 9, 2008
I posted a CodeProject Article this morning with a VMWareTasks C# library on top of the VIX API. It exposes a better programming model for the 99% of those synchronous VMWare scenarios where you don't want to deal with jobs or other more complex constructs. I think we can all benefit from reimplementing the same thing less often!

http://www.codeproject.com/KB/library/VMWareTasks.aspx

http://code.dblock.org/ShowPost.aspx?id=25

I'd love to get more features/patches for the library, feel free to (re)use and contribute.

cheers
dB.

Update: I posted a new build 1.0.1604.0: http://code.dblock.org/ShowPost.aspx?id=29

Click to view eatorres's profile Enthusiast 31 posts since
Oct 21, 2008
Good job! I have also written a wrapper for Vix API, but not nearly as thorough as yours.
Click to view c_shanklin's profile Master 763 posts since
Dec 3, 2007
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?
Click to view JPatten's profile Enthusiast 50 posts since
Oct 16, 2007

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.
Click to view c_shanklin's profile Master 763 posts since
Dec 3, 2007
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.
Click to view JPatten's profile Enthusiast 50 posts since
Oct 16, 2007
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>)

$vm.Login(“<login>”, “<pw>”)

$vm.Execute(“notepad.exe”,$null)


In Workstation and Server, Notepad will launch. With ESX, I get a failed to connect to host message.

Click to view akoeplinger's profile Novice 18 posts since
Nov 29, 2008

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 :D

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 ;-)

Regards, Alex

Click to view akoeplinger's profile Novice 18 posts since
Nov 29, 2008

Hi!

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 :)

Regards, Alex

Click to view JPatten's profile Enthusiast 50 posts since
Oct 16, 2007

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?

Thanks

Click to view akoeplinger's profile Novice 18 posts since
Nov 29, 2008

Hi!

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 ;)

Regards, Alex

Click to view JPatten's profile Enthusiast 50 posts since
Oct 16, 2007

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.

Thanks

Click to view eatorres's profile Enthusiast 31 posts since
Oct 21, 2008
Hi Alex,

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!
Click to view akoeplinger's profile Novice 18 posts since
Nov 29, 2008

Hi!

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).

Regards, Alex

Developer Social Media

Communities