VMware Cloud Community
schistad
Enthusiast
Enthusiast
Jump to solution

VcHostVirtualSwitch object property 'portgroup' returns array of strings, not objects

Something seems a bit amiss here; on a vSphere 5.5 installation, querying a traditional vSwitch (ie not dvSwitch) for portgroups I am not receiving the expected object array of type VcHostPortGroup [], but rather a flat string array that cannot be expanded.

This seems to break the supplied actions for listing portgroups as well as my own code, so I suspect that some change in the 5.5 API may have gone unnoticed since so few people use vSwitches any more.

Could someone check the following code and see what happens:

var hosts=Server.findAllForType("VC:HostSystem");

var host=hosts[0];

var switches=host.configManager.networkSystem.networkInfo.vswitch;

for (var i=0; i<switches.length; i++) {

  vswitch=switches[i];

  System.log(vswitch);

  var pglist=vswitch.portgroup;

  for (var n=0;n<pglist.length;n++) {

  var pg=pglist[n];

  System.log (pg);

System.log("Found portgroup "+ pg.spec.name +" with vlan ID "+pg.spec.vlanId); // This breaks

  }

}

Reply
0 Kudos
1 Solution

Accepted Solutions
schistad
Enthusiast
Enthusiast
Jump to solution

Okay, so I figured this out on my own.

There is a documentation bug in the vCO API in that the HostVirtualSwitch object does not point to a port group but rather returns a 'flattened' string array with the (non-unique, useless) keys to the port groups associated with the vSwitch. This is correctly indicated in the vSphere API reference but incorrect in the vCO version, which might indicate that the actual vCO code is inconsistent as well.

To retrieve an actual populated HostPortGroup object you must drill down through the HostNetworkInfo managed object; the portgroup property here is an array of the correct type.

View solution in original post

Reply
0 Kudos
1 Reply
schistad
Enthusiast
Enthusiast
Jump to solution

Okay, so I figured this out on my own.

There is a documentation bug in the vCO API in that the HostVirtualSwitch object does not point to a port group but rather returns a 'flattened' string array with the (non-unique, useless) keys to the port groups associated with the vSwitch. This is correctly indicated in the vSphere API reference but incorrect in the vCO version, which might indicate that the actual vCO code is inconsistent as well.

To retrieve an actual populated HostPortGroup object you must drill down through the HostNetworkInfo managed object; the portgroup property here is an array of the correct type.

Reply
0 Kudos