Skip to content

Commit

Permalink
Merge pull request #255 from EmilienM/providers/ipv6
Browse files Browse the repository at this point in the history
(MODULES-2983) Enable IPv6 in mongodb provider
  • Loading branch information
hunner committed Jan 19, 2016
2 parents dc31d79 + a77d1a1 commit 202ee76
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions lib/puppet/provider/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ def self.get_mongod_conf_file
file
end

def self.ipv6_is_enabled
file = get_mongod_conf_file
config = YAML.load_file(file)
if config.kind_of?(Hash)
ipv6 = config['net.ipv6']
else # It has to be a key-value store
config = {}
File.readlines(file).collect do |line|
k,v = line.split('=')
config[k.rstrip] = v.lstrip.chomp if k and v
end
ipv6 = config['ipv6']
end
ipv6
end

def self.get_conn_string
file = get_mongod_conf_file
# The mongo conf is probably a key-value store, even though 2.6 is
Expand Down Expand Up @@ -55,8 +71,11 @@ def self.get_conn_string

if bindip
first_ip_in_list = bindip.split(',').first
if first_ip_in_list.eql? '0.0.0.0'
case first_ip_in_list
when '0.0.0.0'
ip_real = '127.0.0.1'
when /\[?::0\]?/
ip_real = '::1'
else
ip_real = first_ip_in_list
end
Expand All @@ -80,7 +99,13 @@ def self.db_ismaster
if mongorc_file
cmd_ismaster = mongorc_file + cmd_ismaster
end
out = mongo(['admin', '--quiet', '--host', get_conn_string, '--eval', cmd_ismaster])
has_ipv6 = ipv6_is_enabled
if has_ipv6
ipv6 = '--ipv6'
else
ipv6 = ''
end
out = mongo(['admin', '--quiet', ipv6, '--host', get_conn_string, '--eval', cmd_ismaster])
out.gsub!(/ObjectId\(([^)]*)\)/, '\1')
out.gsub!(/ISODate\((.+?)\)/, '\1 ')
out.gsub!(/^Error\:.+/, '')
Expand Down Expand Up @@ -118,13 +143,19 @@ def self.mongo_eval(cmd, db = 'admin', retries = 10, host = nil)
cmd = mongorc_file + cmd
end

has_ipv6 = ipv6_is_enabled
if has_ipv6
ipv6 = '--ipv6'
else
ipv6 = ''
end
out = nil
retry_count.times do |n|
begin
if host
out = mongo([db, '--quiet', '--host', host, '--eval', cmd])
out = mongo([db, '--quiet', ipv6, '--host', host, '--eval', cmd])
else
out = mongo([db, '--quiet', '--host', get_conn_string, '--eval', cmd])
out = mongo([db, '--quiet', ipv6, '--host', get_conn_string, '--eval', cmd])
end
rescue => e
Puppet.debug "Request failed: '#{e.message}' Retry: '#{n}'"
Expand Down

0 comments on commit 202ee76

Please sign in to comment.