2014-02-01 21:13:17 -05:00
require 'fog/rackspace/core'
2011-08-16 22:33:15 -04:00
2011-07-07 18:17:31 -04:00
module Fog
module Rackspace
2011-08-04 17:21:22 -04:00
class LoadBalancers < Fog :: Service
2013-04-15 10:31:13 -04:00
include Fog :: Rackspace :: Errors
2011-07-07 18:17:31 -04:00
2011-08-16 22:33:15 -04:00
#These references exist for backwards compatibility
class ServiceError < Fog :: Rackspace :: Errors :: ServiceError ; end
class InternalServerError < Fog :: Rackspace :: Errors :: InternalServerError ; end
class BadRequest < Fog :: Rackspace :: Errors :: BadRequest ; end
2011-07-09 17:46:15 -04:00
2013-03-15 17:38:33 -04:00
DFW_ENDPOINT = 'https://dfw.loadbalancers.api.rackspacecloud.com/v1.0'
ORD_ENDPOINT = 'https://ord.loadbalancers.api.rackspacecloud.com/v1.0'
LON_ENDPOINT = 'https://lon.loadbalancers.api.rackspacecloud.com/v1.0'
2011-07-07 18:17:31 -04:00
requires :rackspace_api_key , :rackspace_username
recognizes :rackspace_auth_url
recognizes :rackspace_auth_token
2011-11-11 10:25:31 -05:00
recognizes :rackspace_lb_endpoint
2013-03-13 17:01:32 -04:00
recognizes :rackspace_load_balancers_url
recognizes :rackspace_region
2011-07-07 18:17:31 -04:00
2011-08-04 17:21:22 -04:00
model_path 'fog/rackspace/models/load_balancers'
2011-07-10 16:35:30 -04:00
collection :load_balancers
model :load_balancer
2011-07-14 15:20:53 -04:00
collection :nodes
model :node
2011-07-18 22:45:47 -04:00
collection :virtual_ips
model :virtual_ip
2011-07-28 13:21:26 -04:00
collection :access_rules
model :access_rule
2011-07-07 18:17:31 -04:00
2011-08-04 17:21:22 -04:00
request_path 'fog/rackspace/requests/load_balancers'
2012-05-05 12:38:08 -04:00
request :get_ssl_termination
request :set_ssl_termination
2012-06-26 00:35:07 -04:00
request :remove_ssl_termination
2011-07-07 18:17:31 -04:00
request :create_load_balancer
2011-07-08 16:39:22 -04:00
request :get_load_balancer
request :list_load_balancers
request :update_load_balancer
2011-07-07 18:17:31 -04:00
request :delete_load_balancer
2011-07-13 16:27:55 -04:00
request :create_node
request :list_nodes
request :get_node
request :update_node
request :delete_node
request :delete_nodes
2011-07-15 00:07:29 -04:00
request :create_virtual_ip
request :list_virtual_ips
request :delete_virtual_ip
2011-07-21 10:41:40 -04:00
request :list_protocols
request :list_algorithms
request :get_connection_logging
request :set_connection_logging
2013-01-02 14:52:26 -05:00
request :get_content_caching
request :set_content_caching
2011-07-27 16:55:01 -04:00
request :create_access_rule
request :list_access_rules
request :delete_access_rule
request :delete_all_access_rules
2011-07-27 17:06:24 -04:00
request :get_session_persistence
request :set_session_persistence
request :remove_session_persistence
2011-07-27 17:19:44 -04:00
request :get_connection_throttling
request :remove_connection_throttling
request :set_connection_throttling
2011-07-27 21:12:46 -04:00
request :get_monitor
request :set_monitor
request :remove_monitor
2011-07-27 21:44:43 -04:00
request :get_usage
2011-07-27 21:53:33 -04:00
request :get_load_balancer_usage
2011-12-15 16:53:06 -05:00
request :get_error_page
request :set_error_page
request :remove_error_page
2013-08-20 17:45:48 -04:00
request :get_stats
2011-07-07 18:17:31 -04:00
2011-08-16 12:56:44 -04:00
module Shared
def algorithms
list_algorithms . body [ 'algorithms' ] . collect { | i | i [ 'name' ] }
end
def protocols
list_protocols . body [ 'protocols' ]
end
def usage ( options = { } )
get_usage ( options ) . body
end
end
2013-03-13 17:01:32 -04:00
class Mock < Fog :: Rackspace :: Service
2011-08-16 12:56:44 -04:00
include Shared
def initialize ( options = { } )
@rackspace_api_key = options [ :rackspace_api_key ]
@rackspace_username = options [ :rackspace_username ]
@rackspace_auth_url = options [ :rackspace_auth_url ]
end
end
2013-03-13 17:01:32 -04:00
class Real < Fog :: Rackspace :: Service
2011-08-16 12:56:44 -04:00
include Shared
2011-07-07 18:17:31 -04:00
def initialize ( options = { } )
@rackspace_api_key = options [ :rackspace_api_key ]
@rackspace_username = options [ :rackspace_username ]
@rackspace_auth_url = options [ :rackspace_auth_url ]
@rackspace_must_reauthenticate = false
2011-09-12 11:01:48 -04:00
@connection_options = options [ :connection_options ] || { }
2013-03-15 17:38:33 -04:00
setup_custom_endpoint ( options )
2011-07-07 18:17:31 -04:00
authenticate
2014-01-02 12:46:11 -05:00
deprecation_warnings ( options )
2013-03-13 17:01:32 -04:00
@persistent = options [ :persistent ] || false
2014-02-26 19:50:35 -05:00
@connection = Fog :: XML :: Connection . new ( endpoint_uri . to_s , @persistent , @connection_options )
2011-07-07 18:17:31 -04:00
end
2013-09-24 13:02:10 -04:00
def request ( params , parse_json = true )
super
2013-06-24 11:13:57 -04:00
rescue Excon :: Errors :: NotFound = > error
2013-08-14 11:05:25 -04:00
raise NotFound . slurp ( error , self )
2013-06-24 11:13:57 -04:00
rescue Excon :: Errors :: BadRequest = > error
2013-08-14 11:05:25 -04:00
raise BadRequest . slurp ( error , self )
2013-06-24 11:13:57 -04:00
rescue Excon :: Errors :: InternalServerError = > error
2013-08-14 11:05:25 -04:00
raise InternalServerError . slurp ( error , self )
2013-06-24 11:13:57 -04:00
rescue Excon :: Errors :: HTTPStatusError = > error
2013-08-14 11:05:25 -04:00
raise ServiceError . slurp ( error , self )
2011-07-07 18:17:31 -04:00
end
2013-06-21 16:11:17 -04:00
def authenticate ( options = { } )
super ( {
2013-03-13 17:01:32 -04:00
:rackspace_api_key = > @rackspace_api_key ,
2011-07-07 18:17:31 -04:00
:rackspace_username = > @rackspace_username ,
2013-05-30 13:52:37 -04:00
:rackspace_auth_url = > @rackspace_auth_url ,
:connection_options = > @connection_options
2013-06-21 16:11:17 -04:00
} )
2013-03-13 17:01:32 -04:00
end
def service_name
:cloudLoadBalancers
end
def region
@rackspace_region
end
def endpoint_uri ( service_endpoint_url = nil )
@uri = super ( @rackspace_endpoint || service_endpoint_url , :rackspace_load_balancers_url )
end
private
2013-03-15 17:38:33 -04:00
def setup_custom_endpoint ( options )
2013-03-20 14:25:38 -04:00
@rackspace_endpoint = Fog :: Rackspace . normalize_url ( options [ :rackspace_load_balancers_url ] || options [ :rackspace_lb_endpoint ] )
2013-03-15 17:38:33 -04:00
if v2_authentication?
case @rackspace_endpoint
when DFW_ENDPOINT
@rackspace_endpoint = nil
@rackspace_region = :dfw
when ORD_ENDPOINT
@rackspace_endpoint = nil
@rackspace_region = :ord
when LON_ENDPOINT
@rackspace_endpoint = nil
@rackspace_region = :lon
else
# we are actually using a custom endpoint
@rackspace_region = options [ :rackspace_region ] || :dfw
end
else
#if we are using auth1 and the endpoint is not set, default to DFW_ENDPOINT for historical reasons
@rackspace_endpoint || = DFW_ENDPOINT
end
end
2013-03-13 17:01:32 -04:00
def deprecation_warnings ( options )
Fog :: Logger . deprecation ( " The :rackspace_lb_endpoint option is deprecated. Please use :rackspace_load_balancers_url for custom endpoints " ) if options [ :rackspace_lb_endpoint ]
if [ DFW_ENDPOINT , ORD_ENDPOINT , LON_ENDPOINT ] . include? ( @rackspace_endpoint ) && v2_authentication?
regions = @identity_service . service_catalog . display_service_regions ( service_name )
Fog :: Logger . deprecation ( " Please specify region using :rackspace_region rather than :rackspace_endpoint. Valid regions for :rackspace_region are #{ regions } . " )
end
2014-01-02 12:46:11 -05:00
unless options [ :rackspace_region ]
Fog :: Logger . deprecation ( " Default region support will be removed in an upcoming release. Please switch to manually setting your endpoint. This requires settng the :rackspace_region option " )
end
2013-03-13 17:01:32 -04:00
end
2013-03-15 17:38:33 -04:00
def append_tenant_v1 ( credentials )
2013-03-13 17:01:32 -04:00
account_id = credentials [ 'X-Server-Management-Url' ] . match ( / .* \/ ([ \ d]+)$ / ) [ 1 ]
endpoint = @rackspace_endpoint || credentials [ 'X-Server-Management-Url' ] || DFW_ENDPOINT
@uri = URI . parse ( endpoint )
@uri . path = " #{ @uri . path } / #{ account_id } "
end
def authenticate_v1 ( options )
2011-09-12 11:01:48 -04:00
credentials = Fog :: Rackspace . authenticate ( options , @connection_options )
2013-03-15 17:38:33 -04:00
append_tenant_v1 credentials
2011-07-07 18:17:31 -04:00
@auth_token = credentials [ 'X-Auth-Token' ]
end
2013-03-13 17:01:32 -04:00
2011-07-07 18:17:31 -04:00
end
end
end
end