Пример #1
0
    def default_interface(self):
        """
        Returns the default interface device.
        
        """
        out, err, ret = exec_cmd(['/sbin/route', '-n'])
        lines = out.splitlines()
        for line in lines[2:]:
            if line.split()[0] == '0.0.0.0':
                iface = line.split()[-1]

        for interface in self.interfaces:
            if interface == iface:
                return self.interfaces[interface]
        return None # pragma: nocover
Пример #2
0
 def parse(self, ifconfig=None):
     """
     Parse ifconfig output into self._interfaces.
     
     Optional Arguments:
     
         ifconfig
             The data (stdout) from the ifconfig command.  Default is to
             call self._meta.ifconfig_cmd_args for the stdout.
             
     """
     _interfaces = []
     if not ifconfig:
         ifconfig, err, retcode = exec_cmd(self._meta.ifconfig_cmd_args)
     self.ifconfig_data = ifconfig
     cur = None
     all_keys = []
     
     for line in self.ifconfig_data.splitlines():
         for pattern in self._get_patterns():
             m = re.match(pattern, line)
             if m:
                 groupdict = m.groupdict()
                 # Special treatment to trigger which interface we're 
                 # setting for if 'device' is in the line.  Presumably the
                 # device of the interface is within the first line of the
                 # device block.
                 if 'device' in groupdict:
                     cur = groupdict['device']
                     if not self._interfaces.has_key(cur):
                         self._interfaces[cur] = {}
                 
                 for key in groupdict:
                     if key not in all_keys:
                         all_keys.append(key)
                     self._interfaces[cur][key] = groupdict[key]
     
     # fix it up        
     self._interfaces = self.alter(self._interfaces)    
     
     # standardize
     for key in all_keys:
         for device,device_dict in self._interfaces.items():
             if key not in device_dict:
                 self._interfaces[device][key] = None
             if type(device_dict[key]) == str:
                 self._interfaces[device][key] = device_dict[key].lower()