[NoBrainer] Get location field for vCAC ComputeResource

In vCAC you can set a location on a ‘Compute Resource’. While in some cases this might not make sense (e.g. vCenter stretched clusters) you might still want to use it, for example to implement some placement logic. When you have a look at the object, you might be surprised to see, that there is no attribute of the corresponding ‘Host’ object within the management model. The reason for this is, that this location field is actually implemented as a ‘HostProperty’ (although it is not visible in the GUI). Here is how you can read out that information via API:

PS > $m.GetType().FullName;
DynamicOps.ManagementModel.ManagementModelEntities
PS > $h = $m.Hosts |? HostName -eq 'vCenterResources';
PS > $h.GetType().FullName;
DynamicOps.ManagementModel.Host
PS > $hp = $m.LoadProperty($h, 'HostProperties') | 
  Select-Object PropertyName, PropertyValue;
PS > $Location = 
  ($hp |? PropertyName -eq 'Vrm.DataCenter.Location')
  .PropertyValue;
PS > $Location
PremiumSite1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: