def get_ip(self, log, options): """Implement AddressPlugin.get_ip().""" opts = dict_of_opts(options) if 'if' not in opts: raise AddressError('Required option if= missing, giving up.') if_ = opts['if'] address = IpAddr() output = subprocess.getoutput('ip address show dev ' + if_) address.parse_ifconfig_output(output) return address
def get_ip(self, log, options): """ Get default interface using ip route and address using ifconfig. """ if_ = None for line in subprocess.getoutput('ip route').split('\n'): words = line.split() if words[0] == 'default': if_ = self.find_device(words) break if if_ is None: raise AddressError("Cannot find default interface, giving up") address = IpAddr() output = subprocess.getoutput('ip address show dev ' + if_) address.parse_ifconfig_output(output) return address