Not all vSphere REST APIs are available currently, we may expect them in the next vSphere major releases. For now to achieve your task use SOAP-based APIs ( vSphere Management SDKs) : Here is the...
See more...
Not all vSphere REST APIs are available currently, we may expect them in the next vSphere major releases. For now to achieve your task use SOAP-based APIs ( vSphere Management SDKs) : Here is the java sample method using VI Java API: Getting started with vSphere API using VI Java public void portgroupList(String vCenterIP, String username, String password, String clusterName) {
Map<String, String> vssPGs = new HashMap<>();
Map<String, String> dvsPGs = new HashMap<>();
try {
ServiceInstance serviceInstance = new ServiceInstance(new URL("https://" + vCenterIP + "/sdk"), username,
password, true);
ClusterComputeResource cls = (ClusterComputeResource) new InventoryNavigator(
serviceInstance.getRootFolder()).searchManagedEntity("ClusterComputeResource", clusterName);
HostSystem[] hsArr = cls.getHosts();
for (HostSystem hs : hsArr) {
Network[] netArr = hs.getNetworks();
for (Network net : netArr) {
if (net.getMOR().getType().equals("Network"))
vssPGs.put(net.getName(), net.getMOR().getVal());
else if (net.getMOR().getType().equals("DistributedVirtualPortgroup"))
dvsPGs.put(net.getName(), net.getMOR().getVal());
}
}
if (!vssPGs.isEmpty()) {
System.out.println("Virtual Standard Switch portgroups in cluster::" + clusterName);
vssPGs.forEach((k, v) -> {
System.out.println(k + " = " + v);
});
}
if (!dvsPGs.isEmpty()) {
System.out.println("Virtual Distributed Switch portgroups in cluster::" + clusterName);
dvsPGs.forEach((k, v) -> {
System.out.println(k + " = " + v);
});
}
} catch (Exception e) {
System.err.println("Error::" + e.getLocalizedMessage());
}
}