class Fog::Rackspace::LoadBalancers::LoadBalancer

Constants

ACTIVE

States

BUILD
DELETED
ERROR
PENDING_DELTE
PENDING_UPDATE
SUSPENDED

Public Class Methods

new(attributes) click to toggle source
Calls superclass method Fog::Model.new
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 31
def initialize(attributes)
  #HACK - Since we are hacking how sub-collections work, we have to make sure the connection is valid first.
  @connection = attributes[:connection]
  super
end

Public Instance Methods

access_rules() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 37
def access_rules
  @access_rules ||= begin
    Fog::Rackspace::LoadBalancers::AccessRules.new({
      :connection => connection,
      :load_balancer => self})
  end
end
access_rules=(new_access_rules=[]) click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 45
def access_rules=(new_access_rules=[])
  access_rules.load(new_access_rules)
end
connection_throttling() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 120
def connection_throttling
  requires :identity
  throttle = connection.get_connection_throttling(identity).body['connectionThrottle']
  throttle.count == 0 ? nil : throttle
end
destroy() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 156
def destroy
  requires :identity
  connection.delete_load_balancer(identity)
  true
end
disable_connection_logging() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 96
def disable_connection_logging
  requires :identity
  connection.set_connection_logging identity, false
  attributes[:connection_logging] = false
end
disable_connection_throttling() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 132
def disable_connection_throttling
  requires :identity
  connection.remove_connection_throttling(identity)
  true
end
disable_health_monitor() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 114
def disable_health_monitor
  requires :identity
  connection.remove_monitor(identity)
  true
end
disable_session_persistence() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 150
def disable_session_persistence
  requires :identity
  connection.remove_session_persistence(identity)
  true
end
disable_ssl_termination() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 73
def disable_ssl_termination
  requires :identity
  connection.remove_ssl_termination(identity)
end
enable_connection_logging() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 90
def enable_connection_logging
  requires :identity
  connection.set_connection_logging identity, true
  attributes[:connection_logging] = true
end
enable_connection_throttling(max_connections, min_connections, max_connection_rate, rate_interval) click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 126
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
enable_health_monitor(type, delay, timeout, attempsBeforeDeactivation, options = {}) click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 108
def enable_health_monitor(type, delay, timeout, attempsBeforeDeactivation, options = {})
  requires :identity
  connection.set_monitor(identity, type, delay, timeout, attempsBeforeDeactivation, options)
  true
end
enable_session_persistence(type) click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 144
def enable_session_persistence(type)
  requires :identity
  connection.set_session_persistence(identity, type)
  true
end
enable_ssl_termination(securePort, privatekey, certificate, options = {}) click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 68
def enable_ssl_termination(securePort, privatekey, certificate, options = {})
  requires :identity
  connection.set_ssl_termination(identity, securePort, privatekey, certificate, options)
end
error_page() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 180
def error_page
  requires :identity
  connection.get_error_page(identity).body['errorpage']['content']
end
error_page=(content) click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 185
def error_page=(content)
  requires :identity
  connection.set_error_page identity, content
end
health_monitor() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 102
def health_monitor
  requires :identity
  monitor = connection.get_monitor(identity).body['healthMonitor']
  monitor.count == 0 ? nil : monitor
end
nodes() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 49
def nodes
  @nodes ||= begin
    Fog::Rackspace::LoadBalancers::Nodes.new({
      :connection => connection,
      :load_balancer => self})
  end
end
nodes=(new_nodes=[]) click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 57
def nodes=(new_nodes=[])
  nodes.load(new_nodes)
end
ready?() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 162
def ready?
  state == ACTIVE
end
reset_error_page() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 190
def reset_error_page
  requires :identity
  connection.remove_error_page identity
end
save() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 166
def save
  if identity
    update
  else
    create
  end
  true
end
session_persistence() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 138
def session_persistence
  requires :identity
  persistence = connection.get_session_persistence(identity).body['sessionPersistence']
  persistence.count == 0 ? nil : persistence
end
ssl_termination() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 61
def ssl_termination
  requires :identity
  ssl_termination = connection.get_ssl_termination(identity).body['sslTermination']
rescue Fog::Rackspace::LoadBalancers::NotFound
  nil
end
usage(options = {}) click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 175
def usage(options = {})
  requires :identity
  connection.get_load_balancer_usage(identity, options).body
end
virtual_ips() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 78
def virtual_ips
  @virtual_ips ||= begin
    Fog::Rackspace::LoadBalancers::VirtualIps.new({
      :connection => connection,
      :load_balancer => self})
  end
end
virtual_ips=(new_virtual_ips=[]) click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 86
def virtual_ips=(new_virtual_ips=[])
  virtual_ips.load(new_virtual_ips)
end

Private Instance Methods

connection_logging=(new_value) click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 235
def connection_logging=(new_value)
  if !new_value.nil? and new_value.is_a?(Hash)
    attributes[:connection_logging] = case new_value['enabled']
                                      when true,'true'
                                        true
                                      when false,'false'
                                        false
                                      end
  else
    attributes[:connection_logging] = new_value
  end
end
create() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 196
def create
  requires :name, :protocol, :port, :virtual_ips, :nodes

  if algorithm
    options = { :algorithm => algorithm }
  else
    options = {}
  end

  data = connection.create_load_balancer(name, protocol, port, virtual_ips_hash, nodes_hash, options)
  merge_attributes(data.body['loadBalancer'])
end
nodes_hash() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 229
def nodes_hash
  nodes.collect do |node|
    { :address => node.address, :port => node.port, :condition => node.condition, :weight => node.weight }
  end
end
update() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 209
def update
  requires :name, :protocol, :port, :algorithm
  options = {
    :name => name,
    :algorithm => algorithm,
    :protocol => protocol,
    :port => port}
  connection.update_load_balancer(identity, options)

  #TODO - Should this bubble down to nodes? Without tracking changes this would be very inefficient.
  # For now, individual nodes will have to be saved individually after saving an LB
end
virtual_ips_hash() click to toggle source
# File lib/fog/rackspace/models/load_balancers/load_balancer.rb, line 222
def virtual_ips_hash
  virtual_ips.collect do |virtual_ip|
    { :type => virtual_ip.type }
  end

end