"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "salt/modules/network.py" between
salt-2019.2.0.tar.gz and salt-2019.2.1.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

network.py  (salt-2019.2.0):network.py  (salt-2019.2.1)
skipping to change at line 805 skipping to change at line 805
ret[len(ret)+1] = { ret[len(ret)+1] = {
'local_addr': '.'.join(connection['local-address'].split('.')[:- 1]), 'local_addr': '.'.join(connection['local-address'].split('.')[:- 1]),
'local_port': '.'.join(connection['local-address'].split('.')[-1 :]), 'local_port': '.'.join(connection['local-address'].split('.')[-1 :]),
'remote_addr': '.'.join(connection['remote-address'].split('.')[ :-1]), 'remote_addr': '.'.join(connection['remote-address'].split('.')[ :-1]),
'remote_port': '.'.join(connection['remote-address'].split('.')[ -1:]) 'remote_port': '.'.join(connection['remote-address'].split('.')[ -1:])
} }
return ret return ret
else: else:
return {} return {}
@salt.utils.decorators.path.which('traceroute')
def traceroute(host): def traceroute(host):
''' '''
Performs a traceroute to a 3rd party host Performs a traceroute to a 3rd party host
.. versionchanged:: 2015.8.0 .. versionchanged:: 2015.8.0
Added support for SunOS Added support for SunOS
.. versionchanged:: 2016.11.4 .. versionchanged:: 2016.11.4
Added support for AIX Added support for AIX
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
salt '*' network.traceroute archlinux.org salt '*' network.traceroute archlinux.org
''' '''
ret = [] ret = []
if not salt.utils.path.which('traceroute'):
log.info('This minion does not have traceroute installed')
return ret
cmd = 'traceroute {0}'.format(salt.utils.network.sanitize_host(host)) cmd = 'traceroute {0}'.format(salt.utils.network.sanitize_host(host))
out = __salt__['cmd.run'](cmd) out = __salt__['cmd.run'](cmd)
# Parse version of traceroute # Parse version of traceroute
if salt.utils.platform.is_sunos() or salt.utils.platform.is_aix(): if salt.utils.platform.is_sunos() or salt.utils.platform.is_aix():
traceroute_version = [0, 0, 0] traceroute_version = [0, 0, 0]
else: else:
cmd2 = 'traceroute --version' version_out = __salt__['cmd.run']('traceroute --version')
out2 = __salt__['cmd.run'](cmd2)
try: try:
# Linux traceroute version looks like: # Linux traceroute version looks like:
# Modern traceroute for Linux, version 2.0.19, Dec 10 2012 # Modern traceroute for Linux, version 2.0.19, Dec 10 2012
# Darwin and FreeBSD traceroute version looks like: Version 1.4a12+[ FreeBSD|Darwin] # Darwin and FreeBSD traceroute version looks like: Version 1.4a12+[ FreeBSD|Darwin]
traceroute_version_raw = re.findall(r'.*[Vv]ersion (\d+)\.([\w\+]+)\ version_raw = re.findall(r'.*[Vv]ersion (\d+)\.([\w\+]+)\.*(\w*)', v
.*(\w*)', out2)[0] ersion_out)[0]
log.debug('traceroute_version_raw: %s', traceroute_version_raw) log.debug('traceroute_version_raw: %s', version_raw)
traceroute_version = [] traceroute_version = []
for t in traceroute_version_raw: for t in version_raw:
try: try:
traceroute_version.append(int(t)) traceroute_version.append(int(t))
except ValueError: except ValueError:
traceroute_version.append(t) traceroute_version.append(t)
if len(traceroute_version) < 3: if len(traceroute_version) < 3:
traceroute_version.append(0) traceroute_version.append(0)
log.debug('traceroute_version: %s', traceroute_version) log.debug('traceroute_version: %s', traceroute_version)
except IndexError: except IndexError:
traceroute_version = [0, 0, 0] traceroute_version = [0, 0, 0]
for line in out.splitlines(): for line in out.splitlines():
# Pre requirements for line parsing
skip_line = False
if ' ' not in line: if ' ' not in line:
continue skip_line = True
if line.startswith('traceroute'): if line.startswith('traceroute'):
continue skip_line = True
if salt.utils.platform.is_aix(): if salt.utils.platform.is_aix():
if line.startswith('trying to get source for'): if line.startswith('trying to get source for'):
continue skip_line = True
if line.startswith('source should be'): if line.startswith('source should be'):
continue skip_line = True
if line.startswith('outgoing MTU'): if line.startswith('outgoing MTU'):
continue skip_line = True
if line.startswith('fragmentation required'): if line.startswith('fragmentation required'):
continue skip_line = True
if skip_line:
log.debug('Skipping traceroute output line: %s', line)
continue
# Parse output from unix variants
if 'Darwin' in six.text_type(traceroute_version[1]) or \ if 'Darwin' in six.text_type(traceroute_version[1]) or \
'FreeBSD' in six.text_type(traceroute_version[1]) or \ 'FreeBSD' in six.text_type(traceroute_version[1]) or \
__grains__['kernel'] in ('SunOS', 'AIX'): __grains__['kernel'] in ('SunOS', 'AIX'):
try: try:
traceline = re.findall(r'\s*(\d*)\s+(.*)\s+\((.*)\)\s+(.*)$', li ne)[0] traceline = re.findall(r'\s*(\d*)\s+(.*)\s+\((.*)\)\s+(.*)$', li ne)[0]
except IndexError: except IndexError:
traceline = re.findall(r'\s*(\d*)\s+(\*\s+\*\s+\*)', line)[0] traceline = re.findall(r'\s*(\d*)\s+(\*\s+\*\s+\*)', line)[0]
log.debug('traceline: %s', traceline) log.debug('traceline: %s', traceline)
delays = re.findall(r'(\d+\.\d+)\s*ms', six.text_type(traceline)) delays = re.findall(r'(\d+\.\d+)\s*ms', six.text_type(traceline))
try: try:
skipping to change at line 905 skipping to change at line 902
result = { result = {
'count': traceline[0], 'count': traceline[0],
'hostname': traceline[1], 'hostname': traceline[1],
'ip': traceline[2], 'ip': traceline[2],
} }
for idx in range(0, len(delays)): for idx in range(0, len(delays)):
result['ms{0}'.format(idx + 1)] = delays[idx] result['ms{0}'.format(idx + 1)] = delays[idx]
except IndexError: except IndexError:
result = {} result = {}
# Parse output from specific version ranges
elif (traceroute_version[0] >= 2 and traceroute_version[2] >= 14 elif (traceroute_version[0] >= 2 and traceroute_version[2] >= 14
or traceroute_version[0] >= 2 and traceroute_version[1] > 0): or traceroute_version[0] >= 2 and traceroute_version[1] > 0):
comps = line.split(' ') comps = line.split(' ')
if comps[1] == '* * *': if len(comps) >= 2 and comps[1] == '* * *':
result = { result = {
'count': int(comps[0]), 'count': int(comps[0]),
'hostname': '*'} 'hostname': '*'}
else: elif len(comps) >= 5:
result = { result = {
'count': int(comps[0]), 'count': int(comps[0]),
'hostname': comps[1].split()[0], 'hostname': comps[1].split()[0],
'ip': comps[1].split()[1].strip('()'), 'ip': comps[1].split()[1].strip('()'),
'ms1': float(comps[2].split()[0]), 'ms1': float(comps[2].split()[0]),
'ms2': float(comps[3].split()[0]), 'ms2': float(comps[3].split()[0]),
'ms3': float(comps[4].split()[0])} 'ms3': float(comps[4].split()[0])}
else:
result = {}
# Parse anything else
else: else:
comps = line.split() comps = line.split()
result = { if len(comps) >= 8:
'count': comps[0], result = {
'hostname': comps[1], 'count': comps[0],
'ip': comps[2], 'hostname': comps[1],
'ms1': comps[4], 'ip': comps[2],
'ms2': comps[6], 'ms1': comps[4],
'ms3': comps[8], 'ms2': comps[6],
'ping1': comps[3], 'ms3': comps[8],
'ping2': comps[5], 'ping1': comps[3],
'ping3': comps[7]} 'ping2': comps[5],
'ping3': comps[7]}
else:
result = {}
ret.append(result) ret.append(result)
if not result:
log.warn('Cannot parse traceroute output line: %s', line)
return ret return ret
@salt.utils.decorators.path.which('dig') @salt.utils.decorators.path.which('dig')
def dig(host): def dig(host):
''' '''
Performs a DNS lookup with dig Performs a DNS lookup with dig
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
 End of changes. 21 change blocks. 
35 lines changed or deleted 41 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)