canonical / canonical/cloud-init
nocloud-datasource with numeric hostname
- Dominant language
- Python
- Stars
- 3.8k
- Forks
- 1.1k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 18
Description
This bug was originally filed in Launchpad as [LP: #1885880](https://bugs.launchpad.net/cloud-init/+bug/1885880)
Launchpad details
affected_projects = []
assignee = None
assignee_name = None
date_closed = None
date_created = 2020-07-01T08:35:09.466686+00:00
date_fix_committed = None
date_fix_released = None
id = 1885880
importance = undecided
is_complete = False
lp_url = https://bugs.launchpad.net/cloud-init/+bug/1885880
milestone = None
owner = tydice
owner_name = DHPark
private = False
status = triaged
submitter = tydice
submitter_name = DHPark
tags = []
duplicates = []
_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 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.
Contributor guide
Assessment
This issue has not been assessed yet.