Class: Cheftacular::Getter
- Inherits:
-
Object
- Object
- Cheftacular::Getter
- Defined in:
- lib/cheftacular/getter.rb
Instance Method Summary collapse
- #get_address_hash(node_name, load_out_of_env_addresses = false, ret = {}) ⇒ Object
- #get_addresses_hash(env = 'staging', ret_hash = {}, mode = "") ⇒ Object
- #get_current_database ⇒ Object
- #get_current_real_node_name(other_node_name = '', ret = '') ⇒ Object
- #get_current_repo_config ⇒ Object
- #get_current_role_map(run_list, ret = {}) ⇒ Object
- #get_current_role_nodes ⇒ Object
- #get_current_stack ⇒ Object
- #get_current_sub_stack ⇒ Object
- #get_db_primary_node_and_nodes ⇒ Object
- #get_repo_names_for_repositories(restrict_to = [{}], ret = {}) ⇒ Object
- #get_repository_from_role_name(name, *args) ⇒ Object
- #get_split_branch_hash(ret = {}) ⇒ Object
-
#get_true_node_objects(get_all_nodes = false) ⇒ Object
- TODO
-
if ridley changes its parsing strategy.
-
#initialize(options, config) ⇒ Getter
constructor
A new instance of Getter.
Constructor Details
#initialize(options, config) ⇒ Getter
Returns a new instance of Getter.
4 5 6 |
# File 'lib/cheftacular/getter.rb', line 4 def initialize , config @options, @config = , config end |
Instance Method Details
#get_address_hash(node_name, load_out_of_env_addresses = false, ret = {}) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/cheftacular/getter.rb', line 142 def get_address_hash node_name, load_out_of_env_addresses=false, ret={} break_on_found = false @config['chef_environments'].each do |env| next if !load_out_of_env_addresses && !@config.has_key?(env) #in case the env hashes are not loaded @config['initializer'].initialize_data_bags_for_environment(env, false, ['addresses']) if @options['env'] != env @config[env]['addresses_bag_hash']['addresses'].each do |serv_hash| if serv_hash['name'] == node_name ret[serv_hash['name']] = { "dn" => serv_hash['dn'], "priv" => serv_hash['address'], "pub" => serv_hash['public'] } break_on_found = true break end end break if break_on_found end ret end |
#get_addresses_hash(env = 'staging', ret_hash = {}, mode = "") ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/cheftacular/getter.rb', line 118 def get_addresses_hash env='staging', ret_hash={}, mode="" @config[env]['addresses_bag_hash']['addresses'].each do |serv_hash| ret_hash[serv_hash['public']] = serv_hash end if @config[env].has_key?('addresses_bag_hash') ret_hash end |
#get_current_database ⇒ Object
98 99 100 |
# File 'lib/cheftacular/getter.rb', line 98 def get_current_database get_current_repo_config['database'] end |
#get_current_real_node_name(other_node_name = '', ret = '') ⇒ Object
187 188 189 190 191 192 |
# File 'lib/cheftacular/getter.rb', line 187 def get_current_real_node_name other_node_name='', ret='' ret << @options['env'] + @config['cheftacular']['node_name_separator'] ret << ( other_node_name.blank? ? @options['node_name'] : other_node_name ) ret end |
#get_current_repo_config ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/cheftacular/getter.rb', line 102 def get_current_repo_config if @config['cheftacular']['repositories'].has_key?(@options['role']) @config['cheftacular']['repositories'][@options['role']] else @options['role'] end end |
#get_current_role_map(run_list, ret = {}) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/cheftacular/getter.rb', line 110 def get_current_role_map run_list, ret={} @config['cheftacular']['role_maps'].each_pair do |main_role, role_hash| ret = role_hash if run_list.include?("role[#{ role_hash['role_name'] }]") end ret end |
#get_current_role_nodes ⇒ Object
194 195 196 197 198 199 200 |
# File 'lib/cheftacular/getter.rb', line 194 def get_current_role_nodes nodes = @config['parser'].exclude_nodes( @config['getter'].get_true_node_objects, [{ unless: "role[#{ @options['role'] }]" }], !@options['run_on_all'] ) nodes = @config['parser'].exclude_nodes( nodes, [{ if: "role[#{ @options['negative_role'] }]" }]) if @options['negative_role'] nodes end |
#get_current_stack ⇒ Object
90 91 92 |
# File 'lib/cheftacular/getter.rb', line 90 def get_current_stack get_current_repo_config['stack'] end |
#get_current_sub_stack ⇒ Object
94 95 96 |
# File 'lib/cheftacular/getter.rb', line 94 def get_current_sub_stack get_current_repo_config['sub_stack'] end |
#get_db_primary_node_and_nodes ⇒ Object
127 128 129 130 131 132 |
# File 'lib/cheftacular/getter.rb', line 127 def get_db_primary_node_and_nodes nodes = get_true_node_objects true target_db_role = get_current_repo_config['db_primary_host_role'] [@config['parser'].exclude_nodes( nodes, [{ unless: "role[#{ target_db_role }]" }, { if: { not_env: @options['env'] } }], true), nodes] end |
#get_repo_names_for_repositories(restrict_to = [{}], ret = {}) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/cheftacular/getter.rb', line 164 def get_repo_names_for_repositories restrict_to=[{}], ret={} @config['cheftacular']['repositories'].each_pair do |name, repo_hash| unless restrict_to.empty? skip = false restrict_to.each do |restrict_hash| restrict_hash.each_pair do |key, val| skip = true if repo_hash[key.to_s] != val && restrict_hash.has_key?(:ignore_value) skip = true if val == 'NOT NIL' && repo_hash[key.to_s].nil? skip = true if val == 'NIL' && !repo_hash[key.to_s].nil? end end next if skip end ret[repo_hash['repo_name']] = repo_hash ret[repo_hash['repo_name']]['role'] = name end ret end |
#get_repository_from_role_name(name, *args) ⇒ Object
8 9 10 |
# File 'lib/cheftacular/getter.rb', line 8 def get_repository_from_role_name name, *args @config['dummy_sshkit'].get_repository_from_role_name( name, @config['cheftacular']['repositories'], args ) end |
#get_split_branch_hash(ret = {}) ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/cheftacular/getter.rb', line 134 def get_split_branch_hash ret={} @config['cheftacular']['repositories'].each_pair do |name, repo_hash| ret[repo_hash['name']] = repo_hash if repo_hash.has_key?('has_split_branches') && repo_hash['has_split_branches'] end ret end |
#get_true_node_objects(get_all_nodes = false) ⇒ Object
- TODO
-
if ridley changes its parsing strategy
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cheftacular/getter.rb', line 13 def get_true_node_objects get_all_nodes=false nodes, all_nodes, names, iter_arr, file_cache_nodes, h = [],[],[],[],[],{} @config['chef_nodes'] = @config['ridley'].node.all @config['helper'].completion_rate? 0, __method__ file_cache_nodes = @config['filesystem'].check_nodes_file_cache if @config['filesystem'].compare_file_node_cache_against_chef_nodes('equal') @config['chef_nodes'].each do |n| true_obj = if !file_cache_nodes.empty? && @config['parser'].array_of_nodes_contains_node_name?(file_cache_nodes, n.name) file_cache_nodes[@config['parser'].index_of_node_name_in_array_of_nodes(file_cache_nodes, n.name)] else @config['filesystem'].cleanup_file_caches('current-nodes') @config['ridley'].node.find(n.name) end iter_arr << n.name progress_value = (( iter_arr.length.to_f/@config['chef_nodes'].length.to_f )*100 ).floor @config['helper'].completion_rate? progress_value, __method__ all_nodes << true_obj next if !get_all_nodes && true_obj.chef_environment != @options['env'] && true_obj.chef_environment != '_default' if get_all_nodes h[n.name] = true_obj names << n.name next end if @options['role'] == 'all' next if true_obj.chef_environment == '_default' h[n.name] = true_obj names << n.name next end if @options['node_name'] && true_obj.name == @options['node_name'] h[n.name] = true_obj names << n.name next end if @options['address'] && true_obj.public_ipaddress == @options['address'] h[n.name] = true_obj names << n.name next end unless ( @options['address'] || @options['node_name'] ) if true_obj.run_list.include?("role[#{ @options['role'] }]") h[n.name] = true_obj names << n.name next #not needed here but good to keep in mind end end end names.sort.each { |name| nodes << h[name] } @config['filesystem'].write_nodes_file_cache(all_nodes) unless @config['filesystem'].compare_file_node_cache_against_chef_nodes('equal') puts("") unless @options['quiet'] nodes end |