File: addr_hardcoded_ip.py

package info (click to toggle)
ddupdate 0.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 420 kB
  • sloc: python: 1,899; sh: 38; makefile: 35
file content (33 lines) | stat: -rw-r--r-- 874 bytes parent folder | download
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
33
"""
ddupdate plugin providing an ip address to use a from an interface option.

See: ddupdate(8)
"""

from ddupdate.ddplugin import AddressPlugin, AddressError, IpAddr, dict_of_opts


class HardcodedIfPlugin(AddressPlugin):
    """
    Use address given in configuration options.

    Options:
        ip = ipv4 address
        ip6 = ipv6 address
    """

    _name = 'hardcoded-ip'
    _oneliner = 'Get address from configuration options'

    def get_ip(self, log, options):
        """Implement AddressPlugin.get_ip()."""
        addr = IpAddr()
        opts = dict_of_opts(options)
        if 'ip' not in opts and 'ip6' not in opts:
            raise AddressError(
                'Required option ip= or ip6= missing, giving up.')
        if 'ip' in opts:
            addr.v4 = opts['ip']
        if 'ip6' in opts:
            addr.v6 = opts['ip6']
        return addr