diff --git a/lib/fog/rackspace/models/load_balancer.rb b/lib/fog/rackspace/models/load_balancer.rb index 53be58092..6324ca454 100644 --- a/lib/fog/rackspace/models/load_balancer.rb +++ b/lib/fog/rackspace/models/load_balancer.rb @@ -45,24 +45,80 @@ module Fog end end - def connection_logging - attributes[:connection_logging] - end - def virtual_ips=(new_virtual_ips=[]) virtual_ips.load(new_virtual_ips) end + def connection_logging + attributes[:connection_logging] + end + def enable_connection_logging + requires :identity connection.set_connection_logging identity, true attributes[:connection_logging] = true end def disable_connection_logging + requires :identity connection.set_connection_logging identity, false attributes[:connection_logging] = false end + def health_monitor + requires :identity + monitor = connection.get_monitor(identity).body['healthMonitor'] + monitor.count == 0 ? nil : monitor + end + + def enable_health_monitor(type, delay, timeout, attempsBeforeDeactivation, options = {}) + requires :identity + connection.set_monitor(identity, type, delay, timeout, attempsBeforeDeactivation, options = {}) + true + end + + def disable_health_monitor + requires :identity + connection.remove_monitor(identity) + true + end + + def connection_throttling + requires :identity + throttle = connection.get_connection_throttling(identity).body['connectionThrottle'] + throttle.count == 0 ? nil : throttle + end + + def enable_connection_throttling(max_connections, min_connections, max_connection_rate, rate_interval) + requires :identity + connection.set_connection_throttling(identity, max_connections, min_connections, max_connection_rate, rate_interval) + true + end + + def disable_connection_throttling + requires :identity + connection.remove_connection_throttling(identity) + true + end + + def session_persistence + requires :identity + persistence = connection.get_session_persistence(identity).body['sessionPersistence'] + persistence.count == 0 ? nil : persistence + end + + def enable_session_persistence(type) + requires :identity + connection.set_session_persistence(identity, type) + true + end + + def disable_session_persistence + requires :identity + connection.remove_session_persistence(identity) + true + end + def destroy requires :identity connection.delete_load_balancer(identity) @@ -82,6 +138,11 @@ module Fog true end + def usage(options = {}) + requires :identity + connection.get_load_balancer_usage(identity, options).body + end + private def create requires :name, :protocol, :port, :virtual_ips, :nodes diff --git a/tests/rackspace/models/load_balancer_tests.rb b/tests/rackspace/models/load_balancer_tests.rb index adc265751..e3d0b2075 100644 --- a/tests/rackspace/models/load_balancer_tests.rb +++ b/tests/rackspace/models/load_balancer_tests.rb @@ -30,6 +30,85 @@ Shindo.tests('Fog::Rackspace::LoadBalancer | load_balancer', ['rackspace']) do returns(false) { @instance.connection_logging } end + tests('#usage').succeeds do + @instance.usage + end + + tests("#usage(:start_time => '2010-05-10', :end_time => '2010-05-11')").succeeds do + @instance.usage(:start_time => '2010-05-10', :end_time => '2010-05-11') + end + + tests("#health_monitor").returns(nil) do + @instance.health_monitor + end + + @instance.wait_for { ready? } + tests("#enable_health_monitor('CONNECT', 5, 5, 5)").succeeds do + @instance.enable_health_monitor('CONNECT', 5, 5, 5) + end + + @instance.wait_for { ready? } + tests("#health_monitor").succeeds do + monitor = @instance.health_monitor + returns('CONNECT') { monitor['type'] } + end + + @instance.wait_for { ready? } + tests("#disable_health_monitor").succeeds do + @instance.disable_health_monitor + end + + @instance.wait_for { ready? } + tests("#connection_throttling").returns(nil) do + @instance.connection_throttling + end + + tests("#enable_connection_throttling(5, 5, 5, 5)").succeeds do + @instance.enable_connection_throttling(5, 5, 5, 5) + end + + @instance.wait_for { ready? } + tests("#connection_throttling").succeeds do + throttle = @instance.connection_throttling + returns(5) { throttle['maxConnections'] } + end + + @instance.wait_for { ready? } + tests("#disable_connection_throttling").succeeds do + @instance.disable_connection_throttling + end + + @instance.wait_for { ready? } + tests("#session_persistence").returns(nil) do + @instance.session_persistence + end + + tests("#enable_session_persistence('HTTP_COOKIE')").succeeds do + @instance.enable_session_persistence('HTTP_COOKIE') + end + + @instance.wait_for { ready? } + tests("#connction_throttling").succeeds do + persistence = @instance.session_persistence + returns('HTTP_COOKIE') { persistence['persistenceType'] } + end + + @instance.wait_for { ready? } + tests("#disable_session_persistence").succeeds do + @instance.disable_session_persistence + end + @instance.wait_for { ready? } end + + tests('failure') do + @lb = @service.load_balancers.new LOAD_BALANCER_ATTRIBUTES + tests('#usage => Requires ID').raises(ArgumentError) do + @lb.usage + end + + tests('#health_monitor => Requires ID').raises(ArgumentError) do + @lb.health_monitor + end + end end