Class: AwsRo::ElasticLoadBalancingV2::TargetGroup

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/aws_ro/elastic_load_balancing_v2/load_balancer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arn, client) ⇒ TargetGroup

Returns a new instance of TargetGroup.



79
80
81
82
# File 'lib/aws_ro/elastic_load_balancing_v2/load_balancer.rb', line 79

def initialize(arn, client)
  @target_group_arn = arn
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



74
75
76
# File 'lib/aws_ro/elastic_load_balancing_v2/load_balancer.rb', line 74

def client
  @client
end

#target_group_arnObject (readonly) Also known as: arn

Returns the value of attribute target_group_arn.



74
75
76
# File 'lib/aws_ro/elastic_load_balancing_v2/load_balancer.rb', line 74

def target_group_arn
  @target_group_arn
end

Instance Method Details

#ec2_instances(ec2_repository = nil) ⇒ Object



110
111
112
113
114
115
116
117
118
119
# File 'lib/aws_ro/elastic_load_balancing_v2/load_balancer.rb', line 110

def ec2_instances(ec2_repository = nil)
  ec2_repository ||= AwsRo::EC2::Repository.new(
    region: client.config.region,
    credentials: client.config.credentials
  )
  case type
  when 'instance' then ec2_repository.instance_ids(health_descriptions.keys)
  when 'ip' then ec2_repository.filters([{ name: 'network-interface.addresses.private-ip-address', values: health_descriptions.keys }])
  end
end

#health(instance_id = nil) ⇒ Object



84
85
86
87
# File 'lib/aws_ro/elastic_load_balancing_v2/load_balancer.rb', line 84

def health(instance_id = nil)
  return health_descriptions[instance_id] if instance_id
  health_descriptions.values
end

#instances(ec2_repository = nil) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/aws_ro/elastic_load_balancing_v2/load_balancer.rb', line 97

def instances(ec2_repository = nil)
  return [] if health_descriptions.empty?

  case type
  when 'instance','ip'
    ec2_instances(ec2_repository)
  when 'lambda'
    health_descriptions.values.map(&:target)
  else
    raise "Unsupported target-type: #{type}"
  end
end

#target_groupObject



89
90
91
# File 'lib/aws_ro/elastic_load_balancing_v2/load_balancer.rb', line 89

def target_group
  @target_group ||= client.describe_target_groups(target_group_arns: [arn]).target_groups.first
end

#target_typeObject



93
94
95
# File 'lib/aws_ro/elastic_load_balancing_v2/load_balancer.rb', line 93

def target_type
  @target_type ||= target_group.target_type
end

#typeObject



77
# File 'lib/aws_ro/elastic_load_balancing_v2/load_balancer.rb', line 77

alias type target_type