om支持ipv6适配补充
This commit is contained in:
parent
8e6c292c55
commit
5db64a85fc
@ -5,6 +5,7 @@ import socket
|
||||
|
||||
from base_utils.os.file_util import FileUtil
|
||||
from gspylib.common.ErrorCode import ErrorCode
|
||||
from base_utils.os.net_util import NetUtil
|
||||
|
||||
class HostsUtil:
|
||||
|
||||
@ -15,14 +16,20 @@ class HostsUtil:
|
||||
input: ip
|
||||
output: hostname
|
||||
"""
|
||||
ip_type = os.environ.get("IP_TYPE")
|
||||
if ip_type == NetUtil.NET_IPV6:
|
||||
socket_family = socket.AF_INET6
|
||||
else:
|
||||
socket_family = socket.AF_INET
|
||||
try:
|
||||
host_ip = socket.gethostbyname(hostname)
|
||||
if host_ip == "127.0.0.1":
|
||||
addr_info = socket.getaddrinfo(hostname, None, socket_family)
|
||||
host_ip = addr_info[0][NetUtil.ADDRESS_FAMILY_INDEX][NetUtil.IP_ADDRESS_INDEX]
|
||||
if host_ip == "127.0.0.1" or host_ip == "::1":
|
||||
return ""
|
||||
except Exception as e:
|
||||
host_ip = ""
|
||||
return host_ip
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_hostname_by_ip_from_etc_hosts(ip):
|
||||
"""
|
||||
@ -49,7 +56,7 @@ class HostsUtil:
|
||||
host_ip = HostsUtil.get_ip_by_hostname_from_etc_hosts(hostname)
|
||||
if host_ip:
|
||||
return host_ip
|
||||
|
||||
|
||||
# get ip from custom hosts file
|
||||
ip_str = ""
|
||||
hosts_file = FileUtil.get_hosts_file()
|
||||
@ -157,4 +164,3 @@ class HostsUtil:
|
||||
finally:
|
||||
lock.release()
|
||||
return True
|
||||
|
@ -435,11 +435,17 @@ General options:
|
||||
"""
|
||||
check parameter node must in xml config file
|
||||
"""
|
||||
ips_type = []
|
||||
backIpList = self.clusterInfo.getClusterBackIps()
|
||||
for nodeIp in self.newHostList:
|
||||
if nodeIp not in backIpList:
|
||||
GaussLog.exitWithError(ErrorCode.GAUSS_357["GAUSS_35702"] %
|
||||
nodeIp)
|
||||
ips_type.append(NetUtil.get_ip_version(nodeIp))
|
||||
if len(set(ips_type)) != 1:
|
||||
GaussLog.exitWithError(ErrorCode.GAUSS_506["GAUSS_50624"] +
|
||||
"The types of these ip addresses are %s" % ips_type + ". Please "
|
||||
"check it.")
|
||||
|
||||
def _getBackIpNameMap(self):
|
||||
backIpList = self.clusterInfo.getClusterBackIps()
|
||||
|
@ -1745,6 +1745,10 @@ Common options:
|
||||
basePort = node_info.datanodes[0].port
|
||||
FileUtil.writeFile(userProfile, ["export PGPORT=%d" % basePort])
|
||||
|
||||
# set IP_TYPE
|
||||
ip_type = NetUtil.get_ip_version(node_info.backIps[0])
|
||||
FileUtil.writeFile(userProfile, ["export IP_TYPE=%s" % ip_type])
|
||||
|
||||
# set PATH
|
||||
if userProfile is ClusterConstants.ETC_PROFILE:
|
||||
FileUtil.writeFile(userProfile, [
|
||||
|
Loading…
x
Reference in New Issue
Block a user