pages

Showing posts with label SOAP client. Show all posts
Showing posts with label SOAP client. Show all posts

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 :)


Monday, February 27, 2012

vCO - want fast success? use python!


As you may know I´m always interested in finding new methods to make vCO available in the most common programming languages. Last week some guys developed their web service client in python using the outstanding PyvCO module: http://labs.vmware.com/flings/pyvco

I see their fast and impressive results which took them just a few days and decided to take a look into python using "native" SOAP clients. After reading thru some available modules I decide to use suds: https://fedorahosted.org/suds/ because it seems to have a simple design.

After installing the module on my MacBook with pip install suds the first test is really simple:

import suds
client = suds.client.Client('http://172.16.0.176:8280/vmware-vmo-webcontrol/webservice?wsdl')
print client

This is the output:














As you can see all methods and types are shown with a simple print :)

Based on this and some indents you can produce some real nice functions like this:
import suds

vCOurl = 'http://172.16.0.176:8280/vmware-vmo-webcontrol/webservice?WSDL'
#username = raw_input('Username: ')
#password = raw_input('Password: ')
username = 'USERNAME'
password = 'PASSWORD'

client = suds.client.Client(vCOurl)
#print client

def getAllWfs():
 allWfs = client.service.getAllWorkflows(username, password)
 return allWfs

def findWfs(name):
 Wfs = client.service.getWorkflowsWithName(name, username, password)
 return Wfs

#allWfs = getAllWfs()
allWfs = findWfs(raw_input('Workflow name: '))

for wf in allWfs:
   print wf.name
   print wf.id
   wfInParas = wf.inParameters
   for iParas in wfInParas[0]:
        print 'inParameter: '
        print (iParas.name, iParas.type)
   wfOutParas = wf.outParameters
   for oParas in wfOutParas[0]:
        print 'outParameter: '
        print (oParas.name, oParas.type)

With this you can search for a workflow and get the IN/OUT parameters. As you can see the success comes really fast!









So feel free to post your implementations!