Class: BjnInventory::SourceCommand::AwsElb
Instance Method Summary
collapse
#initialize, #logger, #run
Instance Method Details
#_retrieve_entries(current, client, marker = nil) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/bjn_inventory/source_command/aws_elb.rb', line 57
def _retrieve_entries(current, client, marker=nil)
logger.debug "Describing load balancers (page #{marker})"
chunk_result = client.describe_load_balancers(marker: marker, page_size: @page_size)
logger.debug "... described"
marker = chunk_result.next_marker
if chunk_result.load_balancer_descriptions.length > 0
chunk = Hash[chunk_result.load_balancer_descriptions.map { |lb| [lb.load_balancer_name, lb.to_h] }]
logger.debug "Describing load balancer tags"
chunk_tags = Hash[client.describe_tags(load_balancer_names: chunk.keys).tag_descriptions.map do |lbtags|
[lbtags.load_balancer_name, { tags: lbtags.to_h[:tags] }]
end]
logger.debug "... described"
chunk_list = chunk.map { |lbname, lb| lb.merge(chunk_tags[lbname]) }
else
chunk_list = [ ]
end
chunk_list = @filters.select(chunk_list)
if marker
return _retrieve_entries(current + chunk_list, client, marker)
else
return current + chunk_list
end
end
|
#new_client(region = nil) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/bjn_inventory/source_command/aws_elb.rb', line 42
def new_client(region=nil)
opts = {
region: (region || @regions.first)
}
opts.update({profile: @profile}) if @profile
Aws::ElasticLoadBalancing::Client.new(opts)
end
|
#new_ec2_client(region = nil) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/bjn_inventory/source_command/aws_elb.rb', line 34
def new_ec2_client(region=nil)
opts = {
region: (region || @regions.first)
}
opts.update({profile: @profile}) if @profile
Aws::EC2::Client.new(opts)
end
|
#retrieve_entries(override_client = nil) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/bjn_inventory/source_command/aws_elb.rb', line 50
def retrieve_entries(override_client=nil)
entries = @regions.map do |region|
client = override_client || @client || new_client(region)
_retrieve_entries([], client)
end.flatten
end
|
#set_options(opt) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/bjn_inventory/source_command/aws_elb.rb', line 11
def set_options(opt)
@page_size = opt[:page_size] || 20
@regions = nil
if opt[:region] and !opt[:region].empty?
@regions = opt[:region].respond_to?(:to_ary) ? opt[:region] : [ opt[:region] ]
region = @regions.first
else
region = 'us-west-2'
end
@filters = BjnInventory::Util::Filter::JsonAws.new(filters: opt[:filters] || '[ ]', logger: logger)
@client = opt[:client]
@ec2_client = opt[:ec2_client]
@profile = opt[:profile]
ec2_client = @ec2_client || new_ec2_client(region)
if @regions.nil? or @regions.empty?
logger.debug "Listing regions"
@regions = ec2_client.describe_regions().regions.map { |region| region.region_name }
end
end
|