mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Deprecation of ipaddr
Modified roster/scan to be IP-agnostic
This commit is contained in:
parent
34ccbda865
commit
2c111faac3
2 changed files with 21 additions and 7 deletions
|
@ -8,7 +8,8 @@ from __future__ import absolute_import
|
|||
import socket
|
||||
|
||||
# Import salt libs
|
||||
import salt.ext.ipaddr
|
||||
import salt.utils.network
|
||||
import salt.ext.ipaddress as ipaddress
|
||||
from salt.ext.six.moves import map # pylint: disable=import-error,redefined-builtin
|
||||
|
||||
|
||||
|
@ -41,20 +42,18 @@ class RosterMatcher(object):
|
|||
# Comma-separate list of integers
|
||||
ports = list(map(int, str(ports).split(',')))
|
||||
try:
|
||||
salt.ext.ipaddr.IPAddress(self.tgt)
|
||||
addrs = [self.tgt]
|
||||
addrs = [ipaddress.ip_address(self.tgt)]
|
||||
except ValueError:
|
||||
try:
|
||||
addrs = salt.ext.ipaddr.IPNetwork(self.tgt).iterhosts()
|
||||
addrs = ipaddress.ip_network(self.tgt).hosts()
|
||||
except ValueError:
|
||||
pass
|
||||
for addr in addrs:
|
||||
addr = str(addr)
|
||||
for port in ports:
|
||||
try:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock = salt.utils.network.get_socket(addr, socket.SOCK_STREAM)
|
||||
sock.settimeout(float(__opts__['ssh_scan_timeout']))
|
||||
sock.connect((addr, port))
|
||||
sock.connect((str(addr), port))
|
||||
sock.shutdown(socket.SHUT_RDWR)
|
||||
sock.close()
|
||||
ret[addr] = {'host': addr, 'port': port}
|
||||
|
|
|
@ -15,6 +15,7 @@ from string import ascii_letters, digits
|
|||
|
||||
# Import 3rd-party libs
|
||||
import salt.ext.six as six
|
||||
import salt.ext.ipaddress as ipaddress
|
||||
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
|
||||
# Attempt to import wmi
|
||||
try:
|
||||
|
@ -290,6 +291,20 @@ def generate_minion_id():
|
|||
return hosts[0]
|
||||
|
||||
|
||||
def get_socket(addr, type=socket.SOCK_STREAM, proto=0):
|
||||
'''
|
||||
Return a socket object for the addr
|
||||
IP-version agnostic
|
||||
'''
|
||||
|
||||
version = ipaddress.ip_address(addr).version
|
||||
if version == 4:
|
||||
family = socket.AF_INET
|
||||
elif version == 6:
|
||||
family = socket.AF_INET6
|
||||
return socket.socket(family, type, proto)
|
||||
|
||||
|
||||
def get_fqhostname():
|
||||
'''
|
||||
Returns the fully qualified hostname
|
||||
|
|
Loading…
Add table
Reference in a new issue