如何使用 VMware vSphere SDK 获取没有分布式端口组的 ESXi 中标准交换机中的端口组列表
本文关键字:列表 交换机 标准 ESXi 分布式 vSphere VMware 何使用 SDK 获取 | 更新日期: 2023-09-27 18:35:48
我设法在Sandard交换机中获取了所有端口组,但该列表包括分布式vSwitch中的分布式端口组,它包含在标准交换机结构中。我不希望在我的情况下这样做。
我正在使用VMware vSphere SDK(5.5),我尝试了这个:
public List<Network> GetPortGroups(VimClient vimClient, Datacenter selectedDC = null, string pgName = null)
{
List<Network> lstPortGroups = new List<Network>();
NameValueCollection pgFilter = new NameValueCollection();
ManagedObjectReference DcMoRef = new ManagedObjectReference();
if (pgName != null)
{
pgFilter.Add("name", pgName);
}
else
{
pgFilter = null;
}
if (selectedDC != null)
{
DcMoRef = selectedDC.MoRef;
}
else
{
DcMoRef = null;
}
List<EntityViewBase> appPortGroups = vimClient.FindEntityViews(typeof(Network), DcMoRef, pgFilter, null);
if (appPortGroups != null)
{
foreach (EntityViewBase appPortGroup in appPortGroups)
{
Network thisPortGroup = (Network)appPortGroup;
lstPortGroups.Add(thisPortGroup);
}
return lstPortGroups;
}
else
{
return null;
}
}
public List<Network> GetStandardPgs(Datacenter selectedDC = null)
{
List<Network> lstPortGroups = new List<Network>();
ManagedObjectReference DcMoRef = new ManagedObjectReference();
if (selectedDC != null)
{
DcMoRef = selectedDC.MoRef;
}
else
{
DcMoRef = null;
}
List<EntityViewBase> appPortGroups = _vmwarecontext.FindEntityViews(typeof(Network), DcMoRef, null, null);
if (appPortGroups != null)
{
foreach (EntityViewBase appPortGroup in appPortGroups.Where(x => x.GetType() == typeof(Network)))
{
lstPortGroups.Add((Network)appPortGroup);
}
return lstPortGroups;
}
else
{
return null;
}
}