This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from rtyler/elb-rebase
Elb rebase
- Loading branch information
Showing
9 changed files
with
152 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'vagrant-aws/util/elb' | ||
|
||
module VagrantPlugins | ||
module AWS | ||
module Action | ||
# This registers instance in ELB | ||
class ElbDeregisterInstance | ||
include ElasticLoadBalancer | ||
|
||
def initialize(app, env) | ||
@app = app | ||
@logger = Log4r::Logger.new("vagrant_aws::action::elb_deregister_instance") | ||
end | ||
|
||
def call(env) | ||
if elb_name = env[:machine].provider_config.elb | ||
deregister_instance env, elb_name, env[:machine].id | ||
end | ||
@app.call(env) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'vagrant-aws/util/elb' | ||
|
||
module VagrantPlugins | ||
module AWS | ||
module Action | ||
# This registers instance in ELB | ||
class ElbRegisterInstance | ||
include ElasticLoadBalancer | ||
|
||
def initialize(app, env) | ||
@app = app | ||
@logger = Log4r::Logger.new("vagrant_aws::action::elb_register_instance") | ||
end | ||
|
||
def call(env) | ||
@app.call(env) | ||
if elb_name = env[:machine].provider_config.elb | ||
register_instance env, elb_name, env[:machine].id | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module VagrantPlugins | ||
module AWS | ||
module ElasticLoadBalancer | ||
|
||
def register_instance(env, elb_name, instance_id) | ||
env[:ui].info I18n.t("vagrant_aws.elb.registering", instance_id: instance_id, elb_name: elb_name), :new_line => false | ||
elb = get_load_balancer(env[:aws_elb], elb_name) | ||
unless elb.instances.include? instance_id | ||
elb.register_instances([instance_id]) | ||
env[:ui].info I18n.t("vagrant_aws.elb.ok"), :prefix => false | ||
adjust_availability_zones env, elb | ||
else | ||
env[:ui].info I18n.t("vagrant_aws.elb.skipped"), :prefix => false | ||
end | ||
end | ||
|
||
def deregister_instance(env, elb_name, instance_id) | ||
env[:ui].info I18n.t("vagrant_aws.elb.deregistering", instance_id: instance_id, elb_name: elb_name), :new_line => false | ||
elb = get_load_balancer(env[:aws_elb], elb_name) | ||
if elb.instances.include? instance_id | ||
elb.deregister_instances([instance_id]) | ||
env[:ui].info I18n.t("vagrant_aws.elb.ok"), :prefix => false | ||
adjust_availability_zones env, elb | ||
else | ||
env[:ui].info I18n.t("vagrant_aws.elb.skipped"), :prefix => false | ||
end | ||
end | ||
|
||
def adjust_availability_zones(env, elb) | ||
env[:ui].info I18n.t("vagrant_aws.elb.adjusting", elb_name: elb.id), :new_line => false | ||
|
||
instances = env[:aws_compute].servers.all("instance-id" => elb.instances) | ||
|
||
azs = if instances.empty? | ||
["#{env[:machine].provider_config.region}a"] | ||
else | ||
instances.map(&:availability_zone).uniq | ||
end | ||
|
||
az_to_disable = elb.availability_zones - azs | ||
az_to_enable = azs - elb.availability_zones | ||
|
||
elb.enable_availability_zones az_to_enable unless az_to_enable.empty? | ||
elb.disable_availability_zones az_to_disable unless az_to_disable.empty? | ||
|
||
env[:ui].info I18n.t("vagrant_aws.elb.ok"), :prefix => false | ||
end | ||
|
||
private | ||
|
||
def get_load_balancer(aws, name) | ||
aws.load_balancers.find { |lb| lb.id == name } or raise Errors::ElbDoesNotExistError | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters