Skip to content

Instantly share code, notes, and snippets.

@endzyme
Created June 11, 2013 01:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save endzyme/5753795 to your computer and use it in GitHub Desktop.
Save endzyme/5753795 to your computer and use it in GitHub Desktop.
F5 Load Balancer SOAP API Interactions with Savon

SOAP Calls

Get Heartbeat String

Connection

soap = 
  Savon.client do |s|
    s.wsdl "https://#{ipaddress}/iControl/iControlPortal.cgi?WSDL=LocalLB.Monitor"
    s.basic_auth [user, password]
    s.ssl_verify_mode :none
    s.endpoint "https://#{ipaddress}/iControl/iControlPortal.cgi"
    s.namespace 'urn:iControl:LocalLB/Monitor'
    s.env_namespace :soapenv
    s.namespace_identifier :mon
    s.raise_errors false
  end

Call

r = 
    soap.call :get_template_string_property, {
        :message => {
            "template_names" => {
                :item => ['TEST-www-heartbeat-443']
            }, 
            "property_types" => {
                :item => ['STYPE_SEND']
            }
        }
    }

# Return
data = r.to_array :get_template_string_property_response, :return, :item
# => [{:type=>"STYPE_SEND", :value=>"GET /www/heartbeat\\r\\n"}]

Available String Types

  • STYPE_SEND
  • STYPE_RECEIVE
  • STYPE_RECEIVE_DRAIN (Error to drain)

Set the Heartbeat Strings

Call

r = 
    soap.call :set_template_string_property do |s|
      s.message "template_names" => {:item => ['TEST-www-heartbeat-443']}, 
                "values" => {
                    :item => [
                        :type => ['STYPE_SEND'],
                        :value => ['GET /www/heartbeat\r\n']
                    ]
                }
    end

# Return
r.succuess?
# => true

Force Member Pool Offline

Connection to LocalLB/PoolMember

soap =
  Savon.client do |s|
    s.wsdl "https://#{ipaddress}/iControl/iControlPortal.cgi?WSDL=LocalLB.PoolMember"
    s.basic_auth [user, password]
    s.ssl_verify_mode :none
    s.endpoint "https://#{ipaddress}/iControl/iControlPortal.cgi"
    s.namespace 'urn:iControl:LocalLB/PoolMember'
    s.env_namespace :soapenv
    s.namespace_identifier :pool
    s.raise_errors false
  end

Call Example (I prefer to start using block format for ease of reading. Too many inset hashes.)

r = 
    soap.call :set_monitor_state do |s|
      s.message 'pool_names' => {:item => ['my-pool-name']},
                'monitor_states' => {
                    :members => [{
                        :items => {
                            :member => {:address => '192.168.197.27', :port => 443},
                            'monitor_state' => 'STATE_ENABLED'
                        }
                    }]
                }
    end
    
# return
r.success?
# => true

Available 'monitor_state' Values

  • STATE_ENABLED
  • STATE_DISABLED

XML Example (soapui)

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pool="urn:iControl:LocalLB/PoolMember" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
  <soapenv:Header/>
  <soapenv:Body>
    <pool:set_monitor_state soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <pool_names xsi:type="urn:Common.StringSequence" soapenc:arrayType="xsd:string[]" xmlns:urn="urn:iControl">
        <item>my-pool-name</item>
      </pool_names>
      <monitor_states xsi:type="urn:LocalLB.PoolMember.MemberMonitorStateSequenceSequence" soapenc:arrayType="urn:LocalLB.PoolMember.MemberMonitorStateSequence[]" xmlns:urn="urn:iControl">
        <members>
          <item>
            <member>
              <address>192.168.197.237</address>
              <port>443</port>
            </member>
            <monitor_state>STATE_ENABLED</monitor_state>
          </item>
        </members>
      </monitor_states>
    </pool:set_monitor_state>
  </soapenv:Body>
</soapenv:Envelope>

Get Members

Connection to LocalLb/Pool

soap =
  Savon.client do |s|
    s.wsdl "https://#{ipaddress}/iControl/iControlPortal.cgi?WSDL=LocalLB.Pool"
    s.basic_auth [user, password]
    s.ssl_verify_mode :none
    s.endpoint "https://#{ipaddress}/iControl/iControlPortal.cgi"
    s.namespace 'urn:iControl:LocalLB/Pool'
    s.env_namespace :soapenv
    s.namespace_identifier :pool
    s.raise_errors false
  end

Call

r = 
    soap.call :get_member, {:message => {"pool_names" => {:item => ['my-pool-name']}}}

# return 
r.to_array(:get_member_response, :return, :item)
# => [{:item=>[{:address=>"192.168.195.182", :port=>"443"}, {:address=>"192.168.197.237", :port=>"443"}], :"@a:array_type"=>"iControl:Common.IPPortDefinition[2]"}]

XML Example (soapui)

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pool="urn:iControl:LocalLB/Pool" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
   <soapenv:Header/>
   <soapenv:Body>
      <pool:get_member soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <pool_names xsi:type="urn:Common.StringSequence" soapenc:arrayType="xsd:string[]" xmlns:urn="urn:iControl">
           <item>my-pool-name</item>
         </pool_names>
      </pool:get_member>
   </soapenv:Body>
</soapenv:Envelope>
@gdlx
Copy link

gdlx commented Oct 17, 2013

Hi,

Which BigIP version did you use these scripts on ?

I tried on 11.1 and 11.4 without any success.

On any module/method, I get a Unknown method error...

@berlincount
Copy link

Same here.

@accidentaldevelopment
Copy link

Looks like the new(ish) version of savon defaults to converting method names to camelCase. Try adding

   s.convert_request_keys_to :none

To the Savon.client block above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment