import cPickle as pickle
except ImportError:
import pickle
+
+try:
+ from seqtools import Sequence
+except ImportError:
+ # NOP for testing
+ class Sequence: pass
try:
- from dispatcher import handler
+ from dispatcher import handler, HandlerError
except ImportError:
- def handler(f): return f # NOP for testing
+ # NOP for testing
+ class HandlerError(RuntimeError): pass
+ def handler(f): return f
__ALL__ = ('DhcpHandler',)
template_dir = path.join(path.dirname(__file__), 'templates')
-class Error(RuntimeError):
+class Error(HandlerError):
r"""
Error(command) -> Error instance :: Base DhcpHandler exception class.
self.message = 'Parameter not found: "%s"' % paramname
-class Host:
+class Host(Sequence):
r"""Host(name, ip, mac) -> Host instance :: Class representing a host.
name - Host name, should be a fully qualified name, but no checks are done.
self.ip = ip
self.mac = mac
+ def as_tuple(self):
+ r"Return a tuple representing the host."
+ return (self.name, self.ip, self.mac)
+
class HostHandler:
r"""HostHandler(hosts) -> HostHandler instance :: Handle a list of hosts.
"""
if not name in self.hosts:
raise HostNotFoundError(name)
- h = self.hosts[name]
- return '%s,%s,%s' % (h.name, h.ip, h.mac)
+ return self.hosts[name]
@handler
def list(self):
The list is returned as a single CSV line with all the hostnames.
"""
- return ','.join(self.hosts)
+ return self.hosts.keys()
@handler
def show(self):
The hosts are returned as a CSV list with each host in a line, like:
hostname,ip,mac
"""
- hosts = self.hosts.values()
- return '\n'.join('%s,%s,%s' % (h.name, h.ip, h.mac) for h in hosts)
+ return self.hosts.values()
class DhcpHandler:
r"""DhcpHandler([pickle_dir[, config_dir]]) -> DhcpHandler instance.
The list is returned as a single CSV line with all the names.
"""
- return ','.join(self.vars)
+ return self.vars.keys()
@handler
def show(self):
line, like:
name,value
"""
- return '\n'.join(('%s,%s' % (k, v) for (k, v) in self.vars.items()))
+ return self.vars.items()
@handler
def start(self):