2014-12-30 17:25:09 -05:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class ELB
|
|
|
|
class Policy < Fog::Model
|
|
|
|
identity :id, :aliases => 'PolicyName'
|
|
|
|
|
|
|
|
attribute :cookie, :aliases => 'CookieName'
|
|
|
|
attribute :expiration, :aliases => 'CookieExpirationPeriod'
|
|
|
|
attribute :type_name
|
|
|
|
attribute :policy_attributes
|
2015-06-01 15:47:01 -04:00
|
|
|
attribute :load_balancer_id
|
2014-12-30 17:25:09 -05:00
|
|
|
|
|
|
|
attr_accessor :cookie_stickiness # Either :app or :lb
|
|
|
|
|
|
|
|
def save
|
2015-06-01 15:47:01 -04:00
|
|
|
requires :id, :load_balancer_id
|
|
|
|
args = [load_balancer_id, id]
|
2014-12-30 17:25:09 -05:00
|
|
|
|
|
|
|
if cookie_stickiness
|
|
|
|
case cookie_stickiness
|
|
|
|
when :app
|
|
|
|
requires :cookie
|
|
|
|
method = :create_app_cookie_stickiness_policy
|
|
|
|
args << cookie
|
|
|
|
when :lb
|
|
|
|
method = :create_lb_cookie_stickiness_policy
|
|
|
|
args << expiration if expiration
|
|
|
|
else
|
|
|
|
raise ArgumentError.new('cookie_stickiness must be :app or :lb')
|
|
|
|
end
|
|
|
|
else
|
|
|
|
requires :type_name, :policy_attributes
|
|
|
|
method = :create_load_balancer_policy
|
|
|
|
args << type_name
|
|
|
|
args << policy_attributes
|
|
|
|
end
|
|
|
|
|
|
|
|
service.send(method, *args)
|
|
|
|
reload
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2015-06-01 15:47:01 -04:00
|
|
|
requires :identity, :load_balancer_id
|
|
|
|
|
|
|
|
service.delete_load_balancer_policy(self.load_balancer_id, self.identity)
|
2014-12-30 17:25:09 -05:00
|
|
|
reload
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_balancer
|
2015-06-01 15:47:01 -04:00
|
|
|
requires :load_balancer_id
|
|
|
|
|
|
|
|
service.load_balancers.new(:identity => self.load_balancer_id)
|
2014-12-30 17:25:09 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|