Quantcast
Viewing all articles
Browse latest Browse all 293210

Re: .Net SDK versus Web Services

Yeah, forget the documentation that comes with the PowerCLI stuff.

 

Just use this guide below.

 

http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/index.html

 

The most confusing part for me to begin with using the VIM dll was the fact that I had to get an object before I could do anything with it.

 

So for example, if I wanted to manipulate a VM, I needed to get it first using (I code in VB.net):

 

  • Dim Filter As New NameValueCollection
  • Filter.Add("name", "MyVMName")
  • Dim myVm as VirtualMachine = Client.FindEntityView(GetType(VirtualMachine), Nothing, Filter, new string() {"name"})

 

This would bring back a pretty naked object as I only specify the name as a the property to return. This provides me with little info on the VM's object, but it's enough to allow me to manipulate it (which is good as less properties returned means less load on the vCenter web service).

 

Then I could use that object to do stuff like:

 

  • myVM.ShutdownGuest

 

If I wanted to get my VM with all info populated I'd do this:

 

  • Dim myVm as VirtualMachine = Client.FindEntityView(GetType(VirtualMachine), Nothing, Filter, Nothing)

 

If I wanted to get my VM with just other specific properties, I'd just add them in to the string array for properties:

 

  • Dim myVm as VirtualMachine = Client.FindEntityView(GetType(VirtualMachine), Nothing, Filter, new string() {"name", "config.hardware.device"})

 

The same goes for any other managed object references. If you want to manipulate a hostSystem, just grab the object using the VIM dll:

 

  • Dim myHost as HostSystem = Client.FindEntityView(GetType(HostSystem), Nothing, Filter, Props)

 

If you need to get multiple objects, use FindEntityViews instead, which will always return an IList(Of EntityViewBase).

 

  •      Client.FindEntityViews(GetType(HostSystem), Nothing, Nothing, Props)

 

You then just cast each returned object in the list into it's specific type, in this case, HostSystem

 

FindEntityView or FindEntityViews from my understanding is only used to get ManagedObjectReference types. If you need to get DataObjectTypes, you use GetView or GetViews. This may be wrong though. Sometimes I had to use GetView if FindEntityView threw an error. Just try them out until you get the hang of it.


Viewing all articles
Browse latest Browse all 293210

Trending Articles