commit 2587cd9176895a27e13dc10558f1e00847edab05 Author: Radek Pazdera rpazdera@redhat.com Date: Tue Jul 31 11:54:44 2012 +0200
NetConfig: Small code cleanup
This commit merges type_init() function with add_interface_config() and type_cleanup() with remove_interface_config().
These functions had too dangerous preconditions, which was not very obvious. The preconditions disappear after the merge.
Also an info entry will be written to the log when a device class is initialized or cleaned up.
Signed-off-by: Radek Pazdera rpazdera@redhat.com
NetConfig/NetConfig.py | 17 +++++++++-------- 1 files changed, 9 insertions(+), 8 deletions(-) --- diff --git a/NetConfig/NetConfig.py b/NetConfig/NetConfig.py index 57903cd..6e97478 100644 --- a/NetConfig/NetConfig.py +++ b/NetConfig/NetConfig.py @@ -58,23 +58,24 @@ class NetConfig: types.add(netdev["type"]) return types
- def _type_init(self, dev_type): + def add_interface_config(self, if_id, config): + dev_type = config["type"] if not dev_type in self._get_used_types(): + logging.info("Initializing '%s' device class", dev_type) NetConfigDeviceType(dev_type).type_init()
- def _type_cleanup(self, dev_type): - if not dev_type in self._get_used_types(): - NetConfigDeviceType(dev_type).type_cleanup() - - def add_interface_config(self, if_id, config): - self._type_init(config["type"]) self._config[if_id] = config self._devnames.assign_name(if_id, self._config)
def remove_interface_config(self, if_id): config = self._config[if_id] del self._config[if_id] - self._type_cleanup(config["type"]) + print self._config + + dev_type = config["type"] + if not dev_type in self._get_used_types(): + logging.info("Cleaning up '%s' device class.", dev_type) + NetConfigDeviceType(dev_type).type_cleanup()
def get_interface_config(self, if_id): return self._config[if_id]
lnst-developers@lists.fedorahosted.org