mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Update doc string and minor cleanup
This commit is contained in:
parent
7950dd01e5
commit
f0a8e13628
1 changed files with 13 additions and 12 deletions
|
@ -426,6 +426,8 @@ class LinuxNetwork(Network):
|
||||||
This is a Linux-specific subclass of Network. It defines
|
This is a Linux-specific subclass of Network. It defines
|
||||||
- interfaces (a list of interface names)
|
- interfaces (a list of interface names)
|
||||||
- interface_<name> dictionary of ipv4, ipv6, and mac address information.
|
- interface_<name> dictionary of ipv4, ipv6, and mac address information.
|
||||||
|
- all_ipv4_addresses and all_ipv6_addresses: lists of all configured addresses.
|
||||||
|
- ipv4_address and ipv6_address: the first non-local address for each family.
|
||||||
"""
|
"""
|
||||||
platform = 'Linux'
|
platform = 'Linux'
|
||||||
|
|
||||||
|
@ -438,17 +440,16 @@ class LinuxNetwork(Network):
|
||||||
self.facts['interfaces'] = interfaces.keys()
|
self.facts['interfaces'] = interfaces.keys()
|
||||||
for iface in interfaces:
|
for iface in interfaces:
|
||||||
self.facts[iface] = interfaces[iface]
|
self.facts[iface] = interfaces[iface]
|
||||||
self.facts['all_ipv4_addresses'] = ips['all_ipv4']
|
|
||||||
self.facts['all_ipv6_addresses'] = ips['all_ipv6']
|
for key in ips:
|
||||||
self.facts['ipv4_address'] = ips['ipv4']
|
self.facts[key] = ips[key]
|
||||||
self.facts['ipv6_address'] = ips['ipv6']
|
|
||||||
|
|
||||||
return self.facts
|
return self.facts
|
||||||
|
|
||||||
|
|
||||||
def parse_ip_addr(self):
|
def parse_ip_addr(self):
|
||||||
interfaces = {}
|
interfaces = {}
|
||||||
ips = {'all_ipv4': [], 'all_ipv6': [], 'ipv4': None, 'ipv6': None}
|
ips = {'all_ipv4_addresses': [], 'all_ipv6_addresses': [],
|
||||||
|
'ipv4_address': None, 'ipv6_address': None}
|
||||||
|
|
||||||
output = subprocess.Popen(['ip','addr'], stdout=subprocess.PIPE).communicate()[0]
|
output = subprocess.Popen(['ip','addr'], stdout=subprocess.PIPE).communicate()[0]
|
||||||
for line in output.split('\n'):
|
for line in output.split('\n'):
|
||||||
|
@ -489,9 +490,9 @@ class LinuxNetwork(Network):
|
||||||
'netmask': netmask,
|
'netmask': netmask,
|
||||||
'network': network}
|
'network': network}
|
||||||
|
|
||||||
ips['all_ipv4'].append(address)
|
ips['all_ipv4_addresses'].append(address)
|
||||||
if not ips['ipv4'] or ips['ipv4'].startswith('127'):
|
if not ips['ipv4_address'] or ips['ipv4_address'].startswith('127'):
|
||||||
ips['ipv4'] = address
|
ips['ipv4_address'] = address
|
||||||
|
|
||||||
elif words[0] == 'inet6':
|
elif words[0] == 'inet6':
|
||||||
address, prefix = words[1].split('/')
|
address, prefix = words[1].split('/')
|
||||||
|
@ -510,9 +511,9 @@ class LinuxNetwork(Network):
|
||||||
'prefix': prefix,
|
'prefix': prefix,
|
||||||
'scope': scope} )
|
'scope': scope} )
|
||||||
|
|
||||||
ips['all_ipv6'].append(address)
|
ips['all_ipv6_addresses'].append(address)
|
||||||
if not ips['ipv6'] or ips['ipv6'] == '::1':
|
if not ips['ipv6_address'] or ips['ipv6_address'] == '::1':
|
||||||
ips['ipv6'] = address
|
ips['ipv6_address'] = address
|
||||||
|
|
||||||
return interfaces, ips
|
return interfaces, ips
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue