Class: Hako::Schedulers::EcsElb
- Inherits:
-
Object
- Object
- Hako::Schedulers::EcsElb
- Defined in:
- lib/hako/schedulers/ecs_elb.rb
Instance Method Summary collapse
- #describe_load_balancer ⇒ Object
- #destroy ⇒ Object
- #exist? ⇒ Boolean
- #find_or_create_load_balancer(front_port) ⇒ Object
-
#initialize(app_id, elb, elb_config) ⇒ EcsElb
constructor
A new instance of EcsElb.
- #name ⇒ Object
Constructor Details
#initialize(app_id, elb, elb_config) ⇒ EcsElb
Returns a new instance of EcsElb.
8 9 10 11 12 |
# File 'lib/hako/schedulers/ecs_elb.rb', line 8 def initialize(app_id, elb, elb_config) @app_id = app_id @elb = elb @elb_config = elb_config end |
Instance Method Details
#describe_load_balancer ⇒ Object
14 15 16 |
# File 'lib/hako/schedulers/ecs_elb.rb', line 14 def describe_load_balancer @elb.describe_load_balancers(load_balancer_names: [name]).load_balancer_descriptions[0] end |
#destroy ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/hako/schedulers/ecs_elb.rb', line 42 def destroy if exist? @elb.delete_load_balancer(load_balancer_name: name) Hako.logger.info "Deleted ELB #{name}" else Hako.logger.info "ELB #{name} doesn't exist" end end |
#exist? ⇒ Boolean
51 52 53 54 55 56 |
# File 'lib/hako/schedulers/ecs_elb.rb', line 51 def exist? describe_load_balancer true rescue Aws::ElasticLoadBalancing::Errors::LoadBalancerNotFound false end |
#find_or_create_load_balancer(front_port) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hako/schedulers/ecs_elb.rb', line 18 def find_or_create_load_balancer(front_port) if @elb_config unless exist? listeners = @elb_config.fetch('listeners').map do |l| { protocol: l.fetch('protocol'), load_balancer_port: l.fetch('load_balancer_port'), instance_port: front_port, ssl_certificate_id: l.fetch('ssl_certificate_id', nil), } end lb = @elb.create_load_balancer( load_balancer_name: name, listeners: listeners, subnets: @elb_config.fetch('subnets'), security_groups: @elb_config.fetch('security_groups'), tags: @elb_config.fetch('tags', {}).map { |k, v| { key: k, value: v.to_s } }, ) Hako.logger.info "Created ELB #{lb.dns_name} with instance_port=#{front_port}" end name end end |
#name ⇒ Object
58 59 60 |
# File 'lib/hako/schedulers/ecs_elb.rb', line 58 def name "hako-#{@app_id}" end |