Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # nodes-per-pool
- #!/usr/bin/env ruby
- # vim:expandtab shiftwidth=2 softtabstop=2
- require 'icontrol'
- Kernel.abort "Usage: #{$0} endpoint [poolname ...]" if ARGV.empty?
- endpoint, *pools = ARGV
- lb = IControl.new(endpoint)
- (pools.empty? ? lb.pool.get_list : pools).each do |pool|
- members = lb.pool.get_member(pool).first
- puts "Pool #{pool}: " + members.map {|member| "#{member.address}:#{member.port}"}.join(', ')
- end
- exit
- # icontrol.rb
- # vim:expandtab shiftwidth=2 softtabstop=2
- require 'rubygems'
- require 'soap/wsdlDriver'
- class IControl
- def initialize(endpoint, config_file='config.yaml')
- begin
- configuration = YAML::load_file(config_file)
- rescue Exception => exc
- raise "error loading configuration from '#{config_file}': #{exc.message}"
- end
- @wsdl = configuration['wsdl']
- username = configuration['username']
- password = configuration['password']
- method = 'https'
- endpoint_url = "#{method}://#{endpoint}/iControl/iControlPortal.cgi"
- basic_auth = [endpoint_url, username, password]
- @driver = Hash.new {|hsh, key|
- hsh[key] = SOAP::WSDLDriverFactory.new(@wsdl[key.to_s]).create_rpc_driver
- verify_mode = OpenSSL::SSL::VERIFY_NONE
- hsh[key].options['protocol.http.ssl_config.verify_mode'] = verify_mode
- hsh[key].options['protocol.http.ssl_config.verify_callback'] = lambda {|is_ok, ctx| true}
- hsh[key].options['protocol.http.basic_auth'] << basic_auth
- hsh[key].endpoint_url = endpoint_url
- self.class.send(:define_method, key) { hsh[key] }
- hsh[key]
- }
- end
- def method_missing(meth, *args)
- if @wsdl.has_key?(meth.to_s)
- @driver[meth]
- else
- raise "unknown method: #{meth}"
- end
- end
- end
Add Comment
Please, Sign In to add comment