diff --git a/TODO b/TODO index 2601449..46686ad 100644 --- a/TODO +++ b/TODO @@ -12,6 +12,7 @@ CRUD IP Allocations Later: Maybe implement a straight passthrough driver for testing and debugging purposes +Separate all SQL alchemy out of the plugin Allocations Controller Extension: diff --git a/quark/plugin.py b/quark/plugin.py index ed60491..36c0fcc 100644 --- a/quark/plugin.py +++ b/quark/plugin.py @@ -16,10 +16,12 @@ """ v2 Quantum Plug-in API Quark Implementation """ +import inspect import netaddr from sqlalchemy import func as sql_func from sqlalchemy.orm import sessionmaker, scoped_session +from sqlalchemy import event from zope.sqlalchemy import ZopeTransactionExtension from oslo.config import cfg @@ -55,6 +57,13 @@ if 'api_extensions_path' in CONF: CONF.set_override('api_extensions_path', ":".join(extensions.__path__)) +# NOTE(jkoelker) init event listener that will ensure id is filled in +# on object creation (prior to commit). +def perhaps_generate_id(target, args, kwargs): + if hasattr(target, 'id') and target.id is None: + target.id = uuidutils.generate_uuid() + + class Plugin(quantum_plugin_base_v2.QuantumPluginBaseV2): # NOTE(mdietz): I hate this supported_extension_aliases = ["mac_address_ranges", "routes", @@ -66,6 +75,14 @@ class Plugin(quantum_plugin_base_v2.QuantumPluginBaseV2): extension=ZopeTransactionExtension())) def __init__(self): + # NOTE(jkoelker) Register the event on all models that have ids + for _name, klass in inspect.getmembers(models, inspect.isclass): + if klass is models.HasId: + continue + + if models.HasId in klass.mro(): + event.listen(klass, "init", perhaps_generate_id) + db_api.configure_db() self._initDBMaker() self.net_driver = (importutils.import_class(CONF.QUARK.net_driver))()