WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Uncategorized / Exploring the vCloud API Using Ruby

Exploring the vCloud API Using Ruby

02.21.2013 by William Lam // 2 Comments

While working on something that was completely random, I started to play around a bit with the Ruby programming language. I had a few questions and I reached out to a buddy of mine who is Ruby developer and in doing so I was introduced to a very cool Ruby gem called HTTParty. For those of you who are not familiar with Ruby gems, it is a packaged library or application for Ruby, similar to an rpm or pkg file. The neat thing about HTTParty is that it makes working with REST APIs extremely easy and processing XML request/responses into Ruby objects without too much effort.

With the bit of knowledge I gained from my buddy, I wanted to see how easy it would be to apply this to the vCloud API using Ruby and HTTParty. To my surprise, it was actually pretty easy!

Disclaimer: I am not a developer nor even a Ruby novice. This is probably the second or third time I have used Ruby.

Before getting started, you will need to have the following installed on your system:

  • ruby (I used the latest release which is 1.9.3)
  • ruby gem
  • httparty
  • xml-fu 
  • yaml

The following vCloud APIs are implemented in the sample below:

  • Query Service API for looking up vCloud vApps
  • PowerOn vApp
  • PowerOff vApp
  • Shutdown vApp
  • Suspend vApp
  • Reset vApp
  • Create Snapshot for vApp
  • Remove Snapshot for vApp

To demonstrate the use of Ruby & HTTParty, I created a very simple Ruby script called vcd.rb which primarily deals with vApp operations.

To use the script, you will need to create a file called config-vcd.yml which contains the credentials to your vCloud Director instance. Here is what the file should look like:

:username: administrator@system
:password: supersecretpassword
:site: https://vcd.primp-industries.com

Note: This example assumes you are running vCloud Director 5.1 (but sample can be modified to support 1.5)

Here is an example of listing all vApps for the given Organization you are logging into:

Here is an example of listing a specific vApp:

Here is an example of performing several operations on the vApp:

At the end of this little exercise, I was pretty impressed at how easy it was to work with REST APIs using Ruby and HTTParty. I think the toughest part for me personally was getting used to Ruby's syntax which I was not familiar with. I also extended this exercise to the vCloud Networking and Security REST APIs which I will share in another blog post.

Useful Resources:

  • http://www.railstips.org/blog/archives/2008/07/29/it-s-an-httparty-and-everyone-is-invited/
  • http://blogs.vmware.com/vsphere/2012/03/exploring-the-vcloud-rest-api-part-1.html
  • http://blogs.vmware.com/vsphere/2012/03/exploring-the-vcloud-rest-api-part-2.html

 

More from my site

  • Exploring the vCloud Networking & Security API Using Ruby
  • How to Access vCloud Director Remote Console using vCloud & VMRC API
  • How To Run The SilverLining Fling Without Installing It In vCloud Director
  • vCloud Director Simulator
  • Nested Virtualization APIs For vSphere & vCloud Director 5.1

Categories // Uncategorized Tags // httparty, REST API, ruby, vcloud api, vcloud director, vcloud director 5.1

Comments

  1. *protectedSimon Fredsted says

    05/01/2014 at 10:30 am

    If you can't find the vcd.rb script, it's because it's moved to Github. The URL is: https://github.com/lamw/vghetto-scripts

    Reply

Trackbacks

  1. vCHS Monitoring and Capacity Management 101 – the Practice « IT 2.0 says:
    04/18/2014 at 10:17 am

    […] Lam, because my ruby script hasn't been written from scratch and we all stand on the shoulders of […]

    Reply

Thanks for the comment!Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025