Skip to content

Instantly share code, notes, and snippets.

@archanasingh
Forked from rubiojr/rbvmomi_example1.rb
Created June 29, 2011 20:03
Show Gist options
  • Save archanasingh/1054790 to your computer and use it in GitHub Desktop.
Save archanasingh/1054790 to your computer and use it in GitHub Desktop.
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
# find VM by name, returns VirtualMachine
# http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.VirtualMachine.html
vm = dc.find_vm 'Nexus1000V-4.2.1.SV1.4'
# retrieve VM config info
# http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.vm.ConfigInfo.html
config = vm.config
# List all VM names
vm = dc.vmFolder.childEntity.grep(RbVmomi::VIM::VirtualMachine).find do |x|
puts x.name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment