X-Git-Url: https://git.llucax.com/software/pymin.git/blobdiff_plain/83738d4fffe1910d9d75849657086d2e4e921a15..6f9f028c43f77c76a0ac6d4f4f7223e5c6e2ba64:/services/dhcp/__init__.py?ds=sidebyside diff --git a/services/dhcp/__init__.py b/services/dhcp/__init__.py index b728162..f490422 100644 --- a/services/dhcp/__init__.py +++ b/services/dhcp/__init__.py @@ -14,11 +14,15 @@ except ImportError: # NOP for testing class Sequence: pass try: - from dispatcher import handler, HandlerError + from dispatcher import Handler, handler, HandlerError except ImportError: # NOP for testing class HandlerError(RuntimeError): pass - def handler(f): return f + class Handler: pass + def handler(help): + def wrapper(f): + return f + return wrapper __ALL__ = ('DhcpHandler',) @@ -123,7 +127,7 @@ class Host(Sequence): r"Return a tuple representing the host." return (self.name, self.ip, self.mac) -class HostHandler: +class HostHandler(Handler): r"""HostHandler(hosts) -> HostHandler instance :: Handle a list of hosts. This class is a helper for DhcpHandler to do all the work related to hosts @@ -136,14 +140,14 @@ class HostHandler: r"Initialize HostHandler object, see class documentation for details." self.hosts = hosts - @handler + @handler(u'Add a new host.') def add(self, name, ip, mac): r"add(name, ip, mac) -> None :: Add a host to the hosts list." if name in self.hosts: raise HostAlreadyExistsError(name) self.hosts[name] = Host(name, ip, mac) - @handler + @handler(u'Update a host.') def update(self, name, ip=None, mac=None): r"update(name[, ip[, mac]]) -> None :: Update a host of the hosts list." if not name in self.hosts: @@ -153,14 +157,14 @@ class HostHandler: if mac is not None: self.hosts[name].mac = mac - @handler + @handler(u'Delete a host.') def delete(self, name): r"delete(name) -> None :: Delete a host of the hosts list." if not name in self.hosts: raise HostNotFoundError(name) del self.hosts[name] - @handler + @handler(u'Get information about a host.') def get(self, name): r"""get(name) -> CSV string :: List all the information of a host. @@ -170,7 +174,7 @@ class HostHandler: raise HostNotFoundError(name) return self.hosts[name] - @handler + @handler(u'List hosts.') def list(self): r"""list() -> CSV string :: List all the hostnames. @@ -178,7 +182,7 @@ class HostHandler: """ return self.hosts.keys() - @handler + @handler(u'Get information about all hosts.') def show(self): r"""show() -> CSV string :: List all the complete hosts information. @@ -187,7 +191,7 @@ class HostHandler: """ return self.hosts.values() -class DhcpHandler: +class DhcpHandler(Handler): r"""DhcpHandler([pickle_dir[, config_dir]]) -> DhcpHandler instance. Handles DHCP service commands for the dhcpd program. @@ -225,21 +229,21 @@ class DhcpHandler: self._write_config() self.host = HostHandler(self.hosts) - @handler + @handler(u'Set a DHCP parameter.') def set(self, param, value): r"set(param, value) -> None :: Set a DHCP parameter." if not param in self.vars: raise ParameterNotFoundError(param) self.vars[param] = value - @handler + @handler(u'Get a DHCP parameter.') def get(self, param): r"get(param) -> None :: Get a DHCP parameter." if not param in self.vars: raise ParameterNotFoundError(param) return self.vars[param] - @handler + @handler(u'List all available DHCP parameters.') def list(self): r"""list() -> CSV string :: List all the parameter names. @@ -247,7 +251,7 @@ class DhcpHandler: """ return self.vars.keys() - @handler + @handler(u'Get all DHCP parameters, with their values.') def show(self): r"""show() -> CSV string :: List all the parameters (with their values). @@ -257,35 +261,35 @@ class DhcpHandler: """ return self.vars.items() - @handler + @handler(u'Start the service.') def start(self): r"start() -> None :: Start the DHCP service." #esto seria para poner en una interfaz #y seria el hook para arrancar el servicio pass - @handler + @handler(u'Stop the service.') def stop(self): r"stop() -> None :: Stop the DHCP service." #esto seria para poner en una interfaz #y seria el hook para arrancar el servicio pass - @handler + @handler(u'Restart the service.') def restart(self): r"restart() -> None :: Restart the DHCP service." #esto seria para poner en una interfaz #y seria el hook para arrancar el servicio pass - @handler + @handler(u'Reload the service config (without restarting, if possible).') def reload(self): r"reload() -> None :: Reload the configuration of the DHCP service." #esto seria para poner en una interfaz #y seria el hook para arrancar el servicio pass - @handler + @handler(u'Commit the changes (reloading the service, if necessary).') def commit(self): r"commit() -> None :: Commit the changes and reload the DHCP service." #esto seria para poner en una interfaz @@ -295,7 +299,7 @@ class DhcpHandler: self._write_config() self.reload() - @handler + @handler(u'Discard all the uncommited changes.') def rollback(self): r"rollback() -> None :: Discard the changes not yet commited." self._load()