diff --git a/cuebot/src/main/java/com/imageworks/spcue/dao/postgres/HostDaoJdbc.java b/cuebot/src/main/java/com/imageworks/spcue/dao/postgres/HostDaoJdbc.java index adee7843a..bf42f0ecb 100644 --- a/cuebot/src/main/java/com/imageworks/spcue/dao/postgres/HostDaoJdbc.java +++ b/cuebot/src/main/java/com/imageworks/spcue/dao/postgres/HostDaoJdbc.java @@ -658,6 +658,10 @@ private String getHostNameFromFQDN(String fqdn, Boolean useLongNames) { if (ipMatcher.matches()){ hostName = fqdn; } + else if (fqdn.contains(":")) { + // looks like IPv6 address. + hostName = fqdn; + } else if (useLongNames) { hostName = fqdn; Pattern domainPattern = Pattern.compile( diff --git a/cuebot/src/main/resources/conf/ddl/postgres/migrations/V7__Increase_hostname_length.sql b/cuebot/src/main/resources/conf/ddl/postgres/migrations/V7__Increase_hostname_length.sql new file mode 100644 index 000000000..0dce0f2fd --- /dev/null +++ b/cuebot/src/main/resources/conf/ddl/postgres/migrations/V7__Increase_hostname_length.sql @@ -0,0 +1,4 @@ +-- Increase the length of hostnames for IPv6 address. + +ALTER TABLE "host" ALTER COLUMN "str_name" TYPE VARCHAR(45); +ALTER TABLE "host_tag" ALTER COLUMN "str_tag" TYPE VARCHAR(45); diff --git a/cuebot/src/test/java/com/imageworks/spcue/test/dao/postgres/HostDaoTests.java b/cuebot/src/test/java/com/imageworks/spcue/test/dao/postgres/HostDaoTests.java index e24620323..9327fc8dd 100644 --- a/cuebot/src/test/java/com/imageworks/spcue/test/dao/postgres/HostDaoTests.java +++ b/cuebot/src/test/java/com/imageworks/spcue/test/dao/postgres/HostDaoTests.java @@ -203,6 +203,45 @@ public void testInsertHostFQDN4() { assertEquals(TEST_HOST_NEW, hostDetail.name); } + @Test + @Transactional + @Rollback(true) + public void testInsertHostIPv61() { + String TEST_HOST_NEW = "::1"; + hostDao.insertRenderHost(buildRenderHost(TEST_HOST_NEW), + hostManager.getDefaultAllocationDetail(), + false); + + HostEntity hostDetail = hostDao.findHostDetail(TEST_HOST_NEW); + assertEquals(TEST_HOST_NEW, hostDetail.name); + } + + @Test + @Transactional + @Rollback(true) + public void testInsertHostIPv62() { + String TEST_HOST_NEW = "ABCD:ABCD:ABCD:ABCD:ABCD:ABCD:ABCD:ABCD"; + hostDao.insertRenderHost(buildRenderHost(TEST_HOST_NEW), + hostManager.getDefaultAllocationDetail(), + false); + + HostEntity hostDetail = hostDao.findHostDetail(TEST_HOST_NEW); + assertEquals(TEST_HOST_NEW, hostDetail.name); + } + + @Test + @Transactional + @Rollback(true) + public void testInsertHostIPv63() { + String TEST_HOST_NEW = "ABCD:ABCD:ABCD:ABCD:ABCD:ABCD:192.168.100.180"; + hostDao.insertRenderHost(buildRenderHost(TEST_HOST_NEW), + hostManager.getDefaultAllocationDetail(), + false); + + HostEntity hostDetail = hostDao.findHostDetail(TEST_HOST_NEW); + assertEquals(TEST_HOST_NEW, hostDetail.name); + } + @Test @Transactional @Rollback(true) diff --git a/rqd/rqd/rqconstants.py b/rqd/rqd/rqconstants.py index 9ffd10273..0a1508e45 100644 --- a/rqd/rqd/rqconstants.py +++ b/rqd/rqd/rqconstants.py @@ -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_BECOME_JOB_USER = True RQD_CREATE_USER_IF_NOT_EXISTS = True RQD_TAGS = '' @@ -187,6 +188,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, "RQD_BECOME_JOB_USER"): RQD_BECOME_JOB_USER = config.getboolean(__section, "RQD_BECOME_JOB_USER") if config.has_option(__section, "RQD_TAGS"): diff --git a/rqd/rqd/rqutil.py b/rqd/rqd/rqutil.py index 6bdf3e5ba..67a50abe0 100644 --- a/rqd/rqd/rqutil.py +++ b/rqd/rqd/rqutil.py @@ -143,7 +143,10 @@ 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(): @@ -151,7 +154,8 @@ def getHostname(): try: if rqd.rqconstants.OVERRIDE_HOSTNAME: return rqd.rqconstants.OVERRIDE_HOSTNAME - elif rqd.rqconstants.RQD_USE_IP_AS_HOSTNAME: + elif 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]