-
- def __init__(self, parent):
- self.parent = parent
-
- @handler(u'Adds an address to a device')
- def add(self, device, ip, prefix, broadcast='+'):
- if not device in self.parent.devices:
- raise DeviceNotFoundError(device)
- if ip in self.parent.devices[device].addrs:
- raise AddressAlreadyExistsError(ip)
- self.parent.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.parent.devices:
- raise DeviceNotFoundError(device)
- if not ip in self.parent.devices[device].addrs:
- raise AddressNotFoundError(ip)
- del self.parent.devices[device].addrs[ip]
-
- @handler(u'Flushes addresses from a device')
- def flush(self, device):
- if not device in self.parent.devices:
- raise DeviceNotFoundError(device)
- self.parent.devices[device].addrs = dict()
-
- @handler(u'List all addresses from a device')
- def list(self, device):
- try:
- k = self.parent.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.parent.devices[device].addrs.values()
- except ValueError:
- k = list()
- return k
-