- return (self.ip, self.prefix, self.broadcast)
-
-class AddressHandler(Handler):
-
- handler_help = u"Manage IP addresses"
-
- def __init__(self, devices):
- self.devices = devices
-
- @handler(u'Adds an address to a device')
- def add(self, device, ip, prefix, broadcast='+'):
- if not device in self.devices:
- raise DeviceNotFoundError(device)
- if ip in self.devices[device].addrs:
- raise AddressAlreadyExistsError(ip)
- self.devices[device].addrs[ip] = Address(ip, prefix, broadcast)
-
- @handler(u'Deletes an address from a device')
- def delete(self, device, ip):
- if not device in self.devices:
- raise DeviceNotFoundError(device)
- if not ip in self.devices[device].addrs:
- raise AddressNotFoundError(ip)
- del self.devices[device].addrs[ip]
-
- @handler(u'Flushes addresses from a device')
- def flush(self, device):
- if not device in self.devices:
- raise DeviceNotFoundError(device)
- self.devices[device].addrs = dict()
-
- @handler(u'List all addresses from a device')
- def list(self, device):
- try:
- k = self.devices[device].addrs.keys()
- except ValueError:
- k = list()
- return k
-
- @handler(u'Get information about addresses from a device')
- def show(self, device):
- try:
- k = self.devices[device].addrs.values()
- except ValueError:
- k = list()
- return k