Class: Hugo::Aws::Elb
- Inherits:
-
Object
- Object
- Hugo::Aws::Elb
- Defined in:
- lib/hugo/aws/elb.rb
Constant Summary collapse
- ACCESS_KEY =
ENV['AMAZON_ACCESS_KEY_ID']
- SECRET_KEY =
ENV['AMAZON_SECRET_ACCESS_KEY']
- ZONES =
["us-east-1c"]
- LISTENERS =
[{"InstancePort"=>"8080", "Protocol"=>"HTTP", "LoadBalancerPort"=>"80"}, {"InstancePort"=>"8443", "Protocol"=>"TCP", "LoadBalancerPort"=>"443"}]
Instance Attribute Summary collapse
-
#aws_access_key_id ⇒ Object
Returns the value of attribute aws_access_key_id.
-
#aws_secret_access_key ⇒ Object
Returns the value of attribute aws_secret_access_key.
-
#create_time ⇒ Object
Returns the value of attribute create_time.
-
#instances ⇒ Object
Returns the value of attribute instances.
-
#listeners ⇒ Object
Returns the value of attribute listeners.
-
#name ⇒ Object
Returns the value of attribute name.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#zones ⇒ Object
Returns the value of attribute zones.
Class Method Summary collapse
- .all(aws_access_key_id, aws_secret_access_key) ⇒ Object
- .find(balancer, aws_access_key_id, aws_secret_access_key) ⇒ Object
- .find_or_create(options) ⇒ Object
Instance Method Summary collapse
- #add(instance) ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
-
#initialize(options = {}) ⇒ Elb
constructor
A new instance of Elb.
- #remove(instance) ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Elb
Returns a new instance of Elb.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hugo/aws/elb.rb', line 13 def initialize( = {} ) @name = [:name] || ["LoadBalancerName"] @uri = ["DNSName"] if ["DNSName"] if ["Instances"] and ["Instances"]["member"] @instances = ["Instances"]["member"].map { |i| i.InstanceId } else @instances = [] end if ["AvailabilityZones"] and ["AvailabilityZones"]["member"] @zones = ["AvailabilityZones"]["member"] else @zones = [:zones] || ZONES end if ["Listeners"] and ["Listeners"]["member"] @listeners = ["Listeners"]["member"] else @listeners = [:listeners] || LISTENERS end if ["CreatedTime"] @create_time = ["CreatedTime"] end @aws_access_key_id = [:aws_access_key_id] || ACCESS_KEY @aws_secret_access_key = [:aws_secret_access_key] || SECRET_KEY end |
Instance Attribute Details
#aws_access_key_id ⇒ Object
Returns the value of attribute aws_access_key_id.
11 12 13 |
# File 'lib/hugo/aws/elb.rb', line 11 def aws_access_key_id @aws_access_key_id end |
#aws_secret_access_key ⇒ Object
Returns the value of attribute aws_secret_access_key.
11 12 13 |
# File 'lib/hugo/aws/elb.rb', line 11 def aws_secret_access_key @aws_secret_access_key end |
#create_time ⇒ Object
Returns the value of attribute create_time.
11 12 13 |
# File 'lib/hugo/aws/elb.rb', line 11 def create_time @create_time end |
#instances ⇒ Object
Returns the value of attribute instances.
11 12 13 |
# File 'lib/hugo/aws/elb.rb', line 11 def instances @instances end |
#listeners ⇒ Object
Returns the value of attribute listeners.
11 12 13 |
# File 'lib/hugo/aws/elb.rb', line 11 def listeners @listeners end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/hugo/aws/elb.rb', line 11 def name @name end |
#uri ⇒ Object
Returns the value of attribute uri.
11 12 13 |
# File 'lib/hugo/aws/elb.rb', line 11 def uri @uri end |
#zones ⇒ Object
Returns the value of attribute zones.
11 12 13 |
# File 'lib/hugo/aws/elb.rb', line 11 def zones @zones end |
Class Method Details
.all(aws_access_key_id, aws_secret_access_key) ⇒ Object
76 77 78 79 80 |
# File 'lib/hugo/aws/elb.rb', line 76 def self.all(aws_access_key_id, aws_secret_access_key) @elb = AWS::ELB::Base.new(:access_key_id => aws_access_key_id, :secret_access_key => aws_secret_access_key) instances = @elb.describe_load_balancers().DescribeLoadBalancersResult.LoadBalancerDescriptions.member instances.map { |i| self.new(i) } end |
.find(balancer, aws_access_key_id, aws_secret_access_key) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/hugo/aws/elb.rb', line 82 def self.find(balancer, aws_access_key_id, aws_secret_access_key) @elb = AWS::ELB::Base.new(:access_key_id => ACCESS_KEY, :secret_access_key => SECRET_KEY) result = nil @elb.describe_load_balancers().DescribeLoadBalancersResult.LoadBalancerDescriptions.member.each do |m| result = self.new(m) if m.LoadBalancerName == balancer end result rescue nil end |
.find_or_create(options) ⇒ Object
96 97 98 |
# File 'lib/hugo/aws/elb.rb', line 96 def self.find_or_create() self.find([:name], [:aws_access_key_id], [:aws_secret_access_key]) || self.new().create end |
Instance Method Details
#add(instance) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/hugo/aws/elb.rb', line 59 def add(instance) elb.register_instances_with_load_balancer( :instances => [instance], :load_balancer_name => @name) @instances << instance self end |
#create ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/hugo/aws/elb.rb', line 42 def create elb.create_load_balancer( :load_balancer_name => self.name, :listeners => self.listeners, :availability_zones => self.zones ) unless self.create_time self end |
#destroy ⇒ Object
51 52 53 |
# File 'lib/hugo/aws/elb.rb', line 51 def destroy elb.delete_load_balancer(:load_balancer_name => self.name) end |
#remove(instance) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/hugo/aws/elb.rb', line 67 def remove(instance) elb.deregister_instances_from_load_balancer( :instances => [instance], :load_balancer_name => @name) @instances = @instances - [instance] self end |
#save ⇒ Object
55 56 57 |
# File 'lib/hugo/aws/elb.rb', line 55 def save self.create end |