[Libvirt-cim] [PATCH] live.full_hostname: Adjust mechanism to get FQDN
John Ferlan
jferlan at redhat.com
Tue Nov 19 13:25:43 UTC 2013
Using just socket.gethostbyaddr(socket.gethostname())[0] caused some
issues recently in one of my DHCP testing environments. Breaking down
the calls showed the following:
>>> socket.gethostname()
'dhcp-186-211.bos.redhat.com'
>>> socket.gethostbyname("dhcp-186-211.bos.redhat.com")
'10.16.186.211'
>>> socket.gethostbyaddr(socket.gethostname())[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
socket.herror: [Errno 1] Unknown host
While just a socket.gethostname() could have worked, using the
socket.getfqdn() seemed to be safer just in case.
---
lib/VirtLib/live.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/VirtLib/live.py b/lib/VirtLib/live.py
index c929e71..6a10474 100644
--- a/lib/VirtLib/live.py
+++ b/lib/VirtLib/live.py
@@ -100,6 +100,9 @@ def hostname(server):
return out
def full_hostname(server):
- """To return the fully qualifiec domain name(FQDN) of the system"""
+ """To return the fully qualified domain name(FQDN) of the system"""
- return socket.gethostbyaddr(socket.gethostname())[0]
+ if socket.getfqdn().find('.') >= 0:
+ return socket.getfqdn()
+ else:
+ return socket.gethostbyaddr(socket.gethostname())[0]
--
1.8.3.1
More information about the Libvirt-cim
mailing list