Skip to content

Instantly share code, notes, and snippets.

@stevenbryen
Created June 16, 2012 21:47
Show Gist options
  • Save stevenbryen/2942603 to your computer and use it in GitHub Desktop.
Save stevenbryen/2942603 to your computer and use it in GitHub Desktop.
Simple Ruby Interface for vCenter Orchestrator
class VCO
#Require the Following Ruby Gems
require "rubygems"
require "savon"
require "ostruct"
#Set the Attributes
attr_writer :vcoHostName, :username, :password
def executeWfl(workflowName, workflowInputs)
vcoWsdl = "http://" + @vcoHostName + ":8280/vmware-vmo-webcontrol/webservice?WSDL"
client = Savon.client(vcoWsdl)
#Call vCO API getWorkflowsWithName Method on the Workflow Name Provided
response = client.request :get_workflows_with_name, :body => { :name => workflowName, :username => @username, :password => @password}
#Convert the Response to a Hash and then get the Workflow ID from that Hash (ID Is needed to Execute the Workflow)
response = response.to_hash
response = OpenStruct.new response
response = response.get_workflows_with_name_response
response = OpenStruct.new response
response = response.get_workflows_with_name_return
response = OpenStruct.new response
workflowId = response.id
#Call the API Again to Execute the Workflow
secondResponse = client.request :execute_workflow, :body => { :workflow_id => workflowId, :username => @username, :password => @password, :workflow_inputs => workflowInputs}
end
end
#Create a new vcoServer Object and Set the Hostname, Username and Password.
vcoServer = VCO.new
vcoServer.vcoHostName = "172.16.253.136"
vcoServer.username = "vcoadmin"
vcoServer.password = "vcoadmin"
#Workflow Inputs need to be passed as an array of hashes. All vCO Workflow Input hashes have the following 3 keys name,type and value.
workflowInputs = [{:name => "firstName", :type => "String", :value => "Hello"}, {:name => "lastName", :type => "String", :value => "API"}]
#Execute the Workflow by passing the Workflow Name and the Input Parameters
vcoServer.executeWfl("helloapi", workflowInputs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment