- try:
- self._load()
- except IOError:
- # This is the first time the handler is used, create a basic
- # setup using some nice defaults
- self.devices = dict(
- eth0=Device('eth0'),
- eth1=Device('eth1'),
- )
- self._dump()
- self.addr = AddressHandler(self.devices, config_dir, self)
- self.route = RouteHandler(self.devices, config_dir, self)
- self.dev = DeviceHandler(self.devices, config_dir)
- self._write_config()
-
- def commit(self):
- r"commit() -> None :: Commit the changes and reload the DHCP service."
- #esto seria para poner en una interfaz
- #y seria que hace el pickle deberia llamarse
- #al hacerse un commit
- self._dump()
- self._write_config()
-
- @handler
- def rollback(self):
- r"rollback() -> None :: Discard the changes not yet commited."
- self._load()
-
- def _dump(self):
- r"_dump() -> None :: Dump all persistent data to pickle files."
- # XXX podría ir en una clase base
- self._dump_var(self.devices, pickle_devices)
-
-
- def _load(self):
- r"_load() -> None :: Load all persistent data from pickle files."
- # XXX podría ir en una clase base
- self.devices = self._load_var(pickle_devices)
-
- def _pickle_filename(self, name):
- r"_pickle_filename() -> string :: Construct a pickle filename."
- # XXX podría ir en una clase base
- return path.join(self.pickle_dir, name) + pickle_ext
-
- def _dump_var(self, var, name):
- r"_dump_var() -> None :: Dump a especific variable to a pickle file."
- # XXX podría ir en una clase base
- pkl_file = file(self._pickle_filename(name), 'wb')
- pickle.dump(var, pkl_file, 2)
- pkl_file.close()
-
- def _load_var(self, name):
- r"_load_var() -> object :: Load a especific pickle file."
- # XXX podría ir en una clase base
- return pickle.load(file(self._pickle_filename(name)))
+ _config_writer_files = ('device', 'ip_add', 'ip_del', 'ip_flush',
+ 'route_add', 'route_del', 'route_flush')
+ _config_writer_tpl_dir = path.join(path.dirname(__file__), 'templates')
+
+ def __init__(self, pickle_dir='.', config_dir='.'):
+ r"Initialize DhcpHandler object, see class documentation for details."
+ self._persistent_dir = pickle_dir
+ self._config_writer_cfg_dir = config_dir
+ self._config_build_templates()
+ self._restore()
+ self.addr = AddressHandler(self.devices)
+ self.route = RouteHandler(self.devices)
+ self.dev = DeviceHandler(self.devices)