Getting Started With Ruby and iControl

Here on DevCentral we’ve released libraries for a number of the big languages from Java and Perl to Powershell. Up until now there has not been much love for Ruby. Well, that’s all about to change: enter the new iControl Ruby Library. This project is a work in progress and the library is a mere 48 lines long as of this initial release. There will be many more features along with more example code coming in the near future.

The first set of installation instructions only cover the most recent Ubuntu release: Lucid 10.04, but should segue well with any distribution that has Ruby 1.8.6 or newer and RubyGems 1.2 or better. In addition to Ruby and Gems, you will also need the Ruby OpenSSL libraries and HTTPClient 2.1.5.2 or newer. Please feel free to test this code on as many other distributions and operating systems as you can and post your feedback in the iControl Ruby Library forum. We will do our best to get your change requests heard and rolled into the next release. Without further ado, let’s get started.

Installing The Ruby iControl Libraries

This installation assumes you are starting with a fresh Ubuntu Lucid (10.04) install.

1. Install the Ruby, Ruby Gems, and Ruby OpenSSL libraries

apt-get install ruby rubygems libopenssl-ruby

3. Download the iControl Ruby Library Gem

4. Install the iControl Gem

gem install f5-icontrol-10.2.0.gem

5. Run one of the example files (located in /var/lib/gems/1.8/gems/f5-icontrol-10.2.0.a.1/examples/ if installed as ‘root’)

ruby get_version.rb 192.168.1.245 admin admin
   => BIG-IP_v10.1.0

Installation Notes for Older Distributions

The age of the distribution does not matter nearly as much as the version of Ruby and RubyGems. If your Gems installation is too old you will get an “HTTP Response 302” and an error when trying to perform any remote actions. Ubuntu namely has not updated any of the RubyGems packages for Hardy (and older releases). As such you will see this error when trying to install iControl Ruby Library because Gems will try to remotely retrieve HTTPClient. If you are stuck using an older distribution we would suggest that you remove the old version of RubyGems and install a newer version (v1.4.1 as of this writing) manually. Instructions for manually installing RubyGems can be found on their download page.

Alternatively, the HTTPClient gem could be retrieved manually and installed locally prior to the iControl Ruby Library.

Example Code

There are currently two pieces of sample code included with this release: create-http-virtual-and-pool.rb and get-version.rb. The ‘create-http-virtual-and-pool.rb’ script will create HTTP pool with a number of members and an associated SNAT automapped HTTP virtual server. Take a look at this code if you are looking for reference on the syntax of complex types in iControl. We will be posting a full tech tip on understanding complex types in the near future, but this should get you started. The ‘get-version.rb’ script is rather simple and does exactly what it says: gets the version of the target BIG-IP. There will be many more pieces of example code coming shortly. More information on syntax and types can be found in the iControl SDK documentation.

Versioning

Contained within the Gem is the iControl Ruby Library and the WSDLs for the most recent iControl SDK (currently v10.2.0). In order to keep things consistent, the first three numbers in the version correspond iControl SDK version that provided the WSDLs. The next ‘a’ signifies that this is an ‘alpha’ release, which will be dropped in subsequent releases. Lastly, the final number signifies the build number supplied by our local repository. Eventually when we deem the library stable, the version number will look something like v11.2.1.678, meaning that this future release was built using WSDLs from the version 11.2.1 iControl SDK and has a build number of 678.

Conclusion

Please keep in mind that this is our first ‘stab’ at an in-house iControl Ruby library and as such this is not by any means a finished product. There are a number of features we would like to add, but we wanted to start receiving your feedback as soon as possible. We feel that there is a lot of upward potential for this project and need your help and feedback to get it moving. We hope this will help all the Ruby shops out there finally start integrating iControl into their applications. Until next time, happy coding!

Published Jan 07, 2011
Version 1.0
  • Hi - I'm having trouble listing things. I know I have virtual servers in my BIG IP but when I ask for a list via LocalLB.VirtualServers.get_list I get zero length array returned.

     

     

    Have I missed something stupid?
  • Tom, are you using admin partitions on your LTM to section off configuration objects? If so, iControl defaults to the "/Common" partition. You'll need to change the "active" partition in your client code before making the get_list() call. I went over this a bit in this article:

     

     

    https://devcentral.f5.com/s/articles/icontrol-101-08-partitions

     

     

    -Joe
  • George_Watkins_'s avatar
    George_Watkins_
    Historic F5 Account
    Tom,

     

     

    Give this a shot:

     

     

     

     

    bigip = F5::IControl.new('test-ltm-01', 'admin', 'admin', ['LocalLB.VirtualServer']).get_interfaces

     

    bigip['LocalLB.VirtualServer'].get_list

     

     

    That returns ["/Common/ELN_Remote_Access_vs", "/Common/ELN_Remote_Access_vs_redirect", "/Common/test-vs-01"] for me.

     

     

    Hope that helps,

     

     

    George

     

  • I had to patch the file lib/f5-icontrol.rb in order to make it work for me:

     

    - It lacked the usage of the http_proxy I configured in my env, fixed by:

     

    ----------------------

     

    @proxy = ENV['https_proxy'] in initialize()

     

    ----------------------

     

    - The endpoint_url wasn't constructed the right way:

     

    https://213.71.15.10//iControl/iControlPortal.cgi

     

    makes the F5 do respond with a 302 (redirect) to the location "/tmui/login.jsp" which results in this error:

     

    ----------------------

     

    /usr/lib/ruby/gems/1.8/gems/httpclient-2.2.5/lib/httpclient/util.rb:117:in `https?': undefined method `downcase' for nil:NilClass (NoMethodError)

     

    from /usr/lib/ruby/gems/1.8/gems/httpclient-2.2.5/lib/httpclient/session.rb:738:in `connect'

     

    ----------------------

     

     

    This diff addresses both problems:

     

    ----------------------

     

    --- /tmp/f5/lib/f5-icontrol.rb 1970-01-01 01:00:00.000000000 +0100

     

    +++ lib/f5-icontrol.rb 2012-06-13 12:20:11.369138428 +0200

     

    @@ -14,6 +14,7 @@

     

    @wsdls = wsdls

     

    @endpoint = '/iControl/iControlPortal.cgi'

     

    @interfaces = {}

     

    + @proxy = ENV['https_proxy']

     

    end

     

     

    def get_interfaces

     

    @@ -25,10 +26,11 @@

     

    @interfaces[wsdl] = SOAP::WSDLDriverFactory.new('file://' + wsdl_path).create_rpc_driver

     

    @interfaces[wsdl].options['protocol.http.ssl_config.verify_mode'] = OpenSSL::SSL::VERIFY_NONE

     

    @interfaces[wsdl].options['protocol.http.ssl_config.verify_callback'] = lambda{ |arg1, arg2| true }

     

    + @interfaces[wsdl].options['protocol.http.proxy'] = @proxy if !@proxy.nil?

     

     

     

    - @interfaces[wsdl].options['protocol.http.basic_auth'] << ['https://' + @hostname + '/' + @endpoint, @username, @password]

     

    - @interfaces[wsdl].endpoint_url = 'https://' + @hostname + '/' + @endpoint

     

    + @interfaces[wsdl].options['protocol.http.basic_auth'] << ['https://' + @hostname + @endpoint, @username, @password]

     

    + @interfaces[wsdl].endpoint_url = 'https://' + @hostname + @endpoint

     

    end

     

    end

     

    ----------------------
  • I get an ERROR message when running the examples scripts.

     

     

    /usr/lib64/ruby/gems/1.8/gems/httpclient-2.3.2/lib/httpclient/session.rb:803:in `initialize': Connection refused - connect(2) (://:0) (Errno::ECONNREFUSED)

     

     

    I can see that there is traffic going to and from my F5 BigIP device, therefore I dono think this is a firewall issue. If I telnet over port 443 it works.

     

     

    any ideas what could be wrong??

     

    Thanks!