Class: Puppet::Util::MongodbValidator
- Inherits:
-
Object
- Object
- Puppet::Util::MongodbValidator
- Defined in:
- lib/puppet/util/mongodb_validator.rb
Instance Attribute Summary collapse
-
#mongodb_port ⇒ Object
readonly
Returns the value of attribute mongodb_port.
-
#mongodb_server ⇒ Object
readonly
Returns the value of attribute mongodb_server.
Instance Method Summary collapse
-
#attempt_connection ⇒ Object
Utility method; attempts to make an https connection to the mongodb server.
-
#initialize(mongodb_resource_name, mongodb_server, mongodb_port) ⇒ MongodbValidator
constructor
A new instance of MongodbValidator.
Constructor Details
#initialize(mongodb_resource_name, mongodb_server, mongodb_port) ⇒ MongodbValidator
Returns a new instance of MongodbValidator.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/puppet/util/mongodb_validator.rb', line 13 def initialize(mongodb_resource_name, mongodb_server, mongodb_port) # NOTE: (spredzy) : By relying on the uri module # we rely on its well tested interface to parse # both IPv4 and IPv6 based URL with a port specified. # Unfortunately URI needs a scheme, hence the http # string here to make the string URI compliant. uri = URI("http://#{mongodb_resource_name}") @mongodb_server = IPAddr.new(uri.host).to_s @mongodb_port = uri.port rescue StandardError @mongodb_server = mongodb_server.to_s @mongodb_port = mongodb_port end |
Instance Attribute Details
#mongodb_port ⇒ Object (readonly)
Returns the value of attribute mongodb_port.
11 12 13 |
# File 'lib/puppet/util/mongodb_validator.rb', line 11 def mongodb_port @mongodb_port end |
#mongodb_server ⇒ Object (readonly)
Returns the value of attribute mongodb_server.
11 12 13 |
# File 'lib/puppet/util/mongodb_validator.rb', line 11 def mongodb_server @mongodb_server end |
Instance Method Details
#attempt_connection ⇒ Object
Utility method; attempts to make an https connection to the mongodb server. This is abstracted out into a method so that it can be called multiple times for retry attempts.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/puppet/util/mongodb_validator.rb', line 32 def attempt_connection Timeout.timeout(Puppet[:http_connect_timeout]) do TCPSocket.new(@mongodb_server, @mongodb_port).close true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e Puppet.debug "Unable to connect to mongodb server (#{@mongodb_server}:#{@mongodb_port}): #{e.}" false end rescue Timeout::Error false end |