713217322f7c82d3e1b2faf7ce6f294e580d8de2
This patch adds register_mutate_hook to ConfigOpts. When mutate_config_files is otherwise finished, it calls all the registered hooks. Each hook is passed the complete, mutated conf object, plus a dict of just the mutated keys with old and new values. Currently there's no way to change or remove a hook once registered. There's no obvious usecase for this (to me at least) and the direct implementation where we accept a unique slug alongside each hook has a good back-compat story (generate slugs if one is not provided) so I've plumped for the absolute simplest system. Hooks are called in a non-deterministic order. This is intentional, it makes it easy to avoid duplicates in the collection of hooks and enforces independence of hook functions. It also means we don't need a complex API for inspecting and reordering this collection. Initially we wanted to avoid hooks in oslo.config entirely. This leads to two problems. One, Nova delegates calling mutate_config_files to oslo.service. How is oslo.service to know which other oslo libs Nova uses and hence which need to be notified? We could solve this by passing a list of hooks to oslo.service from Nova. Ugly but workable. However, then if Nova is using oslo.foo and oslo.foo adds support for mutable config, this leads to problem two. We must patch Nova to pass the new hook to oslo.service. With 30+ OpenStack applications, this would be tedious. The collection is held on the ConfigOpts object because some projects use multiple configs. I could offer a decorator which takes the conf to register with as an argument but this would only be useful to projects which use a global conf and generally seems like extra code for minimal benefit. Doug suggested offering a hook per option or group. The former is inefficient when multiple options relate to a single resource. The latter falls down on the default group, which multiple things need to be notified about changes to. Change-Id: Ied006631a6edbeeffae485d28eff700b13a626c1
Oslo Configuration Library
The Oslo configuration API supports parsing command line arguments and .ini style configuration files.
- License: Apache License, Version 2.0
- Documentation: http://docs.openstack.org/developer/oslo.config
- Source: http://git.openstack.org/cgit/openstack/oslo.config
- Bugs: http://bugs.launchpad.net/oslo.config
Description
Languages
Python
99.8%
Shell
0.2%