-class HostHandler(DictComposedSubHandler):
- handler_help = u"Manage Hosts"
- _comp_subhandler_cont = 'classes'
- _comp_subhandler_attr = 'hosts'
- _comp_subhandler_class = Host
+ def __init__(self, parent):
+ self.parent = parent
+
+ @handler('Adds a host to a class : add <device> <class id> <ip>')
+ def add(self, dev, cid, ip):
+ if not dev in self.parent.devices:
+ raise DeviceNotFoundError(dev)
+
+ if not cid in self.parent.devices[dev].classes:
+ raise ClassNotFoundError(cid)
+
+ try:
+ self.parent.devices[dev].classes[cid].hosts[ip] = Host(ip)
+ except ValueError:
+ raise HostAlreadyExistsError(h + ' -> ' + dev)
+
+ @handler(u'Lists hosts : list <dev> <class id>')
+ def list(self, dev, cid):
+ try:
+ k = self.parent.devices[dev].classes[cid].hosts.keys()
+ except KeyError:
+ k = dict()
+ return k