mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #29334 from rallytime/bp-29237
Back-port #29237 to 2015.8
This commit is contained in:
commit
17d80c051a
3 changed files with 32 additions and 36 deletions
|
@ -528,7 +528,11 @@ def netstat():
|
|||
|
||||
def active_tcp():
|
||||
'''
|
||||
Return a dict containing information on all of the running TCP connections
|
||||
Return a dict containing information on all of the running TCP connections (currently linux and solaris only)
|
||||
|
||||
.. versionchanged:: 2015.8.4
|
||||
|
||||
Added support for SunOS
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -536,7 +540,25 @@ def active_tcp():
|
|||
|
||||
salt '*' network.active_tcp
|
||||
'''
|
||||
return salt.utils.network.active_tcp()
|
||||
if __grains__['kernel'] == 'Linux':
|
||||
return salt.utils.network.active_tcp()
|
||||
elif __grains__['kernel'] == 'SunOS':
|
||||
# lets use netstat to mimic linux as close as possible
|
||||
ret = {}
|
||||
for connection in _netstat_sunos():
|
||||
if not connection['proto'].startswith('tcp'):
|
||||
continue
|
||||
if connection['state'] != 'ESTABLISHED':
|
||||
continue
|
||||
ret[len(ret)+1] = {
|
||||
'local_addr': '.'.join(connection['local-address'].split('.')[:-1]),
|
||||
'local_port': '.'.join(connection['local-address'].split('.')[-1:]),
|
||||
'remote_addr': '.'.join(connection['remote-address'].split('.')[:-1]),
|
||||
'remote_port': '.'.join(connection['remote-address'].split('.')[-1:])
|
||||
}
|
||||
return ret
|
||||
else:
|
||||
return {}
|
||||
|
||||
|
||||
def traceroute(host):
|
||||
|
@ -655,6 +677,7 @@ def traceroute(host):
|
|||
return ret
|
||||
|
||||
|
||||
@decorators.which('dig')
|
||||
def dig(host):
|
||||
'''
|
||||
Performs a DNS lookup with dig
|
||||
|
@ -1158,13 +1181,13 @@ def _get_bufsize_linux(iface):
|
|||
|
||||
def get_bufsize(iface):
|
||||
'''
|
||||
Return network buffer sizes as a dict
|
||||
Return network buffer sizes as a dict (currently linux only)
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' network.getbufsize
|
||||
salt '*' network.get_bufsize
|
||||
'''
|
||||
if __grains__['kernel'] == 'Linux':
|
||||
if os.path.exists('/sbin/ethtool'):
|
||||
|
@ -1210,7 +1233,7 @@ def mod_bufsize(iface, *args, **kwargs):
|
|||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' network.getBuffers
|
||||
salt '*' network.mod_bufsize tx=<val> rx=<val> rx-mini=<val> rx-jumbo=<val>
|
||||
'''
|
||||
if __grains__['kernel'] == 'Linux':
|
||||
if os.path.exists('/sbin/ethtool'):
|
||||
|
@ -1288,6 +1311,8 @@ def default_route(family=None):
|
|||
for route in _routes:
|
||||
if family:
|
||||
if route['destination'] in default_route[family]:
|
||||
if __grains__['kernel'] == 'SunOS' and route['addr_family'] != family:
|
||||
continue
|
||||
ret.append(route)
|
||||
else:
|
||||
if route['destination'] in default_route['inet'] or \
|
||||
|
|
|
@ -47,12 +47,6 @@ def sanitize_host(host):
|
|||
def isportopen(host, port):
|
||||
'''
|
||||
Return status of a port
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' network.isportopen 127.0.0.1 22
|
||||
'''
|
||||
|
||||
if not 1 <= int(port) <= 65535:
|
||||
|
@ -67,12 +61,6 @@ def isportopen(host, port):
|
|||
def host_to_ip(host):
|
||||
'''
|
||||
Returns the IP address of a given hostname
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' network.host_to_ip example.com
|
||||
'''
|
||||
try:
|
||||
family, socktype, proto, canonname, sockaddr = socket.getaddrinfo(
|
||||
|
@ -271,12 +259,6 @@ def generate_minion_id():
|
|||
'''
|
||||
Returns a minion id after checking multiple sources for a FQDN.
|
||||
If no FQDN is found you may get an ip address
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' network.generate_minion_id
|
||||
'''
|
||||
possible_ids = get_hostnames()
|
||||
|
||||
|
@ -314,12 +296,6 @@ def get_socket(addr, type=socket.SOCK_STREAM, proto=0):
|
|||
def get_fqhostname():
|
||||
'''
|
||||
Returns the fully qualified hostname
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' network.get_fqhostname
|
||||
'''
|
||||
l = []
|
||||
l.append(socket.getfqdn())
|
||||
|
@ -347,12 +323,6 @@ def get_fqhostname():
|
|||
def ip_to_host(ip):
|
||||
'''
|
||||
Returns the hostname of a given IP
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' network.ip_to_host 8.8.8.8
|
||||
'''
|
||||
try:
|
||||
hostname, aliaslist, ipaddrlist = socket.gethostbyaddr(ip)
|
||||
|
|
|
@ -107,7 +107,8 @@ class NetworkTestCase(TestCase):
|
|||
of the running TCP connections
|
||||
'''
|
||||
with patch.object(salt.utils.network, 'active_tcp', return_value='A'):
|
||||
self.assertEqual(network.active_tcp(), 'A')
|
||||
with patch.dict(network.__grains__, {'kernel': 'Linux'}):
|
||||
self.assertEqual(network.active_tcp(), 'A')
|
||||
|
||||
def test_traceroute(self):
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue