2011-07-10 16:35:30 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Rackspace
|
|
|
|
class LoadBalancer
|
|
|
|
class LoadBalancer < Fog::Model
|
|
|
|
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :cluster
|
2011-07-10 16:58:27 -04:00
|
|
|
attribute :connection_logging, :aliases => 'connectionLogging'
|
2011-07-10 16:35:30 -04:00
|
|
|
attribute :port
|
|
|
|
attribute :protocol
|
|
|
|
attribute :algorithm
|
2011-07-10 16:58:27 -04:00
|
|
|
attribute :virtual_ips, :aliases => 'virtualIps'
|
2011-07-10 16:35:30 -04:00
|
|
|
attribute :nodes
|
|
|
|
attribute :created
|
|
|
|
attribute :updated
|
|
|
|
attribute :name
|
2011-07-10 16:58:27 -04:00
|
|
|
attribute :state, :aliases => 'status'
|
2011-07-10 16:35:30 -04:00
|
|
|
|
|
|
|
def initialize(attributes={})
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :id
|
|
|
|
connection.delete_load_balancer(id)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def ready?
|
|
|
|
self.state == 'ACTIVE'
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
if identity
|
|
|
|
update
|
|
|
|
else
|
|
|
|
create
|
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def create
|
|
|
|
requires :name, :protocol, :port, :virtual_ips, :nodes
|
|
|
|
data = connection.create_load_balancer(name, protocol, port, virtual_ips, nodes)
|
|
|
|
merge_attributes(data.body['loadBalancer'])
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
requires :name, :protool, :port, :algorithm
|
|
|
|
options = {
|
|
|
|
'name' => name,
|
|
|
|
'algorithm' => algorithm,
|
|
|
|
'protocol' => protocol,
|
|
|
|
'port' => port}
|
|
|
|
connection.update_load_balancer(identity, options)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|