Collecting directly connected switch ports ID from multiple ESXi hosts

We are going to add vlan to a cluster. We need to know what are the switch ports for each Guest vmnic in each hosts so that we can ask the network team to trunk the new vlan.

This little script collects the switch ports information obtained using CDP. The list of hosts is stored in a text file list.

    for i in `cat list`
    do
    ssh -q -T root@$i <<EOF
    hostname
    vim-cmd hostsvc/net/query_networkhint --pnic-name=vmnicX  | grep -E  'devId|portId'
    vim-cmd hostsvc/net/query_networkhint --pnic-name=vmnicY  | grep -E  'devId|portId'
    echo
    EOF
    done

In this example, vmnicX and vmnicY are used for Guest network. If you don't have ssh keys setup, you can use sshpass.

    host1.esx.example.com
             devId = "SwitchA",
             portId = "Ethernet110/1/2",
             devId = "SwitchB",
             portId = "Ethernet110/1/2",

    host2.esx.example.com
             devId = "SwitchA",
             portId = "Ethernet110/1/4",
             devId = "SwitchB",
             portId = "Ethernet110/1/4",

    host3.esx.example.com
             devId = "SwitchA",
             portId = "Ethernet110/1/6",
             devId = "SwitchB",
             portId = "Ethernet110/1/6",

    ... and so on
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s