Last active
August 1, 2017 17:40
-
-
Save sdorsett/a321d355e288b73302a2b352fc90f74b to your computer and use it in GitHub Desktop.
rbvmomi - find vnic info for all ESXi hosts in all clusters in all datacenters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rbvmomi'; | |
credentials = { :host => "192.168.1.10", :user => "[email protected]", :password => "vmware", :insecure => true }; | |
vim = RbVmomi::VIM.connect(credentials); | |
datacenters = {}; | |
vim.rootFolder.childEntity.each { |datacenter| | |
datacenter_info = {} | |
datacenter.hostFolder.childEntity.each { |cluster| | |
cluster_info = {} | |
cluster.host.each { |host| | |
host_info = {} | |
host.config.network.vnic.each { |vnic| | |
vnic_info = {} | |
vnic_info[:portgroup] = vnic.portgroup | |
vnic_info[:dhcp_enabled] = vnic.spec.ip.dhcp | |
vnic_info[:ip_address] = vnic.spec.ip.ipAddress | |
vnic_info[:subnet_mask] = vnic.spec.ip.subnetMask | |
host_info[vnic.device.to_sym] = vnic_info | |
} | |
cluster_info[host.name.to_sym] = host_info | |
} | |
datacenter_info[cluster.name.to_sym] = cluster_info | |
} | |
datacenters[datacenter.name.to_sym] = datacenter_info | |
}; | |
datacenters |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
vnic_info.rb will generate a nested hash of datacenters, clusters, hosts & vnics like the following: