Module: Bcome::FogHelper

Included in:
Stack::Environment
Defined in:
lib/helpers/fog_helper.rb

Instance Method Summary collapse

Instance Method Details

#credentials_keyObject



3
4
5
# File 'lib/helpers/fog_helper.rb', line 3

def credentials_key
  network_lookup[:credentials_key]
end

#ec2_tagsObject



15
16
17
# File 'lib/helpers/fog_helper.rb', line 15

def ec2_tags
  network_lookup[:ec2_tag_filter]
end

#filter_by_tags(instances) ⇒ Object



34
35
36
# File 'lib/helpers/fog_helper.rb', line 34

def filter_by_tags(instances)
  return instances.select{|instance| instance_matches_tags?(instance)}
end

#fog_clientObject



7
8
9
# File 'lib/helpers/fog_helper.rb', line 7

def fog_client
  @fog_client ||= get_fog_client
end

#instance_matches_tags?(instance) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/helpers/fog_helper.rb', line 38

def instance_matches_tags?(instance)
  tags = instance.tags
  return ec2_tags.select{|key, value| tags[key.to_s] == value }.size == ec2_tags.keys.size
end

#serversObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/helpers/fog_helper.rb', line 19

def servers
  all = unfiltered_servers
  filtered_by_tags = ec2_tags ? filter_by_tags(all) : all
  
  custom_filter_method = @meta_data[:network_lookup][:custom_post_process_filter_method]

  if custom_filter_method
    filter = ::Bcome::Filter::Ec2Filter.new(filtered_by_tags, self)
    raise "Custome filter method #{custom_filter_method} is missing. Make sure you've added it".failure unless filter.respond_to?(custom_filter_method.to_sym)
    return filter.send(custom_filter_method.to_sym) 
  else
    return filtered_by_tags
  end
end

#unfiltered_serversObject



11
12
13
# File 'lib/helpers/fog_helper.rb', line 11

def unfiltered_servers
  @unfiltered_servers ||= fog_client.servers.all(network_lookup[:ec2_server_lookup_filters])
end