Advertisement
Guest User

Untitled

a guest
Mar 12th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #This quickie is for getting a dump of all nodes and whether they're active or not
  2. #from a pool on an F5. Takes one arg, the IP of the F5 in question.
  3.  
  4. require 'yaml'
  5. require 'openssl'
  6. gem 'soap4r'
  7. require 'xsd/qname'
  8. require 'soap/wsdlDriver'
  9. require 'net/ssh'
  10. require 'net/http'
  11. require 'net/https'
  12. require 'win32/process'
  13.  
  14. include Windows::Handle
  15.  
  16. class BIGIP_Connection
  17. attr_accessor :bigip_config, :bigip_driver
  18. def initialize(bigip_address)
  19. config_file = 'config\load_balancers.yml'
  20. begin
  21. configuration = YAML::load_file(config_file)
  22. rescue Exception => yaml_ex
  23. puts "Error loading configuration from '#{config_file}': #{yaml_ex}."
  24. return false
  25. end
  26.  
  27. @bigip_config = {
  28. :user => configuration[bigip_address]['user'],
  29. :password => configuration[bigip_address]['password'],
  30. :endpoint => configuration[bigip_address]['endpoint'],
  31. :wsdl => configuration[bigip_address]['wsdl']
  32. }
  33.  
  34. @bigip_driver = SOAP::WSDLDriverFactory.new(@bigip_config[:wsdl]).create_rpc_driver
  35.  
  36. basic_auth = []
  37. basic_auth << @bigip_config[:endpoint]
  38. basic_auth << @bigip_config[:user]
  39. basic_auth << @bigip_config[:password]
  40.  
  41. verify_mode = OpenSSL::SSL::VERIFY_NONE
  42. @bigip_driver.options['protocol.http.ssl_config.verify_mode']= verify_mode
  43. @bigip_driver.options['protocol.http.basic_auth'] << basic_auth
  44.  
  45. #Need this line to override the F5 default endpoint_url
  46. @bigip_driver.endpoint_url = @bigip_config[:endpoint]
  47.  
  48. end
  49.  
  50. def pool_dump(pool_name)
  51. nodes = self.bigip_driver.get_object_status(pool_name)
  52. if nodes[0].length == 0
  53. puts "There are no nodes for this pool"
  54. else
  55. nodes[0].each do |x|
  56. port = x.member.port
  57. address = x.member.address
  58. status = x.object_status.enabled_status.match(/_[A-Z]+$/).to_s.sub("_",'')
  59. availability = x.object_status.availability_status.match(/_[A-Z]+$/).to_s.sub("_",'')
  60. puts "#{address}:#{port}?#{status}?#{availability}"
  61. end
  62. end
  63. end
  64. end
  65.  
  66. @bigip = BIGIP_Connection.new(ARGV[0])
  67. @bigip.pool_dump("SYM_BR_SSL")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement