Created
June 1, 2011 09:52
-
-
Save rubiojr/1002056 to your computer and use it in GitHub Desktop.
ruby vmware vsphere api example 1
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 '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