Class: ActiveAws::TargetGroup

Inherits:
Base
  • Object
show all
Defined in:
lib/active_aws/target_group.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

configure, inherited, #initialize, load_config!, #to_h

Constructor Details

This class inherits a constructor from ActiveAws::Base

Class Method Details

.clientObject



19
20
21
# File 'lib/active_aws/target_group.rb', line 19

def client
  Aws::ElasticLoadBalancingV2::Client.new( **configure.default_client_params )
end

.find(target_group_arn) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/active_aws/target_group.rb', line 23

def find( target_group_arn )
  response = client.describe_target_groups({
    target_group_arns: [target_group_arn], 
  })
  return nil unless response
  new( **response.target_groups[0].to_h )
end

.find_by_name(name) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/active_aws/target_group.rb', line 31

def find_by_name( name )
  response = client.describe_target_groups({
    names: [name], 
  })
  return nil unless response
  new( **response.target_groups[0].to_h )
end

.where(**args) ⇒ Object

Usage: where( load_balancer_arn: [“xxxx”] )



41
42
43
44
45
# File 'lib/active_aws/target_group.rb', line 41

def where( **args )
  filter_params = args.map{|k, v| { name: k, values: Array.wrap(v) }}
  response = client.describe_target_groups( args )
  response.target_groups.map{|i| new( **i.to_h )}
end

Instance Method Details

#deregister!(ids) ⇒ Object



74
75
76
77
78
79
# File 'lib/active_aws/target_group.rb', line 74

def deregister!( ids )
  response = self.class.client.deregister_targets({
    target_group_arn: target_group_arn,
    targets: ids.map{|a| { id: a }}, 
  })
end

#health_descriptionsObject



56
57
58
59
60
61
# File 'lib/active_aws/target_group.rb', line 56

def health_descriptions
  response = self.class.client.describe_target_health({
    target_group_arn: target_group_arn
  })
  response.target_health_descriptions
end

#nameObject



48
49
50
# File 'lib/active_aws/target_group.rb', line 48

def name
  target_group_name
end

#register!(ids) ⇒ Object



67
68
69
70
71
72
# File 'lib/active_aws/target_group.rb', line 67

def register!( ids )
  response = self.class.client.register_targets({
    target_group_arn: target_group_arn,
    targets: ids.map{|a| { id: a }}, 
  })
end

#reloadObject



52
53
54
# File 'lib/active_aws/target_group.rb', line 52

def reload
  self.class.find( target_group_arn )
end

#set!(ids) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/active_aws/target_group.rb', line 81

def set!( ids )
  present_ids     = target_ids
  register_ids    = ids.select{|a| ! present_ids.include?( a ) }
  deregister_ids  = present_ids.select{|a| ! ids.include?( a ) }
  # pp register_ids
  # pp deregister_ids
  register!( register_ids ) if register_ids.present?
  deregister!( deregister_ids ) if deregister_ids.present?
  target_ids
end

#target_idsObject



63
64
65
# File 'lib/active_aws/target_group.rb', line 63

def target_ids
  health_descriptions.map{|a| a.target.id }
end