Module: Bcome::FogHelper
- Included in:
- Stack::Environment
- Defined in:
- lib/helpers/fog_helper.rb
Instance Method Summary collapse
- #colour_code_for_server_status ⇒ Object
- #credentials_key ⇒ Object
- #ec2_filters ⇒ Object
-
#ec2_tags ⇒ Object
———————————————————————.
- #filter_by_tags(instances) ⇒ Object
- #fog_client ⇒ Object
- #instance_matches_tags?(instance) ⇒ Boolean
- #reload! ⇒ Object
-
#render_servers_not_returned_by_filtered_lookup ⇒ Object
smell.
- #servers(all = unfiltered_servers) ⇒ Object
- #servers_not_returned_by_filtered_lookup ⇒ Object
- #show_all_unfiltered_status? ⇒ Boolean
- #unfiltered_fog_lookup ⇒ Object
- #unfiltered_search_params ⇒ Object
-
#unfiltered_servers ⇒ Object
Misnomer - these are filtered.
Instance Method Details
#colour_code_for_server_status ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/helpers/fog_helper.rb', line 41 def colour_code_for_server_status { "pending" => :headsup, "running" => :friendly, "terminated" => :menu_item_white, #durr "stopping" => :headsup, "stopped" => :danger } end |
#credentials_key ⇒ Object
3 4 5 |
# File 'lib/helpers/fog_helper.rb', line 3 def credentials_key network_lookup[:credentials_key] end |
#ec2_filters ⇒ Object
11 12 13 |
# File 'lib/helpers/fog_helper.rb', line 11 def ec2_filters network_lookup[:ec2_server_lookup_filters] ? network_lookup[:ec2_server_lookup_filters] : unfiltered_search_params end |
#ec2_tags ⇒ Object
70 71 72 |
# File 'lib/helpers/fog_helper.rb', line 70 def network_lookup[:ec2_tag_filter] end |
#filter_by_tags(instances) ⇒ Object
88 89 90 |
# File 'lib/helpers/fog_helper.rb', line 88 def (instances) return instances.select{|instance| (instance)} end |
#fog_client ⇒ Object
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
92 93 94 95 |
# File 'lib/helpers/fog_helper.rb', line 92 def (instance) = instance. return .select{|key, value| [key.to_s] == value }.size == .keys.size end |
#reload! ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/helpers/fog_helper.rb', line 15 def reload! @unfiltered_servers = fog_client.servers.all(ec2_filters) @resources = do_load_resources @node = construct_node system("clear") list end |
#render_servers_not_returned_by_filtered_lookup ⇒ Object
smell
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/helpers/fog_helper.rb', line 30 def render_servers_not_returned_by_filtered_lookup return unless show_all_unfiltered_status? unfiltered_servers = servers(servers_not_returned_by_filtered_lookup) if unfiltered_servers.any? puts "\n#{network_lookup[:show_all_unfiltered_title]}".informational puts unfiltered_servers.collect{|server| "#{server.["Name"].} - #{server.state.send(colour_code_for_server_status[server.state])}" }.join("\n") end end |
#servers(all = unfiltered_servers) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/helpers/fog_helper.rb', line 74 def servers(all = unfiltered_servers) = ? (all) : all custom_filter_method = @meta_data[:network_lookup][:custom_post_process_filter_method] if custom_filter_method filter = ::Bcome::Filter::Ec2Filter.new(, self) raise "Custom 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 end end |
#servers_not_returned_by_filtered_lookup ⇒ Object
51 52 53 54 |
# File 'lib/helpers/fog_helper.rb', line 51 def servers_not_returned_by_filtered_lookup filtered_lookup_names = resources.collect(&:identifier) return unfiltered_fog_lookup.select{|server| !filtered_lookup_names.include?(server.["Name"]) } end |
#show_all_unfiltered_status? ⇒ Boolean
60 61 62 |
# File 'lib/helpers/fog_helper.rb', line 60 def show_all_unfiltered_status? self.network_lookup[:show_all_unfiltered] end |
#unfiltered_fog_lookup ⇒ Object
56 57 58 |
# File 'lib/helpers/fog_helper.rb', line 56 def unfiltered_fog_lookup fog_client.servers.all(unfiltered_search_params) end |
#unfiltered_search_params ⇒ Object
23 24 25 |
# File 'lib/helpers/fog_helper.rb', line 23 def unfiltered_search_params { 'instance-id' => [] } end |
#unfiltered_servers ⇒ Object
Misnomer - these are filtered
64 65 66 |
# File 'lib/helpers/fog_helper.rb', line 64 def unfiltered_servers ### Misnomer - these are filtered @unfiltered_servers ||= fog_client.servers.all(ec2_filters) end |