1. Enabling VM Tracker feature
  n9k-sw-1# conf t  
  Enter configuration commands, one per line. End with CNTL/Z.   
                  n9k-sw-1(config)# feature vmtracker  
  n9k-sw-1(config)#   
  1. Establishing a Connection to vCenter
  n9k-sw-1# configure terminal  
  n9k-sw-1(config)# vmtracker connection conn1  
  n9k-sw-1(config-vmt-conn)# remote ip address 10.1.1.1 port 80 vrf management  
  n9k-sw-1(config-vmt-conn)# username user1 password cisco123  
  n9k-sw-1(config-vmt-conn)# connect  
  1. Verification

Once the connection and the information between switch and vCenter has been exchanged you should be able to see the Virtual Machines.

n9k-sw-1# show vmtracker info detail


Interface Host VMNIC VM State PortGroup VLAN-Range

Ethernet1/3 192.168.2.50 vmnic4 VM1 on PGroup100 100

  1. Using XMPP for VM visibility (VM Tracker)

With XMPP we can create groups of switches and then use group-chat execute commands on all of the switches simultaneously. This allows us to send - from a single location - a VM Tracking command to the group, and have each switch return the list of VMs that are connected.

  1. Install an XMPP Server
  admin@linux# yum install jabberd   
  1. Join a Group

Here is an example on how to attach a switch to the group chat "xmpp":

  guestshell# jabberd attach group xmpp  
  guestshell>xmpp#   
  1. Executing a CLI Command

Here is a example of sending a single CLI command to multiple switches leveraging XMPP group chat:

  guestshell>xmpp# show clock  
  
  <n9k-sw-1@xmpp.cisco.com/(fmgr-device)(ABC1234abcd)>  
  18:46:37.481 UTC Wed Sep 30 2015  
  </n9k-sw-1@xmpp.cisco.com/(fmgr-device)(ABC1234abcd)>  
  
  <n9k-sw-2@xmpp.cisco.com/(fmgr-device)(DEF5678abcd)>  
  18:46:56.420 UTC Wed Sep 30 2015  
  </n9k-sw-2@xmpp.cisco.com/(fmgr-device)(DEF5678abcd)>  
  Responses expected:2 received:2, time spend:117 msec   

Below is another sample to showcase the power of VM Tracker with XMPP to gather information across multiple switches based on VM Name, IP address, connected interface, and so on:

  guestshell>xmpp#  
  guestshell>xmpp# show vmtracker info detail  
   
  <n9k-sw-1@xmpp.cisco.com/(fmgr-device)(ABC1234abcd)>  

Interface Host VMNIC VM State PortGroup VLAN-Range

Ethernet1/3 192.168.2.50 vmnic4 VM1 on PGroup100 100

  <n9k-sw-2@xmpp.cisco.com/(fmgr-device)(DEF5678abcd)>  

Interface Host VMNIC VM State PortGroup VLAN-Range


  1. Leveraging Python

Programmatic access using XMPP will allow for the execution of scheduled commands, the capture of structured responses (XML), and the storage of the data to a repository.

In the example below a Python script connects to XMPP and executes a show command against "VM tracker" with a respective VM name. The result is the location of the switch where the virtual machine (VM) is present.

  import xmpp, re  
  
  vm="VM1"  
  cmd="show vmtracker info detail | include " + vm  
  jid='python@xmpp.cisco.com'  
  pwd="P@$$w0rd"  
  room="server@xmpp.cisco.com"  
  
  def messageHandler(conn, msg):  
  if msg.getType() == "groupchat":  
  result=re.findall("Interface [1-9]", str(msg.getBody()))  
  if result:  
  sw=re.findall("/(.*?)/",str(msg.getFrom()))  
  print vm + " was found on:\n"  
  print sw[0] + "\n"  
  print str(msg.getBody()) + "\n"  
  
  def StepOn(conn):  
  try:  
  conn.Process(1)  
  except KeyboardInterrupt:  
  return 0  
  return 1  
  
  def GoOn(conn):  
  while StepOn(conn):  
  pass  
  
  jid=xmpp.protocol.JID(jid)  
  cl=xmpp.Client(jid.getDomain(), debug=[])  
  
  if cl.connect() == "":  
  print "connection failed"  
  sys.exit(0)  
  
  if cl.auth(jid.getNode(),pwd) == None:  
  print "authentication failed"  
  sys.exit(0)  
  
  cl.RegisterHandler('message',messageHandler)  
  cl.sendInitPresence()  
  cl.send(xmpp.Presence(to='{0}/{1}'.format(room, jid)))  
  message = xmpp.Message(room, cmd)  
  message.setAttr('type', 'groupchat')  
  cl.send(message)  
  
  GoOn(cl)  

Below is the output of the Python script, which can be stored for correlation:

VM1 was found on: n9k-sw-1@xmpp.cisco.com

Interface Host VMNIC VM State PortGroup VLAN-Range

Ethernet1/3 192.168.2.50 vmnic4 VM1 on PGroup100 100

Results returned :: 0