Class: Instance::ELB

Inherits:
Instance show all
Defined in:
lib/maws/instance/elb.rb

Overview

for ELBs aws_id is the same as their names

Constant Summary

Constants inherited from Instance

NA_STATUS

Instance Attribute Summary

Attributes inherited from Instance

#description, #groups, #index, #name, #prefix, #region, #role, #zone

Instance Method Summary collapse

Methods inherited from Instance

#alive?, #aws_id, #config, #connection, create, #display, #has_approximate_status?, #initialize, #inspect, #instances, #logical_zone, #matches?, #method_missing, name_for, #region_physical_zone, #region_zone, #security_groups, #status, #terminated?, #to_s

Constructor Details

This class inherits a constructor from Instance

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Instance

Instance Method Details

#add_instances(instances) ⇒ Object



26
27
28
29
30
31
# File 'lib/maws/instance/elb.rb', line 26

def add_instances(instances)
  names = instances.map{|i| i.name}
  info "adding instances to ELB #{aws_id}: #{names.join(', ')}"
  connection.elb.register_instances_with_load_balancer(aws_id, instances.map{|i| i.aws_id})
  info "...done"
end

#attached_instancesObject



40
41
42
43
# File 'lib/maws/instance/elb.rb', line 40

def attached_instances
  instance_ids = @aws_description[:instances]
  @profile.defined_instances.select {|i| instance_ids.include?(i.aws_id)}
end

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/maws/instance/elb.rb', line 5

def create
  return if alive?
  info "creating ELB #{name}..."

  listeners = config(:listeners).dup || []

  server = connection.elb.create_load_balancer(name, @connection.availability_zones, listeners)
  connection.elb.configure_health_check(name, config(:health_check))

  description = server ? {:load_balancer_name => name} : {}
  sync_from_description(description)

  info "...done (ELB #{name} is ready)\n\n"
end

#destroyObject



20
21
22
23
24
# File 'lib/maws/instance/elb.rb', line 20

def destroy
  return unless alive?
  connection.elb.delete_load_balancer(aws_id)
  info "destroying ELB #{name}"
end

#disable_zones(zones) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/maws/instance/elb.rb', line 52

def disable_zones(zones)
  full_zones = zones.map {|z| command_options.region + z}
  info "disabling zones #{full_zones.join(', ')} for ELB #{aws_id}"

  if enabled_availability_zones.size <= 1
    info "can't remove last remaining zone: #{enabled_availability_zones.first}"
    return
  end

  connection.elb.disable_availability_zones_for_load_balancer(aws_id, full_zones)
  info "...done"
end

#display_fieldsObject



81
82
83
# File 'lib/maws/instance/elb.rb', line 81

def display_fields
  [:name, :status, :zones_list, :first_listener_info]
end

#enable_zones(zones) ⇒ Object



45
46
47
48
49
50
# File 'lib/maws/instance/elb.rb', line 45

def enable_zones(zones)
  full_zones = zones.map {|z| command_options.region + z}
  info "enabling zones #{full_zones.join(', ')} for ELB #{aws_id}..."
  connection.elb.enable_availability_zones_for_load_balancer(aws_id, full_zones)
  info "...done"
end

#enabled_availability_zonesObject



73
74
75
# File 'lib/maws/instance/elb.rb', line 73

def enabled_availability_zones
  description.availability_zones
end

#first_listener_infoObject



85
86
87
88
89
90
# File 'lib/maws/instance/elb.rb', line 85

def first_listener_info
  return "" unless alive?
  (description.listeners || [{}]).first.to_hash.collect do |key, val|
    "#{key}=#{val}"
  end.join("; ")
end

#physical_zoneObject



69
70
71
# File 'lib/maws/instance/elb.rb', line 69

def physical_zone
  nil
end

#remove_instances(instances) ⇒ Object



33
34
35
36
37
38
# File 'lib/maws/instance/elb.rb', line 33

def remove_instances(instances)
  names = instances.map{|i| i.name}
  info "removing instances to ELB #{aws_id}: #{names.join(', ')}"
  connection.elb.deregister_instances_with_load_balancer(aws_id, instances.map{|i| i.aws_id})
  info "...done"
end

#serviceObject



65
66
67
# File 'lib/maws/instance/elb.rb', line 65

def service
  :elb
end

#zones_listObject



77
78
79
# File 'lib/maws/instance/elb.rb', line 77

def zones_list
  (description.enabled_zones || []).join(', ')
end