1 # vim: set encoding=utf-8 et sw=4 sts=4 :
3 from pymin.seqtools import Sequence
4 from pymin.service.util import ListSubHandler
6 __all__ = ('MasqHandler',)
10 r"""Masq(dev, src_net) -> Masq instance.
12 dev - Netword device to use.
13 src_net - Source network to apply the masquerade (as IP/mask).
16 def __init__(self, dev, src_net):
17 r"Initialize object, see class documentation for details."
20 self.src_net = src_net
22 def update(self, dev=None, src_net=None):
23 r"update([dev[, ...]]) -> Update the values of a masq (see class doc)."
25 if dev is not None: self.dev = dev
26 if src_net is not None: self.src_net = src_net
28 def __cmp__(self, other):
29 r"Compares two Masq objects."
30 return cmp(self.as_tuple(), other.as_tuple())
33 r"Return a tuple representing the masquerade."
34 return (self.dev, self.src_net)
36 def as_call_list(self, index=None):
37 cmd = ['-t', 'nat', '-I', 'POSTROUTING']
39 cmd.append(str(index))
40 cmd.extend(('-o', self.dev, '-j', 'MASQUERADE', '-s', self.src_net))
43 class MasqHandler(ListSubHandler):
44 r"""MasqHandler(parent) -> MasqHandler instance.
46 This class is a helper for NatHandler to do all the work related to
49 parent - The parent service handler.
52 handler_help = u"Manage NAT masquerading."
54 _cont_subhandler_attr = 'masqs'
55 _cont_subhandler_class = Masq