Commit 5694ed93 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Add support of name resolution to allow use of hostname instead of IPs in configuration.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1464 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent b079ca14
...@@ -134,7 +134,6 @@ RC - Review output of pylint (CODE) ...@@ -134,7 +134,6 @@ RC - Review output of pylint (CODE)
an incoming packet that trigger the poll() system call. an incoming packet that trigger the poll() system call.
- Allow daemonize NEO processes, re-use code from TIDStorage and support - Allow daemonize NEO processes, re-use code from TIDStorage and support
start/stop/restart/status commands. start/stop/restart/status commands.
- Implement name resolution to allow use names instead of IPs
Storage Storage
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from ConfigParser import SafeConfigParser from ConfigParser import SafeConfigParser
from neo.util import bin, parseMasterList from neo import util
class ConfigurationManager(object): class ConfigurationManager(object):
...@@ -51,7 +51,7 @@ class ConfigurationManager(object): ...@@ -51,7 +51,7 @@ class ConfigurationManager(object):
if not masters: if not masters:
return [] return []
# load master node list except itself # load master node list except itself
return parseMasterList(masters, except_node=self.getBind()) return util.parseMasterList(masters, except_node=self.getBind())
def getBind(self): def getBind(self):
""" Get the address to bind to """ """ Get the address to bind to """
...@@ -62,6 +62,7 @@ class ConfigurationManager(object): ...@@ -62,6 +62,7 @@ class ConfigurationManager(object):
ip = bind ip = bind
# took port from default bind address # took port from default bind address
port = self.defaults['bind'].split(':')[1] port = self.defaults['bind'].split(':')[1]
ip = util.resolve(ip)
return (ip, int(port)) return (ip, int(port))
def getDatabase(self): def getDatabase(self):
...@@ -90,5 +91,5 @@ class ConfigurationManager(object): ...@@ -90,5 +91,5 @@ class ConfigurationManager(object):
def getUUID(self): def getUUID(self):
# only from command line # only from command line
return bin(self.argument_list.get('uuid', None)) return util.bin(self.argument_list.get('uuid', None))
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
import re import re
import socket
from zlib import adler32 from zlib import adler32
from struct import pack, unpack from struct import pack, unpack
...@@ -54,6 +55,19 @@ def makeChecksum(s): ...@@ -54,6 +55,19 @@ def makeChecksum(s):
"""Return a 4-byte integer checksum against a string.""" """Return a 4-byte integer checksum against a string."""
return adler32(s) & 0xffffffff return adler32(s) & 0xffffffff
def resolve(hostname):
"""
Returns the first IP address that match with the given hostname
"""
try:
# an IP resolves to itself
_, _, address_list = socket.gethostbyname_ex(hostname)
except socket.gaierror:
return None
return address_list[0]
def parseMasterList(masters, except_node=None): def parseMasterList(masters, except_node=None):
if not masters: if not masters:
return [] return []
...@@ -61,6 +75,7 @@ def parseMasterList(masters, except_node=None): ...@@ -61,6 +75,7 @@ def parseMasterList(masters, except_node=None):
master_node_list = [] master_node_list = []
for node in masters.split('/'): for node in masters.split('/'):
ip_address, port = node.split(':') ip_address, port = node.split(':')
ip_address = resolve(ip_address)
address = (ip_address, int(port)) address = (ip_address, int(port))
if (address != except_node): if (address != except_node):
master_node_list.append(address) master_node_list.append(address)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment