VMware Communities > VMware Developer > Forums > VIX API > Discussions

This Question is Possibly Answered

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

VMWareTasks: A VIX API C# Library (let's reinvent less wheels)

Jan 3, 2009 6:33 AM

Click to view dblock's profile Enthusiast dblock 109 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

Reply Re: VMWareTasks: A VIX API C# Library (let's reinvent less wheels) Dec 22, 2008 1:24 PM
Click to view eatorres's profile Enthusiast eatorres 31 posts since
Oct 21, 2008
Good job! I have also written a wrapper for Vix API, but not nearly as thorough as yours.
Reply Re: VMWareTasks: A VIX API C# Library (let's reinvent less wheels) Dec 23, 2008 12:40 PM
Click to view c_shanklin's profile Master c_shanklin 740 posts since
Dec 3, 2007
VMware
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?
Reply Re: VMWareTasks: A VIX API C# Library (let's reinvent less wheels) Dec 23, 2008 10:41 PM
in response to: c_shanklin
Click to view dblock's profile Enthusiast dblock 109 posts since
Dec 9, 2008

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 :)
Reply Re: VMWareTasks: A VIX API C# Library (let's reinvent less wheels) Dec 24, 2008 12:55 PM
Click to view JPatten's profile Enthusiast JPatten 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.
Reply Re: VMWareTasks: A VIX API C# Library (let's reinvent less wheels) Dec 24, 2008 1:34 PM
in response to: JPatten
Click to view c_shanklin's profile Master c_shanklin 740 posts since
Dec 3, 2007
VMware
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.
Reply Re: VMWareTasks: A VIX API C# Library (let's reinvent less wheels) Dec 24, 2008 2:26 PM
in response to: c_shanklin
Click to view JPatten's profile Enthusiast JPatten 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.

Reply Re: VMWareTasks: A VIX API C# Library (let's reinvent less wheels) Dec 25, 2008 10:14 AM
Click to view akoeplinger's profile Novice akoeplinger 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

Reply Re: VMWareTasks: A VIX API C# Library (let's reinvent less wheels) Dec 26, 2008 12:44 PM
in response to: akoeplinger
Click to view dblock's profile Enthusiast dblock 109 posts since
Dec 9, 2008
Hey Alex,

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

cheers
dB.

Reply Re: VMWareTasks: A VIX API C# Library (let's reinvent less wheels) Dec 27, 2008 10:04 AM
in response to: dblock
Click to view akoeplinger's profile Novice akoeplinger 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

Reply Re: VMWareTasks: A VIX API C# Library (let's reinvent less wheels) Dec 29, 2008 6:03 AM
in response to: JPatten
Click to view JPatten's profile Enthusiast JPatten 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

Reply Re: VMWareTasks: A VIX API C# Library (let's reinvent less wheels) Dec 29, 2008 8:15 AM
in response to: JPatten
Click to view akoeplinger's profile Novice akoeplinger 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

Reply Re: VMWareTasks: A VIX API C# Library (let's reinvent less wheels) Dec 29, 2008 8:19 AM
in response to: akoeplinger
Click to view JPatten's profile Enthusiast JPatten 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

Reply Re: VMWareTasks: A VIX API C# Library (let's reinvent less wheels) Dec 30, 2008 12:39 PM
in response to: akoeplinger
Click to view eatorres's profile Enthusiast eatorres 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!
Reply Re: VMWareTasks: A VIX API C# Library (let's reinvent less wheels) Dec 31, 2008 2:55 AM
in response to: eatorres
Click to view akoeplinger's profile Novice akoeplinger 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

1 2 Previous Next
Actions