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!
- John_AllenAltostratusWindows Installs:
- George_Watkins_Historic F5 AccountHi John,
- Just installed on my Mac with the default ruby install already on there and it's working great! No other gem's were needed! Can't wait to start playing with it.
- benjamin_indermNimbostratusthe link to the ruby gem is dead
- benjamin_indermNimbostratusRHEL is using the Ruby version 1.8.5
- Steven_Wagner_1NimbostratusI just got bitten by that same "only numbers in the gemspec" issue whilst developing on RHEL 5.5...
- George_Watkins_Historic F5 AccountHi Benjamin and Steven,
- George_Watkins_Historic F5 AccountVersion 10.2.0.2 of the Ruby iControl library is now available: https://devcentral.f5.com/s/articles/icontrol-ruby-library-updated-to-v10202
- John_AllenAltostratusRevised link for what George posted above: https://devcentral.f5.com/s/articles/automating-web-app-deployments-with-opscode-chef-and-icontrol
- Tom_Duckering_9NimbostratusHi - 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.