Class: Awsborn::Elb
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- AwsConstants
- Defined in:
- lib/awsborn/elb.rb
Constant Summary
AwsConstants::AVAILABILITY_ZONES, AwsConstants::INSTANCE_TYPES, AwsConstants::INSTANCE_TYPES_32_BIT, AwsConstants::INSTANCE_TYPES_64_BIT, AwsConstants::REGIONS, AwsConstants::SYMBOL_CONSTANT_MAP
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#canonical_hosted_zone_name_id(balancer_name) ⇒ Object
-
#configure_health_check(balancer_name, health_check) ⇒ Object
-
#connection ⇒ Object
-
#create_load_balancer(balancer_name) ⇒ Object
-
#deregister_instances(balancer_name, instances) ⇒ Object
-
#describe_load_balancer(balancer_name) ⇒ Object
-
#disable_zones(balancer_name, zones) ⇒ Object
-
#dns_name(balancer_name) ⇒ Object
-
#enable_zones(balancer_name, zones) ⇒ Object
-
#health_status(balancer_name) ⇒ Object
-
#initialize(zone) ⇒ Elb
constructor
-
#instances(balancer_name) ⇒ Object
-
#register_instances(balancer_name, instances) ⇒ Object
-
#remove_all_cookie_policies(balancer_name) ⇒ Object
-
#running?(balancer_name) ⇒ Boolean
-
#set_app_cookie_policy(balancer_name, ports, cookie_name) ⇒ Object
-
#set_lb_cookie_policy(balancer_name, ports, expiration_period) ⇒ Object
-
#set_load_balancer_listeners(balancer_name, listeners) ⇒ Object
-
#zones(balancer_name) ⇒ Object
#aws_constant, #aws_instance_type_to_symbol, #aws_zone_to_symbol, #endpoint_for_zone_and_service, #symbol_to_aws_instance_type, #symbol_to_aws_zone, #zone_to_aws_region
Constructor Details
#initialize(zone) ⇒ Elb
Returns a new instance of Elb.
25
26
27
28
|
# File 'lib/awsborn/elb.rb', line 25
def initialize (zone)
@region = zone_to_aws_region(zone)
@endpoint = endpoint_for_zone_and_service(@region, :elb)
end
|
Instance Attribute Details
#endpoint ⇒ Object
Returns the value of attribute endpoint.
6
7
8
|
# File 'lib/awsborn/elb.rb', line 6
def endpoint
@endpoint
end
|
#region ⇒ Object
Returns the value of attribute region.
6
7
8
|
# File 'lib/awsborn/elb.rb', line 6
def region
@region
end
|
Instance Method Details
#canonical_hosted_zone_name_id(balancer_name) ⇒ Object
53
54
55
|
# File 'lib/awsborn/elb.rb', line 53
def canonical_hosted_zone_name_id (balancer_name)
describe_load_balancer(balancer_name)[:canonical_hosted_zone_name_id]
end
|
119
120
121
122
|
# File 'lib/awsborn/elb.rb', line 119
def configure_health_check (balancer_name, health_check)
logger.debug "Setting health check on load balancer #{balancer_name}"
connection.configure_health_check(balancer_name, health_check)
end
|
#connection ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/awsborn/elb.rb', line 8
def connection
unless @connection
env_ec2_url = ENV['ELB_URL']
begin
ENV['ELB_URL'] = @endpoint
@connection = RightAws::ElbInterface.new(
Awsborn.access_key_id,
Awsborn.secret_access_key,
:logger => Awsborn.logger
)
ensure
ENV['ELB_URL'] = env_ec2_url
end
end
@connection
end
|
#create_load_balancer(balancer_name) ⇒ Object
57
58
59
60
|
# File 'lib/awsborn/elb.rb', line 57
def create_load_balancer (balancer_name)
logger.debug "Creating load balancer #{balancer_name}"
connection.create_load_balancer(balancer_name, [@region+'a'], [])
end
|
#deregister_instances(balancer_name, instances) ⇒ Object
104
105
106
107
|
# File 'lib/awsborn/elb.rb', line 104
def deregister_instances (balancer_name, instances)
logger.debug "De-registering instances #{instances.inspect} on load balancer #{balancer_name}"
connection.deregister_instances_with_load_balancer(balancer_name, *instances)
end
|
#describe_load_balancer(balancer_name) ⇒ Object
30
31
32
|
# File 'lib/awsborn/elb.rb', line 30
def describe_load_balancer (balancer_name)
connection.describe_load_balancers(balancer_name).first
end
|
#disable_zones(balancer_name, zones) ⇒ Object
114
115
116
117
|
# File 'lib/awsborn/elb.rb', line 114
def disable_zones (balancer_name, zones)
logger.debug "Disabling zones #{zones.inspect} on load balancer #{balancer_name}"
connection.disable_availability_zones_for_load_balancer(balancer_name, *zones)
end
|
#dns_name(balancer_name) ⇒ Object
41
42
43
|
# File 'lib/awsborn/elb.rb', line 41
def dns_name (balancer_name)
describe_load_balancer(balancer_name)[:dns_name]
end
|
#enable_zones(balancer_name, zones) ⇒ Object
109
110
111
112
|
# File 'lib/awsborn/elb.rb', line 109
def enable_zones (balancer_name, zones)
logger.debug "Enabling zones #{zones.inspect} on load balancer #{balancer_name}"
connection.enable_availability_zones_for_load_balancer(balancer_name, *zones)
end
|
#health_status(balancer_name) ⇒ Object
124
125
126
|
# File 'lib/awsborn/elb.rb', line 124
def health_status (balancer_name)
connection.describe_instance_health(balancer_name, *instances(balancer_name))
end
|
#instances(balancer_name) ⇒ Object
45
46
47
|
# File 'lib/awsborn/elb.rb', line 45
def instances (balancer_name)
describe_load_balancer(balancer_name)[:instances]
end
|
#register_instances(balancer_name, instances) ⇒ Object
99
100
101
102
|
# File 'lib/awsborn/elb.rb', line 99
def register_instances (balancer_name, instances)
logger.debug "Registering instances #{instances.inspect} on load balancer #{balancer_name}"
connection.register_instances_with_load_balancer(balancer_name, *instances)
end
|
#remove_all_cookie_policies(balancer_name) ⇒ Object
92
93
94
95
96
97
|
# File 'lib/awsborn/elb.rb', line 92
def remove_all_cookie_policies(balancer_name)
description = describe_load_balancer(balancer_name)
description[:listeners].each do |listener|
connection.set_load_balancer_policies_of_listener(balancer_name, listener[:load_balancer_port])
end
end
|
#running?(balancer_name) ⇒ Boolean
34
35
36
37
38
39
|
# File 'lib/awsborn/elb.rb', line 34
def running? (balancer_name)
describe_load_balancer(balancer_name)
true
rescue RightAws::AwsError
false
end
|
#set_app_cookie_policy(balancer_name, ports, cookie_name) ⇒ Object
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/awsborn/elb.rb', line 81
def set_app_cookie_policy (balancer_name, ports, cookie_name)
logger.debug "Setting cookie policies for ports #{ports.inspect} on load balancer #{balancer_name}"
policy_name = "app-#{balancer_name}-#{cookie_name}".tr('_','-')
unless existing_app_cookie_policies(balancer_name).include?(policy_name)
connection.create_app_cookie_stickiness_policy(balancer_name, policy_name, cookie_name)
end
ports.each do |port|
connection.set_load_balancer_policies_of_listener(balancer_name, port, policy_name)
end
end
|
#set_lb_cookie_policy(balancer_name, ports, expiration_period) ⇒ Object
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/awsborn/elb.rb', line 70
def set_lb_cookie_policy (balancer_name, ports, expiration_period)
logger.debug "Setting cookie policies for ports #{ports.inspect} on load balancer #{balancer_name}"
policy_name = "lb-#{balancer_name}-#{expiration_period}".tr('_','-')
unless existing_lb_cookie_policies(balancer_name).include?(policy_name)
connection.create_lb_cookie_stickiness_policy(balancer_name, policy_name, expiration_period)
end
ports.each do |port|
connection.set_load_balancer_policies_of_listener(balancer_name, port, policy_name)
end
end
|
#set_load_balancer_listeners(balancer_name, listeners) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/awsborn/elb.rb', line 62
def set_load_balancer_listeners (balancer_name, listeners)
logger.debug "Setting listeners on load balancer #{balancer_name}"
description = describe_load_balancer(balancer_name)
previous_ports = description[:listeners].map{|i| i[:instance_port]}
connection.delete_load_balancer_listeners(balancer_name, *previous_ports) unless previous_ports.empty?
connection.create_load_balancer_listeners(balancer_name, listeners)
end
|
#zones(balancer_name) ⇒ Object
49
50
51
|
# File 'lib/awsborn/elb.rb', line 49
def zones (balancer_name)
describe_load_balancer(balancer_name)[:availability_zones]
end
|