nodeutils: use socket.getaddrinfo instead of ipaddress

This changes uses getaddrinfo in nodeutils.keyscan to seemlesly support ip and
hostname.

Change-Id: If36d3180e588a6e6e6c63792d384b9a1e05f6fa0
This commit is contained in:
Tristan Cacqueray 2018-01-30 01:01:05 +00:00
parent 6c6cbfc209
commit 318e899b89
1 changed files with 3 additions and 8 deletions

View File

@ -17,9 +17,7 @@
# limitations under the License.
import errno
import ipaddress
import time
import six
import socket
import logging
@ -52,12 +50,9 @@ def keyscan(ip, port=22, timeout=60):
if 'fake' in ip:
return ['ssh-rsa FAKEKEY']
if ipaddress.ip_address(six.text_type(ip)).version < 6:
family = socket.AF_INET
sockaddr = (ip, port)
else:
family = socket.AF_INET6
sockaddr = (ip, port, 0, 0)
addrinfo = socket.getaddrinfo(ip, port)[0]
family = addrinfo[0]
sockaddr = addrinfo[4]
keys = []
key = None