nocloud-datasource with numeric hostname

Bug #1885880 reported by DHPark
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Expired
Undecided
Unassigned

Bug Description

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.

Revision history for this message
Chad Smith (chad.smith) wrote :

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.

Changed in cloud-init:
status: New → Triaged
Revision history for this message
James Falcon (falcojr) wrote :
Changed in cloud-init:
status: Triaged → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.