]> git.llucax.com Git - software/pymin.git/blob - services/ip/hop.py
Import HandlerError in vpn service handler (closes #32)
[software/pymin.git] / services / ip / hop.py
1 # vim: set encoding=utf-8 et sw=4 sts=4 :
2
3 from pymin.seqtools import Sequence
4 from pymin.dispatcher import handler
5 from pymin.service.util import ContainerNotFoundError, ListSubHandler
6
7 __all__ = ('HopHandler',)
8
9
10 class Hop(Sequence):
11
12     def __init__(self, gateway, device):
13         self.gateway = gateway
14         self.device = device
15
16     def as_tuple(self):
17         return (self.gateway, self.device)
18
19     def __cmp__(self, other):
20         if self.gateway == other.gateway \
21                 and self.device == other.device:
22             return 0
23         return cmp(id(self), id(other))
24
25 class HopHandler(ListSubHandler):
26     handler_help = u"Manage IP hops"
27     _cont_subhandler_attr = 'hops'
28     _cont_subhandler_class = Hop
29
30     @handler('Add a hop: add <device> <gateway>')
31     def add(self, dev, gw):
32         if not dev in self.parent.devices:
33             raise ContainerNotFoundError(device)
34         return ListSubHandler.add(self, dev, gw)
35