Skip to content

Instantly share code, notes, and snippets.

@Maka7veli
Maka7veli / rbvmomi_example1.rb
Created January 13, 2017 21:12 — forked from archanasingh/rbvmomi_example1.rb
ruby vmware vsphere api example 1
require 'rubygems'
require 'rbvmomi'
vim = RbVmomi::VIM.connect :host => '10.60.1.71', :user => 'root', :password => 'temporal', :insecure => true
# get current time
vim.serviceInstance.CurrentTime
# get datacenter
dc = vim.serviceInstance.find_datacenter
$sql = "select abc.vm_name as vm_name, abc.vm_dns_name as vm_dns_name, abc.ip_addresses as ip_address, abc.dns_ip_address as dns_ip_address, abc.network_address as network_address, group_concat(vlan SEPARATOR ' ; ') as vlan, group_concat(mac_address SEPARATOR ' ; ') as mac_address, group_concat(hdd SEPARATOR ' ; ') as hdd, cpu, memory, os, owner, vcenter_name, datastore_name, cluster_name, hypervisor_name
from (
SELECT distinct group_concat(b.ip_address SEPARATOR ' ; ') as ip_addresses,
group_concat(b.vm_dnsname_ip SEPARATOR ' ;') as dns_ip_address,
a.vm_name, a.id ,a.vm_serial, a.vm_dns_name, a.vcenter_id, a.datastore_id, a.cluster_id, a.hypervisor_id,
group_concat(b.network_address SEPARATOR ' ;') as network_address
FROM vm a, ip_address b , vcenter h
WHERE a.vcenter_id = h.id
and a.id =