Showing results for 
Search instead for 
Did you mean: 

Tech Tip: Ruby and SOAP - a rubygems implementation

This article presents an alternative approach to the document Tech Tip: Using the SOAP Control API with Ruby.

One of our partners (David Peterson) started a project to create a Control API bunding for Ruby. It's a work in progress (methods will be added as needed), but is a great starting point if you need to build a Control API client using Ruby.

You'll find the project here:, and published through RubyGems.

To get started:

$ sudo gem install zeus-api

Sample code

The included simple.rb is a good place to start. It illustrates how to:

  • List virtual servers, pools and rules
  • Create a new pool containing the provided node list
  • Create a virtual server
  • Create a rule, including parsing the validation response (as rules may have syntax errors)
  • Bind the rule to the virtual server

require 'rubygems'

require 'zeus-api'

endpoint = "https://stingray:9090/soap"

username = "api"

password = "api"

vs =, username, password)

p =, username, password)

r =, username, password)

# basic config

vs_name = "test"

pool_name = "test-pool"

pool_nodes = ["", ""]

rule_name = "test-rule"

# delete if existing

if vs.list.include?(vs_name)


  puts "Found existing virtual server '#{vs_name}', deleting ..."


if p.list.include?(pool_name)


  puts "Found existing pool '#{pool_name}', deleting ..."


if r.list.include?(rule_name)


  puts "Found existing rule '#{rule_name}', deleting ..."


# create pool

pool_nodes = ["", ""]

p.create(pool_name, pool_nodes)

puts "Pool '#{pool_name}' was successfully created."

# create a new virtual server

vs_info = {

  Smiley Tonguerotocol => "http",

  Smiley Tongueort => "8000",

  :default_pool => pool_name


vs.create(vs_name, vs_info)

puts "Virtual server '#{vs_name}' was successfully created."


puts "Virtual server '#{vs_name}' was enabled."

# create a new rule and add to virtual server

rule_text = "

     if( string.contains( http.getheader( 'Host' ), '' ) ){

        pool.use( 'test-pool' );


rule_note = "Simple Host header dispatch rule using trafficscript"

if (r.valid?(rule_text))

  r.create(rule_name, rule_text)

  r.note(rule_name, rule_note)


  puts "Error! Rule '#{rule_name}' failed validation!"

  puts "Errors: #{r.errors}"

  puts "Warnings: #{r.warnings}"


vs.add_request_rule(vs_name, rule_name)

puts "Rule '#{rule_name}' added to virtual server '#{vs_name}'."

Read more

Version history
Revision #:
1 of 1
Last update:
‎02-25-2013 07:38:AM
Updated by:
Labels (1)