Add some whitespace

This commit is contained in:
Michael DeHaan 2013-04-22 23:46:58 -04:00
parent e9e4bb0b81
commit c7ab476b94

28
setup
View file

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