From cdd724dff6d0901aef4a043bec5c5ad350ff21c9 Mon Sep 17 00:00:00 2001 From: Josh Lane Date: Mon, 1 Jun 2015 09:14:45 -0700 Subject: [PATCH] make elb/policies collection standalone * there is no need to inject data from the load balancer model when an index request exists that maps directly --- lib/fog/aws/models/elb/load_balancer.rb | 19 +++++++++---------- lib/fog/aws/models/elb/policies.rb | 22 ++++++++++++++++------ lib/fog/aws/models/elb/policy.rb | 7 +------ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/lib/fog/aws/models/elb/load_balancer.rb b/lib/fog/aws/models/elb/load_balancer.rb index 61c36d779..a21949aa3 100644 --- a/lib/fog/aws/models/elb/load_balancer.rb +++ b/lib/fog/aws/models/elb/load_balancer.rb @@ -143,23 +143,22 @@ module Fog end def listeners - Fog::AWS::ELB::Listeners.new({ - :data => attributes['ListenerDescriptions'], - :service => service, + Fog::AWS::ELB::Listeners.new( + :data => attributes['ListenerDescriptions'], + :service => service, :load_balancer => self - }) + ) end def policies - Fog::AWS::ELB::Policies.new({ - :data => policy_descriptions, - :service => service, - :load_balancer => self - }) + requires :id + + service.policies(:load_balancer_id => self.identity) end def policy_descriptions requires :id + @policy_descriptions ||= service.describe_load_balancer_policies(id).body["DescribeLoadBalancerPoliciesResult"]["PolicyDescriptions"] end @@ -202,7 +201,7 @@ module Fog service.remove_tags(id, tag_keys) tags end - + def save requires :id diff --git a/lib/fog/aws/models/elb/policies.rb b/lib/fog/aws/models/elb/policies.rb index fa613c1db..f41e64964 100644 --- a/lib/fog/aws/models/elb/policies.rb +++ b/lib/fog/aws/models/elb/policies.rb @@ -1,23 +1,33 @@ require 'fog/aws/models/elb/policy' + module Fog module AWS class ELB class Policies < Fog::Collection + + attribute :load_balancer_id + model Fog::AWS::ELB::Policy - attr_accessor :data, :load_balancer + def all(options={}) + merge_attributes(options) - def all - load(munged_data) + requires :load_balancer_id + + data = service.describe_load_balancer_policies(self.load_balancer_id). + body["DescribeLoadBalancerPoliciesResult"]["PolicyDescriptions"] + + load(munge(data)) end def get(id) - all.find{|policy| id == policy.id} + all.find { |policy| id == policy.id } end private - def munged_data - data.reduce([]){|m,e| + + def munge(data) + data.reduce([]) { |m,e| policy_attribute_descriptions = e["PolicyAttributeDescriptions"] policy = { diff --git a/lib/fog/aws/models/elb/policy.rb b/lib/fog/aws/models/elb/policy.rb index fd6251a91..ea4a83486 100644 --- a/lib/fog/aws/models/elb/policy.rb +++ b/lib/fog/aws/models/elb/policy.rb @@ -13,7 +13,6 @@ module Fog def save requires :id, :load_balancer - service_method = nil args = [load_balancer.id, id] if cookie_stickiness @@ -45,12 +44,8 @@ module Fog reload end - def reload - load_balancer.reload - end - def load_balancer - collection.load_balancer + service.load_balancers.new(identity: collection.load_balancer_id) end end end