pages

Friday, May 4, 2012

ruby - SOAP access with savon

The last three days I played around with ruby and learned a lot of things (a big thanks to Marius). When practicing some basic functionalities (tryruby.org) I decide to check if I can connect to the SOAP interface of the vCenter Orchestrator. Yes, SOAP, it´s old school :)

First you need to install a new gem called savon to enable ruby as a SOAP client. After that the require 'savon' loads the gem.

Now here is an example to get some vCenter Orchestrator workflows:


require 'savon'


Savon.configure do |config|
  config.log = false         
end


client = Savon::Client.new do
 wsdl.document = "http://10.4.13.15:8280/vmware-vmo-webcontrol/webservice?wsdl"
end
user = "YourUser"
pass = "YourPass"


def findWorkflow(wfName, client,user,pass)
 response = client.request :get_workflows_with_name do
  soap.body = { workflowName: wfName, username: user, password: pass }
 end
 return response
end


def getAllWfs(client,user,pass)
 response = client.request :get_all_workflows do
  soap.body = { username: user, password: pass}
 end
 return response
end


def getAllWfInfos(allWfs)
 allWfs[:get_all_workflows_response][:get_all_workflows_return].each do |wf|
  wf.each { |x| x.each { |y| p y } }
 end
end


myWfs = getAllWfs(client)
wfInfos = getAllWfInfos(myWfs)



This code produces the following output:
















So maybe this helps you to play around with ruby and some SOAP operations. Hopefully I will find some time to consume the REST API of the vCloud Director and show you some examples :)


No comments:

Post a Comment