Q

Help with the VI3 SDK

Learn how to shut down and power on guest virtual machines outside of VirtualCenter with the VMware Infrastructure 3 (VI3) SDK.

I came across your three articles on creating a C# utility to access VI3 environment using the VI3 SDK.

What I need is a way to is shut down guest virtual machines (VMs) and power them back on outside of VirtualCenter. I've seen the perl extensions that are available, but I don't won't to have installing perl as a requirement for performing these tasks. I'd like to create a command line tool and/or .net assembly that will take a virtual machine (VM) name, user credentials, and a command (i.e. ShutdownGuest, PowerOn, etc.) and perform...

that operation through the VI3 SDK.

I've already made a few changes to the code you provide to list all the VMs instead of the hosts.

Questions: When the following line from the code executes it takes about 30 seconds to complete: vim_svc = new VimService();

Any thoughts why it takes so long or how to improve it? (I'm using the .NET 2.0 VimApi library that you created)

Also, can you provide any examples how to query for a single VM object given its name? Can you also point me where to learn how to create a "registered" assembly/class (not sure what the proper terminology would be) that could be called from other .NET apps, scripts, etc.?

Here are the answers to your questions:

When the following line from the code executes it takes about 30 seconds to complete: vim_svc = new VimService();
Any thoughts why it takes so long or how to improve it?

VMware solved the issue of the class taking a frustratingly long time to instantiate (it was a problem with how the XML serialization was generated). There is a KB article on the subject at VMware's Website.

Can you provide any examples how to query for a single VM object given its name?

For this you would use the FindByDnsName method (you can look it up in the SDK reference guide). In a recent article I demonstrate how to use the FindByIP method, the use is almost the same. Here is an example:

ManagedObjectReference moref_vm = 
vim_svc.FindByDnsName( vim_svc_content.searchIndex, null,  
  "foo.lostcreations.local", true );

That will get you a managed object reference to the VM you are looking for.

Can you also point me where to learn how to create a "registered" assembly/class (not sure what the proper terminology would be) that could be called from other .net apps, scripts, etc.?

Simply create a library assembly (DLL) and you can reference it from other .NET applications. For scripts you would need to do a type library export to make the .NET classes available as COM objects. The tlbexport command should do the trick. In order for a .NET assembly to be globally visible you must install it into the Global Assembly Cache. To do this the assembly must be signed by a strong name key. The tool "snk" will help you with that, but so can Visual Studio.

Hope this helps!

This was first published in December 2007

Dig deeper on VMware virtualization

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchVMware

SearchWindowsServer

SearchCloudComputing

SearchVirtualDesktop

SearchDataCenter

Close