class Awful::Elb
Constants
- COLORS
Public Instance Methods
all_matching_elbs(name)
click to toggle source
cannot search ELBs by tag, so just name here
# File lib/awful/elb.rb, line 20 def all_matching_elbs(name) elb.describe_load_balancers.map(&:load_balancer_descriptions).flatten.select do |elb| elb.load_balancer_name.match(name) end end
color(string)
click to toggle source
# File lib/awful/elb.rb, line 15 def color(string) set_color(string, COLORS.fetch(string.to_sym, :yellow)) end
create(name)
click to toggle source
# File lib/awful/elb.rb, line 106 def create(name) whitelist = %i[load_balancer_name listeners availability_zones subnets security_groups scheme tags] opt = load_cfg opt[:load_balancer_name] = name opt[:listeners] = opt.fetch(:listener_descriptions, []).map { |l| l[:listener] } opt.delete(:availability_zones) unless opt.fetch(:subnets, []).empty? opt = remove_empty_strings(opt) opt = only_keys_matching(opt, whitelist) elb.create_load_balancer(opt).map(&:dns_name).flatten.output { |dns| puts dns } health_check(name) if opt[:health_check] end
delete(name)
click to toggle source
# File lib/awful/elb.rb, line 133 def delete(name) if yes? "really delete ELB #{name}?", :yellow elb.delete_load_balancer(load_balancer_name: name) end end
deregister(name, *instances)
click to toggle source
# File lib/awful/elb.rb, line 145 def deregister(name, *instances) elb.deregister_instances_from_load_balancer(load_balancer_name: name, instances: instance_ids(*instances)) end
dns(name)
click to toggle source
# File lib/awful/elb.rb, line 99 def dns(name) all_matching_elbs(name).map(&:dns_name).output do |dns_names| puts dns_names end end
dump(name)
click to toggle source
# File lib/awful/elb.rb, line 72 def dump(name) all_matching_elbs(name).map(&:to_hash).output do |elbs| elbs.each do |elb| puts YAML.dump(stringify_keys(elb)) end end end
health_check(name)
click to toggle source
# File lib/awful/elb.rb, line 124 def health_check(name) opt = load_cfg.merge(options.reject(&:nil?)) hc = elb.configure_health_check(load_balancer_name: name, health_check: opt[:health_check]) hc.map(&:health_check).flatten.first.output do |h| print_table h.to_hash end end
instance_ids(*ids)
click to toggle source
get array of instance_id hashes in form expected by get methods
# File lib/awful/elb.rb, line 27 def instance_ids(*ids) ids.map do |id| {instance_id: id} end end
instances(name)
click to toggle source
# File lib/awful/elb.rb, line 50 def instances(name) instances = all_matching_elbs(name).map do |e| elb.describe_instance_health(load_balancer_name: e.load_balancer_name).map(&:instance_states) end.flatten if instances.empty? instances.output { puts 'no instances' } else instances_by_id = instances.inject({}) { |hash,instance| hash[instance.instance_id] = instance; hash } if options[:long] ec2.describe_instances(instance_ids: instances_by_id.keys).map(&:reservations).flatten.map(&:instances).flatten.map do |instance| health = instances_by_id[instance.instance_id] instance_name = tag_name(instance) || '-' [ instance.instance_id, instance_name, instance.public_ip_address, color(health.state), health.reason_code, health.description ] end.output { |list| print_table list } else instances_by_id.keys.output { |list| puts list } end end end
ls(name = /./)
click to toggle source
# File lib/awful/elb.rb, line 36 def ls(name = /./) all_matching_elbs(name).output do |elbs| if options[:long] print_table elbs.map { |e| [e.load_balancer_name, e.instances.length, e.availability_zones.join(','), e.dns_name] }.sort else puts elbs.map(&:load_balancer_name).sort end end end
register(name, *instances)
click to toggle source
# File lib/awful/elb.rb, line 140 def register(name, *instances) elb.register_instances_with_load_balancer(load_balancer_name: name, instances: instance_ids(*instances)) end
state(name, *instances)
click to toggle source
# File lib/awful/elb.rb, line 151 def state(name, *instances) elb.describe_instance_health(load_balancer_name: name, instances: instance_ids(*instances)).instance_states.output do |list| if options[:long] print_table list.map { |i| [ i.instance_id, color(i.state), i.reason_code, i.description ] } else puts list.map(&:state) end end end
tag(name, key)
click to toggle source
# File lib/awful/elb.rb, line 90 def tag(name, key) elb.describe_tags(load_balancer_names: [name]).tag_descriptions.first.tags.find do |tag| tag.key == key end.output do |tag| puts tag.value end end