Topics


Blogs


Forums


Samples


Media


Labs


Resources

 




DevCentral > Weblogs > Jason Rahm - Jason's Blog
 Ruby iControl Wrapper
posted on Thursday, June 04, 2009 3:21 PM

DevCentral community user mkelly kicked in some excellent Ruby contributions a while back with some scripts that Colin wrapped  some documentation around in an article series back in January:

This week, another community member, josb, contributed a SOAP4R wrapper for iControl.  I'm not familiar at all with Ruby, but I downloaded the windows version of the language (sorry Colin), installed the SOAP4R gem, and tried out josb's scripts.  Here's one example:

GetPools.rb

#!/usr/bin/env ruby
# vim:expandtab shiftwidth=2 softtabstop=2

require 'f5'

Kernel.abort "Usage: #{$0} endpoint [poolname ...]" if ARGV.empty?

hostname, *pools = ARGV

lb = F5::LoadBalancer.new(hostname)
pools = pools.empty? ? lb.pools : pools.map {|pool| F5::LoadBalancer::Pool.new(lb, pool)}

pools.each do |pool|
  members = lb.pool(pool).members
  puts "Pool #{pool.name}: " + members.map {|member| "#{member.address}:#{member.port}"}.join(', ')
end

exit

 

And of course, the (sanitized) output:

Pool pool3: 10.10.40.57:80, 10.10.40.58:80, 10.10.40.59:80
Pool pool2: 10.10.40.54:80, 10.10.40.55:80, 10.10.40.56:80
Pool pool1: 10.10.40.51:80, 10.10.40.52:80, 10.10.40.53:80
Pool gateway_pool: 10.10.10.1:0
Pool cacti_ssh_rd1: 10.10.40.50:22, 10.10.40.50%1:22
Pool pool1_rd1: 10.10.40.51%1:80, 10.10.40.52%1:80, 10.10.40.53%1:80

Not too shabby!  Thanks, josb, for sharing with the community!  And community, josb is soliciting feedback, so please post if you want to assist in expanding / improving the project.

 

Follow me on Twitter Follow me on LinkedIn Follow me on Facebook Add to Technorati Favorites

 



 
      

Feedback


6/4/2009 5:02 PM
Gravatar Thanks Jason!

I just posted another small update which fixes a problem where I was inadvertently creating F5::IControl::Module instances over and over, plus a few other small tweaks. Please let me know how well it works for you.

Cheers,
Jos
Jos Backus

6/15/2009 12:20 PM
Gravatar hey Jos, thanks for providing the f5 ruby module, sleek.
Refering to, http://www.catnook.com/programs/f5-icontrol/
I was trying to test the sample code on my lab, couldn't figure out the below exception, or am i missing something. any help would be appreciated.

---------------------------------
[root@lab1 test]# ruby node-list.rb f5sf02.gid.gap.com
/usr/lib/ruby/1.8/soap/netHttpClient.rb:145:in `create_connection': Cannot connect to LocalLB.NodeAddress.wsdl (Not HTTP.) (RuntimeError)
from /usr/lib/ruby/1.8/soap/netHttpClient.rb:113:in `start'
from /usr/lib/ruby/1.8/soap/netHttpClient.rb:104:in `get_content'
from /usr/lib/ruby/1.8/wsdl/xmlSchema/importer.rb:64:in `fetch'
from /usr/lib/ruby/1.8/wsdl/xmlSchema/importer.rb:30:in `import'
from /usr/lib/ruby/1.8/wsdl/importer.rb:18:in `import'
from /usr/lib/ruby/1.8/soap/wsdlDriver.rb:124:in `import'
from /usr/lib/ruby/1.8/soap/wsdlDriver.rb:28:in `initialize'
from ./f5.rb:65:in `new'
from ./f5.rb:65:in `initialize'
from ./f5.rb:47:in `new'
from ./f5.rb:47:in `initialize'
from ./f5.rb:57:in `call'
from ./f5.rb:57:in `default'
from ./f5.rb:57:in `[]'
from ./f5.rb:57:in `method_missing'
from ./f5.rb:146:in `nodes'
from node-list.rb:11
---------------------------------
tester1

6/16/2009 12:23 PM
Gravatar A few questions:

- What version of Ruby?
- What version of SOAP4R? This will only work with 1.5.8 because that version introduces the endpoint_url method on the RPC driver my code uses.
Your backtrace suggests that you are using a different version.
- What does your (password-sanitized) config.yaml look like? Specifically, are the WSDL files where the config.yaml file says they are?

Jos
Jos Backus

6/18/2009 11:32 AM
Gravatar Jos, thanks for the feedback, i've corrected the wsdl path with full url and resolved the above error, now i am trying to resolve the below ssl verification error.
----------------------------------------------------------------
[root@lab1 test]# ruby getpools.rb testf5 -v
cacerts: /usr/lib/ruby/gems/1.8/gems/httpclient-2.1.5/lib/httpclient/cacert.p7s loading failed
at depth 0 - 18: self signed certificate
/usr/lib/ruby/gems/1.8/gems/httpclient-2.1.5/lib/httpclient/session.rb:247:in `connect': certificate verify failed (OpenSSL::SSL::SSLError)
from /usr/lib/ruby/gems/1.8/gems/httpclient-2.1.5/lib/httpclient/session.rb:247:in `ssl_connect'
from /usr/lib/ruby/gems/1.8/gems/httpclient-2.1.5/lib/httpclient/session.rb:639:in `connect'
from /usr/lib/ruby/gems/1.8/gems/httpclient-2.1.5/lib/httpclient/timeout.rb:128:in `timeout'
from /usr/lib/ruby/gems/1.8/gems/httpclient-2.1.5/lib/httpclient/session.rb:631:in `connect'
from /usr/lib/ruby/gems/1.8/gems/httpclient-2.1.5/lib/httpclient/session.rb:522:in `query'
from /usr/lib/ruby/gems/1.8/gems/httpclient-2.1.5/lib/httpclient/session.rb:147:in `query'
from /usr/lib/ruby/gems/1.8/gems/httpclient-2.1.5/lib/httpclient.rb:953:in `do_get_block'
from /usr/lib/ruby/gems/1.8/gems/httpclient-2.1.5/lib/httpclient.rb:765:in `do_request'
... 16 levels...
from ./f5.rb:56:in `method_missing'
from ./f5.rb:144:in `initialize'
from getpools.rb:10:in `new'
from getpools.rb:10
----------------------------------------------------------------

from one of the ruby threads, looks like though the code has "verify_mode = OpenSSL::SSL::VERIFY_NONE" it may not work on the ruby versions above 1.8.5.

below is the list of versions on my test system.
-----------------------------------------------
[root@lab1 test]# rpm -qa | grep ruby
ruby-rdoc-1.8.6.287-2.fc10.i386
ruby-1.8.6.287-2.fc10.i386
ruby-libs-1.8.6.287-2.fc10.i386
rubygems-1.3.1-1.fc10.noarch
ruby-irb-1.8.6.287-2.fc10.i386
[root@lab1 test]# gem list --local

*** LOCAL GEMS ***

httpclient (2.1.5)
soap4r (1.5.8)
------------------------------------

i will try with ruby 1.8.5 and possibly lower the version of httpclient gem, see if i get any luck. do you happen to have similar issue?
tester1

6/19/2009 2:34 PM
Gravatar I use the same 1.8.6 version and haven't had any issues.

ruby 1.8.6 (2008-08-11 patchlevel 287) [i686-linux]

I do notice I use httpclient 2.1.4. Can you try that version please?

Jos
Jos Backus

6/21/2009 2:54 PM
Gravatar Jos,

it worked, by changing the wsdl path in the config.yaml to have local path or http path, as https path doesn't work.

partial config.yaml before
--------------------------
node_address: https://f5test/iControl/iControlPortal.cgi?WSDL=LocalLB.NodeAddress.wsdl

after
------
node_address: http://192.168.0.60/ic/sdk/wsdl/LocalLB.NodeAddress.wsdl


-----

I tried, httpclient 2.1.3, 2.1.4, 2.1.5.1. and ruby 1.8.4, had the same ssl verify error.

now its back on ruby-1.8.6 with httpclient 2.1.5.

edited the file /usr/lib/ruby/gems/1.8/gems/httpclient-2.1.5/lib/httpclient/ssl_config.rb and updated the line number 79 to have the verify_mod just "SSL:VERIFY_NONE".

it passed that ssl verify error but the new one popped up saying "unexpected message" .... "Authorization required".

Assumed the code doesn't support the wsdl path to be https with authentication, and changed the wsdl path, now all good.
tester1

6/22/2009 11:20 AM
Gravatar That's correct. This is why I use local copies of the WSDL files. Glad to hear it's working now.

Let me know if you see any other issues, and thanks for the feedback.

Jos
Jos Backus

7/21/2009 8:06 PM
Gravatar Hello, Where do I get this wrapper code

Is the below part of iControl SDK?

----
require 'f5'
----
Steve

7/21/2009 9:25 PM
Gravatar It's linked in the post, though it looks like the site is not working. I posted in the forum for a good location for the files, here's the thread:

http://devcentral.f5.com/Default.aspx?tabid=53&forumid=1&tpage=1&view=topic&postid=57673
Jason Rahm

7/23/2009 3:36 PM
Gravatar The site has been fixed.
Jos Backus

2/24/2010 8:10 AM
Gravatar Hil the site no longer contains the files, anyone know where to get them?
Nick
 Leave Feedback
Title  
Name  
Email
Url
Comments   
Please add 1 and 7 and type the answer here: