Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nocloud-datasource with numeric hostname #3755

Open
ubuntu-server-builder opened this issue May 12, 2023 · 1 comment
Open

nocloud-datasource with numeric hostname #3755

ubuntu-server-builder opened this issue May 12, 2023 · 1 comment
Labels
bug Something isn't working correctly launchpad Migrated from Launchpad

Comments

@ubuntu-server-builder
Copy link
Collaborator

This bug was originally filed in Launchpad as LP: #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 <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.

@ubuntu-server-builder ubuntu-server-builder added bug Something isn't working correctly launchpad Migrated from Launchpad labels May 12, 2023
@ubuntu-server-builder
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly launchpad Migrated from Launchpad
Projects
None yet
Development

No branches or pull requests

1 participant