Revision bcf043c9 lib/utils.py
b/lib/utils.py | ||
---|---|---|
396 | 396 |
return names_filtered[0] |
397 | 397 |
|
398 | 398 |
|
399 |
class HostInfo: |
|
400 |
"""Class holding host info as returned by gethostbyname |
|
401 |
|
|
402 |
""" |
|
403 |
def __init__(self, name, aliases, ipaddrs): |
|
404 |
"""Initialize the host name object. |
|
405 |
|
|
406 |
Arguments are the same as returned by socket.gethostbyname_ex() |
|
407 |
|
|
408 |
""" |
|
409 |
self.name = name |
|
410 |
self.aliases = aliases |
|
411 |
self.ipaddrs = ipaddrs |
|
412 |
self.ip = self.ipaddrs[0] |
|
413 |
|
|
414 |
|
|
399 | 415 |
def LookupHostname(hostname): |
400 | 416 |
"""Look up hostname |
401 | 417 |
|
... | ... | |
403 | 419 |
hostname: hostname to look up, can be also be a non FQDN |
404 | 420 |
|
405 | 421 |
Returns: |
406 |
Dictionary with keys: |
|
407 |
- ip: IP addr |
|
408 |
- hostname_full: hostname fully qualified |
|
409 |
- hostname: hostname fully qualified (historic artifact) |
|
422 |
a HostInfo object |
|
410 | 423 |
|
411 | 424 |
""" |
412 | 425 |
try: |
413 |
(fqdn, dummy, ipaddrs) = socket.gethostbyname_ex(hostname) |
|
414 |
ipaddr = ipaddrs[0] |
|
426 |
(name, aliases, ipaddrs) = socket.gethostbyname_ex(hostname) |
|
415 | 427 |
except socket.gaierror: |
416 | 428 |
# hostname not found in DNS |
417 | 429 |
return None |
418 | 430 |
|
419 |
returnhostname = { |
|
420 |
"ip": ipaddr, |
|
421 |
"hostname_full": fqdn, |
|
422 |
"hostname": fqdn, |
|
423 |
} |
|
424 |
|
|
425 |
return returnhostname |
|
431 |
return HostInfo(name, aliases, ipaddrs) |
|
426 | 432 |
|
427 | 433 |
|
428 | 434 |
def ListVolumeGroups(): |
Also available in: Unified diff