Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 244595

Re: using VMware.Vim

$
0
0

So I'm back, I'm now pulling datastores in portgroups based on the moref stored as a value in a dropdown. Here is the listing

 

 

//// Get a list of datastores// 
string SelectedDataCenter = cboClusters.SelectedItem.Text;
NameValueCollection dcFilter = new NameValueCollection();
dcFilter.Add("name", SelectedDataCenter); 
List<EntityViewBase> appDC = vimClient.FindEntityViews(typeof(Datacenter), null,dcFilter, null);
Datacenter thisDC = (Datacenter)appDC[0];
ManagedObjectReference[] DSmoRefs = thisDC.Datastore;
foreach (ManagedObjectReference dsmoRef in DSmoRefs){    Datastore thisDs = new Datastore(vimClient, dsmoRef);    ListItem vmDatastore = new ListItem();    vmDatastore.Text = thisDs.Name;    vmDatastore.Value = thisDs.MoRef.ToString();    cboDatastores.Items.Add(vmDatastore);}        //// Get a list of network portgroups// 
ManagedObjectReference[] PGmoRefs = thisDC.Network;
foreach (ManagedObjectReference pgmoRef in PGmoRefs){    DistributedVirtualPortgroup thisPort = new DistributedVirtualPortgroup(vimClient, pgmoRef);    ListItem vmPortName = new ListItem();    vmPortName.Text = thisPort.Name;    vmPortName.Value = thisPort.MoRef.ToString();    cboNetwork.Items.Add(vmPortName);}

 

So, I kind of went a little different way, and as I paste this in I'm wondering if I could get around the line where I reference the first (and only) item in the collection returned from the findentityviews. Earlier testing I was using findentityview, but I think the problem was in my filter I was using "fields" that appeared in powershell but didn't actually show up when I browsed the mob.

 

So as a POC this seems to work, and is much quicker than attempting to load a snap-in inside powershell, inside a webpage ;-) not that i personally didn't think that was cool.

 

Ok, so I'm getting the right datastores and portgroups, but i'm not getting the pretty names, which for the moment i'm ok with. My next challenge is how to get a list of specfiles. My original code for that didn't work at all.

 

 

//// Get a list of OS Customizations// 
List<EntityViewBase> appOsCustomizationSpecs = vimClient.FindEntityViews(typeof(CustomizationSpec), null, null, null);
foreach (EntityViewBase appOsCustomizationSpec in appOsCustomizationSpecs){    CustomizationSpec thisSpec = (CustomizationSpec)appOsCustomizationSpec;    ListItem specName = new ListItem(thisSpec.Identity.ToString());}

 

I get red wavy's under the first line in the foreach. The message is cannot convert type vmware.vim.entityviewbase to vmware.vim.customizationspec. Any thoughts or insight would be appreciated.


Viewing all articles
Browse latest Browse all 244595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>