Open ubuntu-server-builder opened 1 year ago
Launchpad user Chad Smith(chad.smith) wrote on 2020-07-03T02:30:59.676568+00:00
Thanks for filing this bug and making cloud-init better.
RFC 1123 says hostname can start with digits and contain only digits. https://tools.ietf.org/html/rfc1123 I think this is a fair feature/bug request.
This bug was originally filed in Launchpad as LP: #1885880
Launchpad details
Launchpad user DHPark(tydice) wrote on 2020-07-01T08:35:09.466686+00:00
When I use nocloud datasource with numeric hostname like 1234, it shows errors as follow, 2020-07-01 06:37:49,018 - util.py[DEBUG]: Getting data from <class 'cloudinit.sources.DataSourceNoCloud.DataSourceNoCloud'> failed Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/cloudinit/sources/init.py", line 733, in find_source if s.update_metadata([EventType.BOOT_NEW_INSTANCE]): File "/usr/lib/python2.7/site-packages/cloudinit/sources/init.py", line 622, in update_metadata result = self.get_data() File "/usr/lib/python2.7/site-packages/cloudinit/sources/init.py", line 259, in get_data self.persist_instance_data() File "/usr/lib/python2.7/site-packages/cloudinit/sources/init.py", line 289, in persist_instance_data self._get_standardized_metadata()) File "/usr/lib/python2.7/site-packages/cloudinit/sources/init.py", line 209, in _get_standardized_metadata local_hostname = self.get_hostname() File "/usr/lib/python2.7/site-packages/cloudinit/sources/init.py", line 566, in get_hostname if util.is_ipv4(lhost): File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 544, in is_ipv4 toks = instr.split('.') AttributeError: 'int' object has no attribute 'split'
In get_hostname function in cloudinit/sources/init.py,
601 else:
602 # if there is an ipv4 address in 'local-hostname', then
603 # make up a hostname (LP: #475354) in format ip-xx.xx.xx.xx
604 lhost = self.metadata['local-hostname']
605 if net.is_ipv4_address(lhost):
606 toks = []
607 if resolve_ip:
608 toks = util.gethostbyaddr(lhost)
609
610 if toks:
611 toks = str(toks).split('.')
612 else:
613 toks = ["ip-%s" % lhost.replace(".", "-")]
614 else:
615 toks = lhost.split(".")
before utilize lhost, it needs to convert to string type like -> net.is_ipv4_address(str(lhost)) -> str(lhost).split(".") because when hostname is numeric only, lhost type would be integer by default in python.