1 # vim: set encoding=utf-8 et sw=4 sts=4 :
3 from pymin.seqtools import Sequence
4 from pymin.dispatcher import handler
5 from pymin.service.util import SubHandler, ContainerNotFoundError, \
8 __all__ = ('HostHandler',)
13 def __init__(self, ip):
19 def __cmp__(self, other):
20 if self.ip == other.ip:
22 return cmp(id(self), id(other))
25 class HostHandler(SubHandler):
27 def __init__(self, parent):
30 @handler('Adds a host to a class : add <device> <class id> <ip>')
31 def add(self, dev, cid, ip):
32 if not dev in self.parent.devices:
33 raise ContainerNotFoundError(dev)
35 if not cid in self.parent.devices[dev].classes:
36 raise ContainerNotFoundError(cid)
39 self.parent.devices[dev].classes[cid].hosts[ip] = Host(ip)
41 raise ItemAlreadyExistsError(h + ' -> ' + dev)
43 @handler(u'Lists hosts : list <dev> <class id>')
44 def list(self, dev, cid):
46 k = self.parent.devices[dev].classes[cid].hosts.keys()