vmware-nsx/neutron/plugins/nicira/dbexts/distributedrouter.py
Salvatore Orlando 1600cd3a2f Allow subclasses to modify dict_extend hooks
Partial-Bug 1219991

This change modifies the hook processing for dict_extend routines
to call the method on the instance if a hook is registered as a string.
Otherwise, the callable hook is directly invoked as an unbound method.

This patch fixes hook registration for all extensions except port_binding.
This is because some plugins are currently working around this limitation
by invoking both the global hook and another dict_extend function,
which might either be registered as another hook, or invoked explicitly
before returning the response.
Fixing this would go beyong the scope of this patch.

Change-Id: Ibe78433e6554aa7fdf5156fc75b8339254876e78
2013-09-02 17:37:22 -07:00

70 lines
2.9 KiB
Python

# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 Nicira Networks, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# @author: Salvatore Orlando, Nicira, Inc
#
from neutron.db import db_base_plugin_v2
from neutron.extensions import l3
from neutron.openstack.common import log as logging
from neutron.plugins.nicira.dbexts import nicira_models
from neutron.plugins.nicira.extensions import distributedrouter as dist_rtr
LOG = logging.getLogger(__name__)
class DistributedRouter_mixin(object):
"""Mixin class to enable distributed router support."""
def _extend_router_dict_distributed(self, router_res, router_db):
# Avoid setting attribute to None for routers already existing before
# the data model was extended with the distributed attribute
nsx_attrs = router_db['nsx_attributes']
# Return False if nsx attributes are not definied for this
# neutron router
router_res[dist_rtr.DISTRIBUTED] = (
nsx_attrs and nsx_attrs['distributed'] or False)
def _process_distributed_router_create(
self, context, router_db, router_req):
"""Ensures persistency for the 'distributed' attribute.
Either creates or fetches the nicira extended attributes
record for this router and stores the 'distributed'
attribute value.
This method should be called from within a transaction, as
it does not start a new one.
"""
if not router_db['nsx_attributes']:
nsx_attributes = nicira_models.NSXRouterExtAttributes(
router_id=router_db['id'],
distributed=router_req['distributed'])
context.session.add(nsx_attributes)
router_db['nsx_attributes'] = nsx_attributes
else:
# The situation where the record already exists will
# be likely once the NSXRouterExtAttributes model
# will allow for defining several attributes pertaining
# to different extensions
router_db['nsx_attributes']['distributed'] = (
router_req['distributed'])
LOG.debug(_("Distributed router extension successfully processed "
"for router:%s"), router_db['id'])
# Register dict extend functions for ports
db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs(
l3.ROUTERS, ['_extend_router_dict_distributed'])