Skip to content

Instantly share code, notes, and snippets.

@sdorsett
Last active August 1, 2017 15:58
Show Gist options
  • Save sdorsett/7cddb69ec8cf194a8fd47210f2670e4d to your computer and use it in GitHub Desktop.
Save sdorsett/7cddb69ec8cf194a8fd47210f2670e4d to your computer and use it in GitHub Desktop.
rbvmomi - find vnic IP addresses for hosts in a cluster
require 'rbvmomi'
credentials = { :host => "192.168.1.10", :user => "administrator@vsphere.local", :password => "vmware", :insecure => true }
vim = RbVmomi::VIM.connect(credentials)
datacenter = vim.rootFolder.childEntity.first # grab the first datacenter
datacenter.hostFolder.childEntity # this will return an array of all the clusters in the datacenter
cluster = datacenter.hostFolder.childEntity.first # grab the first cluster from the datacenter
cluster.host # this will return an array of all the ESXi hosts in the first cluster
host = cluster.host.first # grab the first host in the cluster
host.config.network.vnic # display all the vnics on the host
host.config.network.vnic.first.spec.ip.ipAddress # display the ip address bound the to first vnic on the host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment