Home > Ask the Server Virtualization Experts > VMware Questions & Answers > Help with the VI3 SDK
Ask The Server Virtualization Expert: Questions & Answers
EMAIL THIS

Help with the VI3 SDK

Andrew Kutz EXPERT RESPONSE FROM: Andrew Kutz

Pose a Question
Other Server Virtualization Categories
Meet all Server Virtualization Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 04 December 2007
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.?


>
EXPERT RESPONSE
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!


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   





Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



More Expert Analysis on Virtual Machines and Integrating Virtualization
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersEvents
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2006 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts