Class: CloudMaker::ElbInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_maker/elb_interface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ElbInterface

Public: Creates a new ElbInterface instance

options - Elb configuration options

:aws_access_key_id     - (required) The AWS access key
:aws_secret_access_key - (required) The AWS secret
:elb_name              - (required) The name of the elb to use
:instance           - (required) The AWS instance

Returns a new CloudMaker::ElbInterface instance Raises RuntimeError if any of the required options are not specified



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cloud_maker/elb_interface.rb', line 23

def initialize(options)
  required_keys = [:aws_access_key_id, :aws_secret_access_key, :instance, :elb_name]
  unless (required_keys - options.keys).empty?
    raise RuntimeError.new("Instantiated #{self.class} without required attributes: #{required_keys - options.keys}.")
  end
  
  self.instance = options[:instance]
  self.aws_access_key_id = options[:aws_access_key_id]
  self.aws_secret_access_key = options[:aws_secret_access_key]
  
  @elb = AWS::ELB.new(
    :access_key_id => self.aws_access_key_id,
    :secret_access_key => self.aws_secret_access_key
  ).load_balancers[options[:elb_name]]
end

Instance Attribute Details

#aws_access_key_idObject

Public: Gets/Sets the AWS secret.



6
7
8
# File 'lib/cloud_maker/elb_interface.rb', line 6

def aws_access_key_id
  @aws_access_key_id
end

#aws_secret_access_keyObject

Public: Gets/Sets the AWS access key.



4
5
6
# File 'lib/cloud_maker/elb_interface.rb', line 4

def aws_secret_access_key
  @aws_secret_access_key
end

#elb_nameObject

Internal: Gets/Sets the the elb name.



10
11
12
# File 'lib/cloud_maker/elb_interface.rb', line 10

def elb_name
  @elb_name
end

#instanceObject

Public: Gets/Sets the EC2 instance.



8
9
10
# File 'lib/cloud_maker/elb_interface.rb', line 8

def instance
  @instance
end

Instance Method Details

#attachObject

Raises:

  • (RuntimeError)


39
40
41
42
# File 'lib/cloud_maker/elb_interface.rb', line 39

def attach
  @elb.instances.register([self.instance])
  raise RuntimeError.new("The instance was not registerd correctly. id:#{self.instance.id}") unless @elb.instances[self.instance.id]
end