Guest User

Untitled

a guest
Jun 20th, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. # nodes-per-pool
  2.  
  3. #!/usr/bin/env ruby
  4. # vim:expandtab shiftwidth=2 softtabstop=2
  5.  
  6. require 'icontrol'
  7.  
  8. Kernel.abort "Usage: #{$0} endpoint [poolname ...]" if ARGV.empty?
  9.  
  10. endpoint, *pools = ARGV
  11.  
  12. lb = IControl.new(endpoint)
  13. (pools.empty? ? lb.pool.get_list : pools).each do |pool|
  14. members = lb.pool.get_member(pool).first
  15. puts "Pool #{pool}: " + members.map {|member| "#{member.address}:#{member.port}"}.join(', ')
  16. end
  17.  
  18. exit
  19.  
  20. # icontrol.rb
  21.  
  22. # vim:expandtab shiftwidth=2 softtabstop=2
  23.  
  24. require 'rubygems'
  25. require 'soap/wsdlDriver'
  26.  
  27. class IControl
  28. def initialize(endpoint, config_file='config.yaml')
  29. begin
  30. configuration = YAML::load_file(config_file)
  31. rescue Exception => exc
  32. raise "error loading configuration from '#{config_file}': #{exc.message}"
  33. end
  34.  
  35. @wsdl = configuration['wsdl']
  36. username = configuration['username']
  37. password = configuration['password']
  38.  
  39. method = 'https'
  40. endpoint_url = "#{method}://#{endpoint}/iControl/iControlPortal.cgi"
  41. basic_auth = [endpoint_url, username, password]
  42.  
  43. @driver = Hash.new {|hsh, key|
  44. hsh[key] = SOAP::WSDLDriverFactory.new(@wsdl[key.to_s]).create_rpc_driver
  45.  
  46. verify_mode = OpenSSL::SSL::VERIFY_NONE
  47. hsh[key].options['protocol.http.ssl_config.verify_mode'] = verify_mode
  48. hsh[key].options['protocol.http.ssl_config.verify_callback'] = lambda {|is_ok, ctx| true}
  49. hsh[key].options['protocol.http.basic_auth'] << basic_auth
  50.  
  51. hsh[key].endpoint_url = endpoint_url
  52.  
  53. self.class.send(:define_method, key) { hsh[key] }
  54.  
  55. hsh[key]
  56. }
  57. end
  58.  
  59. def method_missing(meth, *args)
  60. if @wsdl.has_key?(meth.to_s)
  61. @driver[meth]
  62. else
  63. raise "unknown method: #{meth}"
  64. end
  65. end
  66. end
Add Comment
Please, Sign In to add comment