Three more functions to go with the previously posted ones.
protected List<ClusterComputeResource> GetClusters(VimClient vimClient, string clusterName = null)
{ List<ClusterComputeResource> lstClusters = new List<ClusterComputeResource>(); List<EntityViewBase> appClusters = new List<EntityViewBase>(); if (clusterName == null) { appClusters = vimClient.FindEntityViews(typeof(ClusterComputeResource), null, null, null); } else { NameValueCollection clusterFilter = new NameValueCollection(); clusterFilter.Add("name", clusterName); appClusters = vimClient.FindEntityViews(typeof(ClusterComputeResource), null, clusterFilter, null); } if (appClusters != null) { foreach (EntityViewBase appCluster in appClusters) { ClusterComputeResource thisCluster = (ClusterComputeResource)appCluster; lstClusters.Add(thisCluster); } return lstClusters; } else { return null; }
}
protected List<HostSystem> GetHosts(VimClient vimClient, string hostParent = null)
{ List<HostSystem> lstHosts = new List<HostSystem>(); List<EntityViewBase> appHosts = new List<EntityViewBase>(); if (hostParent == null) { appHosts = vimClient.FindEntityViews(typeof(HostSystem), null, null, null); } else { NameValueCollection hostFilter = new NameValueCollection(); hostFilter.Add("parent", hostParent); appHosts = vimClient.FindEntityViews(typeof(HostSystem), null, hostFilter, null); } if (appHosts != null) { foreach (EntityViewBase appHost in appHosts) { HostSystem thisHost = (HostSystem)appHost; lstHosts.Add(thisHost); } return lstHosts; } else { return null; }
}
protected List<Datacenter> GetDcFromCluster(VimClient vimClient, string clusterParent)
{ List<Datacenter> lstDataCenters = new List<Datacenter>(); NameValueCollection parentFilter = new NameValueCollection(); parentFilter.Add("hostFolder", clusterParent); List<EntityViewBase> arrDataCenters = vimClient.FindEntityViews(typeof(Datacenter), null, parentFilter, null); if (arrDataCenters != null) { foreach (EntityViewBase arrDatacenter in arrDataCenters) { Datacenter thisDatacenter = (Datacenter)arrDatacenter; lstDataCenters.Add(thisDatacenter); } return lstDataCenters; } else { return null; }
}