Add some whitespace
This commit is contained in:
parent
e9e4bb0b81
commit
c7ab476b94
1 changed files with 33 additions and 9 deletions
42
setup
42
setup
|
@ -1039,7 +1039,9 @@ class LinuxNetwork(Network):
|
|||
interfaces[device]['all_slaves_active'] = open(os.path.join(path, 'bonding', 'all_slaves_active')).read() == '1'
|
||||
output = subprocess.Popen(['/sbin/ip', 'addr', 'show', device], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
|
||||
for line in output.split('\n'):
|
||||
if not line: continue
|
||||
|
||||
if not line:
|
||||
continue
|
||||
words = line.split()
|
||||
if words[0] == 'inet':
|
||||
if '/' in words[1]:
|
||||
|
@ -1071,23 +1073,29 @@ class LinuxNetwork(Network):
|
|||
|
||||
if not address.startswith('127.'):
|
||||
ips['all_ipv4_addresses'].append(address)
|
||||
|
||||
elif words[0] == 'inet6':
|
||||
|
||||
address, prefix = words[1].split('/')
|
||||
scope = words[3]
|
||||
|
||||
if 'ipv6' not in interfaces[device]:
|
||||
interfaces[device]['ipv6'] = []
|
||||
interfaces[device]['ipv6'].append( {
|
||||
'address': address,
|
||||
'prefix': prefix,
|
||||
'scope': scope} )
|
||||
|
||||
interfaces[device]['ipv6'].append({
|
||||
'address' : address,
|
||||
'prefix' : prefix,
|
||||
'scope' : scope
|
||||
})
|
||||
|
||||
# If this is the default address, update default_ipv6
|
||||
|
||||
if 'address' in default_ipv6 and default_ipv6['address'] == address:
|
||||
default_ipv6['prefix'] = prefix
|
||||
default_ipv6['scope'] = scope
|
||||
default_ipv6['prefix'] = prefix
|
||||
default_ipv6['scope'] = scope
|
||||
default_ipv6['macaddress'] = macaddress
|
||||
default_ipv6['mtu'] = interfaces[device]['mtu']
|
||||
default_ipv6['type'] = interfaces[device]['type']
|
||||
default_ipv6['mtu'] = interfaces[device]['mtu']
|
||||
default_ipv6['type'] = interfaces[device]['type']
|
||||
|
||||
if not address == '::1':
|
||||
ips['all_ipv6_addresses'].append(address)
|
||||
|
@ -1111,36 +1119,48 @@ class GenericBsdIfconfigNetwork(Network):
|
|||
Network.__init__(self)
|
||||
|
||||
def populate(self):
|
||||
|
||||
ifconfig_path = module.get_bin_path('ifconfig')
|
||||
|
||||
if ifconfig_path is None:
|
||||
return self.facts
|
||||
route_path = module.get_bin_path('route')
|
||||
|
||||
if route_path is None:
|
||||
return self.facts
|
||||
|
||||
default_ipv4, default_ipv6 = self.get_default_interfaces(route_path)
|
||||
interfaces, ips = self.get_interfaces_info(ifconfig_path)
|
||||
self.merge_default_interface(default_ipv4, interfaces, 'ipv4')
|
||||
self.merge_default_interface(default_ipv6, interfaces, 'ipv6')
|
||||
self.facts['interfaces'] = interfaces.keys()
|
||||
|
||||
for iface in interfaces:
|
||||
self.facts[iface] = interfaces[iface]
|
||||
|
||||
self.facts['default_ipv4'] = default_ipv4
|
||||
self.facts['default_ipv6'] = default_ipv6
|
||||
self.facts['all_ipv4_addresses'] = ips['all_ipv4_addresses']
|
||||
self.facts['all_ipv6_addresses'] = ips['all_ipv6_addresses']
|
||||
|
||||
return self.facts
|
||||
|
||||
def get_default_interfaces(self, route_path):
|
||||
|
||||
# Use the commands:
|
||||
# route -n get 8.8.8.8 -> Google public DNS
|
||||
# route -n get 2404:6800:400a:800::1012 -> ipv6.google.com
|
||||
# to find out the default outgoing interface, address, and gateway
|
||||
|
||||
command = dict(
|
||||
v4 = [route_path, '-n', 'get', '8.8.8.8'],
|
||||
v6 = [route_path, '-n', 'get', '2404:6800:400a:800::1012']
|
||||
)
|
||||
|
||||
interface = dict(v4 = {}, v6 = {})
|
||||
|
||||
for v in 'v4', 'v6':
|
||||
|
||||
if v == 'v6' and not socket.has_ipv6:
|
||||
continue
|
||||
rc, out, err = module.run_command(command[v])
|
||||
|
@ -1154,6 +1174,7 @@ class GenericBsdIfconfigNetwork(Network):
|
|||
# look for first word starting interface
|
||||
if len(words) > 0 and words[0] == 'interface:':
|
||||
interface[v]['interface'] = words[1]
|
||||
|
||||
return interface['v4'], interface['v6']
|
||||
|
||||
def get_interfaces_info(self, ifconfig_path):
|
||||
|
@ -1164,9 +1185,12 @@ class GenericBsdIfconfigNetwork(Network):
|
|||
all_ipv6_addresses = [],
|
||||
)
|
||||
rc, out, err = module.run_command([ifconfig_path])
|
||||
|
||||
for line in out.split('\n'):
|
||||
|
||||
if line:
|
||||
words = line.split()
|
||||
|
||||
if re.match('^\S', line) and len(words) > 3:
|
||||
current_if = self.parse_interface_line(words)
|
||||
interfaces[ current_if['device'] ] = current_if
|
||||
|
|
Loading…
Reference in a new issue