Skip to content

Commit

Permalink
Introduce RQD_USE_IPV6_AS_HOSTNAME to get IPv6 address
Browse files Browse the repository at this point in the history
  • Loading branch information
splhack committed Dec 1, 2020
1 parent 068d0e3 commit 07d881d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions rqd/rqd/rqconstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
RQD_RETRY_STARTUP_CONNECT_DELAY = 30
RQD_RETRY_CRITICAL_REPORT_DELAY = 30
RQD_USE_IP_AS_HOSTNAME = True
RQD_USE_IPV6_AS_HOSTNAME = False
RQD_CREATE_USER_IF_NOT_EXISTS = True

KILL_SIGNAL = 9
Expand Down Expand Up @@ -182,6 +183,8 @@
LOAD_MODIFIER = config.getint(__section, "LOAD_MODIFIER")
if config.has_option(__section, "RQD_USE_IP_AS_HOSTNAME"):
RQD_USE_IP_AS_HOSTNAME = config.getboolean(__section, "RQD_USE_IP_AS_HOSTNAME")
if config.has_option(__section, "RQD_USE_IPV6_AS_HOSTNAME"):
RQD_USE_IPV6_AS_HOSTNAME = config.getboolean(__section, "RQD_USE_IPV6_AS_HOSTNAME")
if config.has_option(__section, "DEFAULT_FACILITY"):
DEFAULT_FACILITY = config.get(__section, "DEFAULT_FACILITY")
if config.has_option(__section, "LAUNCH_FRAME_USER_GID"):
Expand Down
8 changes: 6 additions & 2 deletions rqd/rqd/rqutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,17 @@ def checkAndCreateUser(username):

def getHostIp():
"""Returns the machine's local ip address"""
return socket.gethostbyname(socket.gethostname())
if rqd.rqconstants.RQD_USE_IPV6_AS_HOSTNAME:
return socket.getaddrinfo(socket.gethostname(), None, socket.AF_INET6)[0][4][0]
else:
return socket.gethostbyname(socket.gethostname())


def getHostname():
"""Returns the machine's fully qualified domain name"""
try:
if rqd.rqconstants.RQD_USE_IP_AS_HOSTNAME:
if rqd.rqconstants.RQD_USE_IP_AS_HOSTNAME or \
rqd.rqconstants.RQD_USE_IPV6_AS_HOSTNAME:
return getHostIp()
else:
return socket.gethostbyaddr(socket.gethostname())[0].split('.')[0]
Expand Down

0 comments on commit 07d881d

Please sign in to comment.