VMware Cloud Community
joshnlarsen
Contributor
Contributor
Jump to solution

Programmatic method to determine the current pNIC / standard switch uplink a VM is using

Fellow Virt Professionals,

     Surely there has to be a way to gather the same data produced by esxtop in columns 'USED-BY', 'TEAM-PNIC', and 'DNAME' in the network panel...aside from creating a custom esxtop config file then specifying that file when running esxtop in interactive batch mode and then redirecting the output to a .csv file and then parsing it with sed and regex. All of that seems a bit excessive don't you think? Plus it will consume a considerable amount of run time which I cannot spare due to the shear amount of hosts across our distributed environment that this mapping of virtual machine to virtual machine host physical interface associations will cover.

   Whether accessing the api via PowerCli and view or extension data or though the content of my service instances through the pyVmomi Python sdk doesn't really matter. I just really need a programmatic way to efficiently and pragmatically gather and report on this data. Any suggestions, ideas, shared experiences, advice, alternate methodology, perspectives or collaborative brainstorms will be gratefully appreciated as I am at a standstill beating my head against a wall trying to pound a screw in to this with a hammer. Thank you for taking the time to read my long winded question. I apologize for any forum guidelines I may have neglected to follow as I very rarely am more than a spectator within the community.

Thank you,

Josh Larsen

Virtualization Engineer - Hosting

vcp-dcv6.5, vcp-nv6 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The real problem with esxtop and it's columns, is that there is no clear explanation where the values are coming from.

In PowerCLI we have the Get-EsxTop, which retrieves the values displayed by esxtop.

And it is only with a partial mapping document, see my Hitchhiker’s Guide To Get-EsxTop – Part 2 – The Wrapper post, that we can map most of the esxtop column names.
For the DNAME column we need to get the topology information, and then use that table as a lookup.

You need to be connected to the ESXi node for the Get-EsxTop cmdlet.

$esxName = 'myesx.domain'

$user = 'root'

$pswd = 'VMware1!'

Connect-VIServer -Server $esxName -User $user -Password $pswd | Out-Null


$topo = Get-EsxTop -Topology NetPort -TopologyInfo


Get-EsxTop -Server $esxName -CounterName NetPort |

Select PortId, @{N = 'Used-By'; E = { $_.ClientName } },

@{N = 'Team-pNic'; E = { $_.TeamUplink } },

@{N = 'DName'; E = {

   $portId = $_.portId

   ($topo.Entries | where { $_.PortId -eq $portId }).PortsetName

   }

}


Disconnect-VIServer -Server $esxName -Confirm:$false

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

The real problem with esxtop and it's columns, is that there is no clear explanation where the values are coming from.

In PowerCLI we have the Get-EsxTop, which retrieves the values displayed by esxtop.

And it is only with a partial mapping document, see my Hitchhiker’s Guide To Get-EsxTop – Part 2 – The Wrapper post, that we can map most of the esxtop column names.
For the DNAME column we need to get the topology information, and then use that table as a lookup.

You need to be connected to the ESXi node for the Get-EsxTop cmdlet.

$esxName = 'myesx.domain'

$user = 'root'

$pswd = 'VMware1!'

Connect-VIServer -Server $esxName -User $user -Password $pswd | Out-Null


$topo = Get-EsxTop -Topology NetPort -TopologyInfo


Get-EsxTop -Server $esxName -CounterName NetPort |

Select PortId, @{N = 'Used-By'; E = { $_.ClientName } },

@{N = 'Team-pNic'; E = { $_.TeamUplink } },

@{N = 'DName'; E = {

   $portId = $_.portId

   ($topo.Entries | where { $_.PortId -eq $portId }).PortsetName

   }

}


Disconnect-VIServer -Server $esxName -Confirm:$false

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
joshnlarsen
Contributor
Contributor
Jump to solution

Thank you LucD! You're a legend! I really appreciate it.

>Josh

0 Kudos