Quick thoughts on IT, fun projects, and the singularities I come across.

Querying vCloud Director API with Ruby Script

Well it’s been awhile since I’ve posted since I started working on HireUpJob, but this one’s good. I recently had a use case where I needed to get the virtual hardware version of a client machine provisioned through vCloud Director. Now, that information is not accessible anywhere on the client machine, so I had to look to the vCloud Director API for it. The process for querying the API also had to be automated for future provisions, so it had to be scripted. Enough back story and context, lets look at the ruby code.

If you’re using my code more or less verbatim and everything executes properly, you should get a simple “true” or “false” as output. Now, this script is for a fairly specific use case, but I think the real potential value here is to use this enable Opscode Chef (written in Ruby) to communicate with vCloud Director. I’ll be sure to post again as I develop some use cases.

In case you have a very different use case but need some help, here are some of the pages I referred to for writing this script:

Hope this helps some of you out there and let me know if you have any questions.

 

Social tagging: > > > > > >

2 Responses to Querying vCloud Director API with Ruby Script

  1. zelig8 says:

    Hi Alex – thanks for this! I found that needed to make a change where you set the accept headers for the post, specifically the req.add_field had to change so that the first param was ‘Accept’, and the second ‘:application/*+xml;version5.1′. I am using vCD 5.1, don’t know if that has any impact here, but the : needed to be in the second param. Until i made that change, i got a 406 response code.

    • AlexDGlover says:

      Hey zelig8 – thanks for the comment. We are also running 5.1, and I’ve been using this code relatively recently so not sure what the problem is. I’ll look into the 406 response code and see if I can come up with any explanation. In the meantime, glad you got it fixed and are enjoying the script.

Leave a Reply