Module: Chef::Provisioning::SshDriver::Helpers
- Included in:
- Driver
- Defined in:
- lib/chef/provisioning/ssh_driver/helpers.rb
Instance Method Summary collapse
- #deep_hashify(machine_options) ⇒ Object
- #false_or_value(v) ⇒ Object
- #ip_is_valid?(given_ip) ⇒ Boolean
- #log_debug(str = false) ⇒ Object
- #log_info(str = false) ⇒ Object
- #log_ts(str) ⇒ Object
- #stringify_keys(hash) ⇒ Object
- #strip_hash_nil(val) ⇒ Object
- #symbolize_keys(hash) ⇒ Object
- #valid_ip?(given_ip) ⇒ Boolean
- #valid_ssh_options ⇒ Object
Instance Method Details
#deep_hashify(machine_options) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/chef/provisioning/ssh_driver/helpers.rb', line 102 def deep_hashify() if .respond_to?(:to_hash) hash = .to_hash hash.inject({}){|result, (key, value)| if value.respond_to?(:to_hash) new_value = deep_hashify(value) else new_value = value end result[key] = new_value result } end end |
#false_or_value(v) ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/chef/provisioning/ssh_driver/helpers.rb', line 118 def false_or_value(v) case v when "false" false when false false else v end end |
#ip_is_valid?(given_ip) ⇒ Boolean
155 156 157 158 |
# File 'lib/chef/provisioning/ssh_driver/helpers.rb', line 155 def ip_is_valid?(given_ip) valid_ip = ( given_ip =~ Resolv::IPv4::Regex || given_ip =~ Resolv::IPv6::Regex ) valid_ip end |
#log_debug(str = false) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/chef/provisioning/ssh_driver/helpers.rb', line 28 def log_debug(str = false) if str.kind_of?(String) if str.empty? return else if ENV['METAL_SSH_LOGGING_ENABLE'] put_val = [] put_val << "" put_val << ("=================== BEGIN LOG ENTRY ====================>") put_val << str put_val << ("=================== END LOG ENTRY ====================>") put_val << "" puts put_val else Chef::Log.debug("======================================>") Chef::Log.debug(str) Chef::Log.debug("======================================>") end end else return end end |
#log_info(str = false) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/chef/provisioning/ssh_driver/helpers.rb', line 6 def log_info(str = false) if str.kind_of?(String) && ENV['METAL_SSH_LOGGING_ENABLE'] if str.empty? return else log_debug(str) end else return end end |
#log_ts(str) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/chef/provisioning/ssh_driver/helpers.rb', line 18 def log_ts(str) put_val = [] put_val << "" put_val << ("=================== BEGIN LOG ENTRY ====================>") put_val << str put_val << ("=================== END LOG ENTRY ====================>") put_val << "" puts put_val end |
#stringify_keys(hash) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/chef/provisioning/ssh_driver/helpers.rb', line 77 def stringify_keys(hash) if hash.is_a?(Hash) hash.inject({}){|result, (key, value)| new_key = case key when Symbol key.to_s else key end new_value = case value when Hash stringify_keys(value) when String value else value end result[new_key] = new_value result } end end |
#strip_hash_nil(val) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/chef/provisioning/ssh_driver/helpers.rb', line 129 def strip_hash_nil(val) vvv = case val when Hash cleaned_val = val.delete_if { |kk,vv| vv.nil? || vv.empty? } cleaned_val.each do |k,v| case v when Hash strip_hash_nil(v) when Array v.flatten! v.uniq! end end end # puts "VVV is #{vvv}" vvv end |
#symbolize_keys(hash) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/chef/provisioning/ssh_driver/helpers.rb', line 52 def symbolize_keys(hash) if hash.is_a?(Hash) hash.inject({}){|result, (key, value)| new_key = case key when String key.to_sym else key end new_value = case value when Hash symbolize_keys(value) when String value else value end result[new_key] = new_value result } end end |
#valid_ip?(given_ip) ⇒ Boolean
147 148 149 150 151 152 153 |
# File 'lib/chef/provisioning/ssh_driver/helpers.rb', line 147 def valid_ip?(given_ip) if ip_is_valid?(given_ip) true else false end end |
#valid_ssh_options ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/chef/provisioning/ssh_driver/helpers.rb', line 160 def vso = [ :auth_methods, :bind_address, :compression, :compression_level, :config, :encryption, :forward_agent, :hmac, :host_key, :keepalive, :keepalive_interval, :kex, :keys, :key_data, :languages, :logger, :password, :paranoid, :port, :proxy, :rekey_blocks_limit, :rekey_limit, :rekey_packet_limit, :timeout, :verbose, :global_known_hosts_file, :user_known_hosts_file, :host_key_alias, :host_name, :user, :properties, :passphrase, :keys_only, :max_pkt_size, :max_win_size, :send_env, :use_agent ] vso end |