- def __init__(self, parent):
- self.parent = parent
-
- @handler(u'Adds a route to a device')
- def add(self, device, net_addr, prefix, gateway):
- if not device in self.parent.devices:
- raise DeviceNotFoundError(device)
- r = Route(net_addr, prefix, gateway)
- try:
- self.parent.devices[device].routes.index(r)
- raise RouteAlreadyExistsError(net_addr + '/' + prefix + '->' + gateway)
- except ValueError:
- self.parent.devices[device].routes.append(r)
-
- @handler(u'Deletes a route from a device')
- def delete(self, device, net_addr, prefix, gateway):
- if not device in self.parent.devices:
- raise DeviceNotFoundError(device)
- r = Route(net_addr, prefix, gateway)
- try:
- self.parent.devices[device].routes.remove(r)
- except ValueError:
- raise RouteNotFoundError(net_addr + '/' + prefix + '->' + gateway)
-
- @handler(u'Flushes routes from a device')
- def flush(self, device):
- if not device in self.parent.devices:
- raise DeviceNotFoundError(device)
- self.parent.devices[device].routes = list()
-
-
- @handler(u'List routes')
- def list(self, device):
- try:
- k = self.parent.devices[device].routes.keys()
- except ValueError:
- k = list()
- return k
-
- @handler(u'Get information about all routes')
- def show(self, device):
- try:
- k = self.parent.devices[device].routes.values()
- except ValueError:
- k = list()
- return k
-
-
-class Address(Sequence):
-
- def __init__(self, ip, prefix, broadcast):
- self.ip = ip
- self.prefix = prefix
- self.broadcast = broadcast
-
- def as_tuple(self):
- return (self.ip, self.prefix, self.broadcast)
-
-class AddressHandler(Handler):