provide way to specify id in models_v2

Asked by Aaron Rosen

Currently in models_v2.py there is no way to pass in your own id for tables that inherit HasId.

For example:

class HasId(object):
    """id mixin, add to subclasses that have an id."""
    id = sa.Column(sa.String(36), primary_key=True, default=utils.str_uuid)

class Network(model_base.BASEV2, HasId, HasTenant):
    <...snip>

I suggest modifying db_base_plugin_v2.py so this is possible:

For example:

  def create_network(self, context, network):
        n = network['network']

        tenant_id = self._get_tenant_id_for_create(context, n)
        with context.session.begin():
            network = models_v2.Network(tenant_id=tenant_id,
                                        id = n.get('id') or utils.str_uuid(),
           <..snip>

This modification would not change the interface at all. Does anyone have any strong opinions against this? If not I'll make a bug report and provide the patch.

Thanks,

Aaron

Question information

Language:
English Edit question
Status:
Solved
For:
neutron Edit question
Assignee:
No assignee Edit question
Solved by:
Aaron Rosen
Solved:
Last query:
Last reply:
Revision history for this message
dan wendlandt (danwent) said :
#1

yeah, i think that makes sense, given that certain plugins may be using external ids. It sounds like it won't break things for other people, I think you can just go right ahead.

Revision history for this message
Aaron Rosen (arosen) said :
#2

Thanks, bug created.