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.?
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!
Dig deeper on VMware virtualization
Related Q&A from Andrew Kutz
This expert's insights will help you make a decision whether to use Ubuntu remote backup.continue reading
A user wonders how well Ubuntu will serve him/her in terms of stability, and gets release recommendations from an expert.continue reading
Learn about an emerging product that aims to decrease time spent fixing dependencies.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.