diff --git a/script/base_utils/os/hosts_util.py b/script/base_utils/os/hosts_util.py index f09dfcb..0d83f42 100644 --- a/script/base_utils/os/hosts_util.py +++ b/script/base_utils/os/hosts_util.py @@ -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 - \ No newline at end of file diff --git a/script/gs_expansion b/script/gs_expansion index 0bacb05..b5bb1c6 100644 --- a/script/gs_expansion +++ b/script/gs_expansion @@ -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() diff --git a/script/local/PreInstallUtility.py b/script/local/PreInstallUtility.py index ce25d8c..2ead21e 100644 --- a/script/local/PreInstallUtility.py +++ b/script/local/PreInstallUtility.py @@ -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, [