Ruby to Manage and Automate VMware vSphere?

As I mentioned in a previous blog, vSphere(VI) Java API can be used in any JVM languages/frameworks. We have samples in Jython, Groovy, Grail. This weekend I got a sample in JRuby shared by our community member Martin Jackson in the API forum. Thanks Martin!

I think it would be fun to share it with you. If you can write Ruby code, you can take advantage of VI Java API for managing and automating vSphere as well. If you have samples leveraging the API to share, I am happy to hear about it.

Bothered by SLOW Web UI to manage vSphere? Want to manage ALL your VMware vCenters, AWS, Azure, Openstack, container behind a SINGLE pane of glass? Want to search, analyze, report, visualize VMs, hosts, networks, datastores, events as easily as Google the Web? Find out more about vSearch 3.0: the search engine for all your private and public clouds.

Now, let us take a look at Martin’s sample code ported from a VI Java API sample.

#  VI Java API Hello using JRuby
require 'java'
require 'dom4j-1.6.1.jar'
require 'vijava2120100824.jar'

# Only using a single class from this package so I'll just import it
import java.net.URL
# Creating ViJava Module so I don't have to import each com.vmware.vim25.mo class individually.
module VIJava
  include_package "com.vmware.vim25.mo"
end

si = VIJava::ServiceInstance.new(URL.new("https://192.168.1.9/sdk"), "root", "password", true)
rootFolder = si.getRootFolder() vms = VIJava::InventoryNavigator.new(rootFolder).searchManagedEntities("VirtualMachine")
puts "Hello " + vms[0].getName()

si.getServerConnection().logout()

This entry was posted in vSphere API and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Trackback

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  • NEED HELP?


    My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__ doublecloud.org.

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.