class Applb::DSL::EC2::LoadBalancer::Result
Constants
- ATTRIBUTES
- CREATE_KEYS
Public Class Methods
new(context)
click to toggle source
# File lib/applb/dsl/load_balancer.rb, line 17 def initialize(context) @context = context @options = context.options end
Public Instance Methods
aws(aws_lb)
click to toggle source
# File lib/applb/dsl/load_balancer.rb, line 38 def aws(aws_lb) @aws_lb = aws_lb self end
create()
click to toggle source
# File lib/applb/dsl/load_balancer.rb, line 31 def create Applb.logger.info "Create ELB v2 #{name}" return if @options[:dry_run] client.create_load_balancer(create_option).load_balancers.first end
create_option()
click to toggle source
# File lib/applb/dsl/load_balancer.rb, line 27 def create_option to_h.select { |k, _| CREATE_KEYS.include?(k) } end
ip_address_type_updated?()
click to toggle source
# File lib/applb/dsl/load_balancer.rb, line 51 def ip_address_type_updated? ip_address_type != @aws_lb.ip_address_type end
modify_ip_address_type()
click to toggle source
# File lib/applb/dsl/load_balancer.rb, line 91 def modify_ip_address_type return unless ip_address_type_updated? Applb.logger.info "Modify #{name} ip_address_type" diff = Applb::Utils.diff( @aws_lb.ip_address_type, ip_address_type, color: @options[:color], ) Applb.logger.info("<diff>\n#{diff}") return if @options[:dry_run] client.set_ip_address_type( load_balancer_arn: @aws_lb.load_balancer_arn, ip_address_type: ip_address_type, ).ip_address_type end
modify_load_balancer_attributes()
click to toggle source
# File lib/applb/dsl/load_balancer.rb, line 109 def modify_load_balancer_attributes attrs = attributes.map do |attr| {key: attr[:key], value: attr[:value].to_s} end log_enabled = attrs.find { |attr| attr[:key] == 'access_logs.s3.enabled' }[:value] if log_enabled.to_s == 'false' attrs.reject! do |attr| %w/access_logs.s3.bucket access_logs.s3.prefix/.include?(attr[:key]) end end dsl_hash = attrs.map { |a| a.to_h }.sort { |a, b| a[:key] <=> b[:key] } aws_attributes = client.describe_load_balancer_attributes( load_balancer_arn: @aws_lb.load_balancer_arn, ).attributes aws_hash = aws_attributes.map { |a| a.to_h }.sort { |a, b| a[:key] <=> b[:key] } aws_log_enabled = aws_attributes.find { |attr| attr[:key] == 'access_logs.s3.enabled' }[:value] if aws_log_enabled == 'false' aws_hash.reject! do |attr| %w/access_logs.s3.bucket access_logs.s3.prefix/.include?(attr[:key]) end end return if dsl_hash == aws_hash Applb.logger.info "Modify #{name} load_balancer_attributes" Applb.logger.info("<diff>\n#{Applb::Utils.diff(aws_hash, dsl_hash, color: @options[:color])}") return if @options[:dry_run] client.modify_load_balancer_attributes( load_balancer_arn: @aws_lb.load_balancer_arn, attributes: attrs, ).attributes end
modify_security_groups()
click to toggle source
# File lib/applb/dsl/load_balancer.rb, line 73 def modify_security_groups return unless security_groups_updated? Applb.logger.info "Modify #{name} security_groups" diff = Applb::Utils.diff( @aws_lb.security_groups.sort, security_groups.sort, color: @options[:color], ) Applb.logger.info("<diff>\n#{diff}") return if @options[:dry_run] client.set_security_groups( load_balancer_arn: @aws_lb.load_balancer_arn, security_groups: security_groups, ).security_group_ids end
modify_subnets()
click to toggle source
# File lib/applb/dsl/load_balancer.rb, line 55 def modify_subnets return unless subnets_updated? Applb.logger.info("Modify #{name} subnets") diff = Applb::Utils.diff( @aws_lb.availability_zones.map(&:subnet_id).sort, subnets.sort, color: @options[:color], ) Applb.logger.info("<diff>\n#{diff}") return if @options[:dry_run] client.set_subnets( load_balancer_arn: @aws_lb.load_balancer_arn, subnets: subnets, ).availability_zones end
security_groups_updated?()
click to toggle source
# File lib/applb/dsl/load_balancer.rb, line 47 def security_groups_updated? security_groups.sort != @aws_lb.security_groups.sort end
subnets_updated?()
click to toggle source
# File lib/applb/dsl/load_balancer.rb, line 43 def subnets_updated? subnets.sort != @aws_lb.availability_zones.map(&:subnet_id).sort end
to_h()
click to toggle source
# File lib/applb/dsl/load_balancer.rb, line 22 def to_h Hash[ATTRIBUTES.sort.map { |name| [name, public_send(name)] }] end
Private Instance Methods
client()
click to toggle source
# File lib/applb/dsl/load_balancer.rb, line 146 def client @client ||= Applb::ClientWrapper.new(@options) end