1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
"""
ddupdate plugin providing an ip address from an interface option.
See: ddupdate(8)
"""
import subprocess
from ddupdate.ddplugin import AddressPlugin, AddressError, IpAddr, dict_of_opts
class HardcodedIfPlugin(AddressPlugin):
"""
Use address on hardcoded interface.
Options:
if=interface
"""
_name = 'hardcoded-if'
_oneliner = 'Get address from an configuration option interface'
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
|