Class: VirtualServer
- Inherits:
-
Object
- Object
- VirtualServer
- Defined in:
- lib/simple_lb.rb
Class Method Summary collapse
- .create_config ⇒ Object
- .create_pool(soap, pool_name, pool_member) ⇒ Object
- .create_soap_connection(locallb_prop) ⇒ Object
-
.create_virtual_server(soap, vs_name, vs_address) ⇒ Object
end m.success?.
Instance Method Summary collapse
-
#initialize(args) ⇒ VirtualServer
constructor
A new instance of VirtualServer.
Constructor Details
#initialize(args) ⇒ VirtualServer
Returns a new instance of VirtualServer.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/simple_lb.rb', line 7 def initialize (args) @vs_attrs = args.to_a if @vs_attrs.empty? puts "Usage: simple_lb <virtual_server_name> <vs_ipaddress> <member1_ip> <member2_ip>" puts "Example: simple_lb my_virtuals_server 192.168.10.100 192.168.10.102 192.168.10.103" exit end $vs_name = @vs_attrs.shift $vs_address = @vs_attrs.shift $pool_member1 = @vs_attrs.shift VirtualServer.create_config VirtualServer.create_soap_connection('Pool') VirtualServer.create_soap_connection('VirtualServer') end |
Class Method Details
.create_config ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/simple_lb.rb', line 22 def self.create_config path = File. "~/.bigip.yml" config = YAML.load(File.read(path)) rescue nil unless config then config = { :ipaddress => '172.16.222.120', :user => 'admin', :password => 'admin' } File.open(path, "w") { |f| YAML.dump(config, f) } abort "Created config file #{path} update with your bigip info" end @ipaddress = config[:ipaddress] @user = config[:user] @password = config[:password] end |
.create_pool(soap, pool_name, pool_member) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/simple_lb.rb', line 59 def self.create_pool (soap,pool_name,pool_member) r = soap.call :create do |pool| pool. 'pool_names' => {:item => ["#{pool_name}"]}, 'lb_methods' => {:item => ['LB_METHOD_ROUND_ROBIN']}, 'members' => { :item => { :item => [:address => pool_member, :port => '80']}} end unless @vs_attrs.blank? @vs_attrs.each do |member| soap.call :add_member do |pool| pool. 'pool_names' => {:item => ["#{pool_name}"]}, 'members' => { :item => { :item => [:address => member, :port => '80']}} end r.success? end end end |
.create_soap_connection(locallb_prop) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/simple_lb.rb', line 41 def self.create_soap_connection (locallb_prop) @soap = Savon.client do |s| s.wsdl "https://#{@ipaddress}/iControl/iControlPortal.cgi?WSDL=LocalLB.#{locallb_prop}" s.basic_auth [@user, @password] s.ssl_verify_mode :none s.endpoint "https://#{@ipaddress}/iControl/iControlPortal.cgi" s.namespace "urn:iControl:LocalLB/#{locallb_prop}" s.convert_request_keys_to :none end case locallb_prop when 'VirtualServer' self.create_virtual_server(@soap,$vs_name,$vs_address) when 'Pool' self.create_pool(@soap,$vs_name,$pool_member1) end end |
.create_virtual_server(soap, vs_name, vs_address) ⇒ Object
end
m.success?
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/simple_lb.rb', line 87 def self.create_virtual_server (soap,vs_name,vs_address) vsdefinitions = [ :name => vs_name, :address => vs_address, :port => '80', :protocol => 'PROTOCOL_TCP' ] vswildmasks = '255.255.255.255' vsresources = [ :type => 'RESOURCE_TYPE_POOL', :default_pool_name => vs_name ] vsprofiles = [ :profile_type => 'PROFILE_TYPE_FAST_L4', :profile_context => 'PROFILE_CONTEXT_TYPE_ALL', :profile_name => 'tcp' ] r = soap.call :create do |vs| vs. :definitions => {:item => vsdefinitions}, :wildmasks => {:item => vswildmasks}, :resources => {:item => vsresources}, :profiles => {:item => {:item => vsprofiles}} end r.success? end |