+from seqtools import Sequence
+from dispatcher import Handler, handler, HandlerError
+from services.util import Restorable, ConfigWriter
+from services.util import InitdHandler, TransactionalHandler
+
+__ALL__ = ('DhcpHandler', 'Error', 'HostError', 'HostAlreadyExistsError',
+ 'HostNotFoundError', 'ParameterError', 'ParameterNotFoundError')
+
+class Error(HandlerError):
+ r"""
+ Error(message) -> Error instance :: Base DhcpHandler exception class.
+
+ All exceptions raised by the DhcpHandler inherits from this one, so you can
+ easily catch any DhcpHandler exception.
+
+ message - A descriptive error message.
+ """
+
+ def __init__(self, message):
+ r"Initialize the Error object. See class documentation for more info."
+ self.message = message
+
+ def __str__(self):
+ return self.message
+
+class HostError(Error, KeyError):
+ r"""
+ HostError(hostname) -> HostError instance
+
+ This is the base exception for all host related errors.
+ """
+
+ def __init__(self, hostname):
+ r"Initialize the object. See class documentation for more info."
+ self.message = 'Host error: "%s"' % hostname
+
+class HostAlreadyExistsError(HostError):
+ r"""
+ HostAlreadyExistsError(hostname) -> HostAlreadyExistsError instance
+
+ This exception is raised when trying to add a hostname that already exists.
+ """
+
+ def __init__(self, hostname):
+ r"Initialize the object. See class documentation for more info."
+ self.message = 'Host already exists: "%s"' % hostname
+
+class HostNotFoundError(HostError):
+ r"""
+ HostNotFoundError(hostname) -> HostNotFoundError instance
+
+ This exception is raised when trying to operate on a hostname that doesn't
+ exists.
+ """
+
+ def __init__(self, hostname):
+ r"Initialize the object. See class documentation for more info."
+ self.message = 'Host not found: "%s"' % hostname
+
+class ParameterError(Error, KeyError):
+ r"""
+ ParameterError(paramname) -> ParameterError instance
+
+ This is the base exception for all DhcpHandler parameters related errors.
+ """
+
+ def __init__(self, paramname):
+ r"Initialize the object. See class documentation for more info."
+ self.message = 'Parameter error: "%s"' % paramname
+
+class ParameterNotFoundError(ParameterError):
+ r"""
+ ParameterNotFoundError(hostname) -> ParameterNotFoundError instance
+
+ This exception is raised when trying to operate on a parameter that doesn't
+ exists.
+ """
+
+ def __init__(self, paramname):
+ r"Initialize the object. See class documentation for more info."
+ self.message = 'Parameter not found: "%s"' % paramname
+
+
+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.
+ ip - IP assigned to the hostname.
+ mac - MAC address to associate to the hostname.
+ """