Example #1
0
         not context.is_admin)):
        msg = _("Specifying 'tenant_id' other than authenticated "
                "tenant in request requires admin privileges")
        raise webob.exc.HTTPBadRequest(msg)

    if is_create and 'tenant_id' not in res_dict:
        if context.tenant_id:
            res_dict['tenant_id'] = context.tenant_id
        elif 'tenant_id' in attr_info:
            msg = _("Running without keystone AuthN requires "
                    "that tenant_id is specified")
            raise webob.exc.HTTPBadRequest(msg)


def verify_attributes(res_dict, attr_info):
    extra_keys = set(res_dict.keys()) - set(attr_info.keys())
    if extra_keys:
        msg = _("Unrecognized attribute(s) '%s'") % ', '.join(extra_keys)
        raise webob.exc.HTTPBadRequest(msg)


# Shim added to move the following to neutron_lib.constants:
# ATTR_NOT_SPECIFIED
# HEX_ELEM
# UUID_PATTERN
#
# Neutron-lib migration shim. This will emit a deprecation warning on any
# reference to constants that have been moved out of this module and into
# the neutron_lib.constants module.
_deprecate._MovedGlobals(constants)
Example #2
0
    def update_security_group_on_port(self, context, id, port,
                                      original_port, updated_port):
        """Update security groups on port.

        This method returns a flag which indicates request notification
        is required and does not perform notification itself.
        It is because another changes for the port may require notification.
        """
        need_notify = False
        port_updates = port['port']
        if (ext_sg.SECURITYGROUPS in port_updates and
            not helpers.compare_elements(
                original_port.get(ext_sg.SECURITYGROUPS),
                port_updates[ext_sg.SECURITYGROUPS])):
            # delete the port binding and read it with the new rules
            port_updates[ext_sg.SECURITYGROUPS] = (
                self._get_security_groups_on_port(context, port))
            self._delete_port_security_group_bindings(context, id)
            self._process_port_create_security_group(
                context,
                updated_port,
                port_updates[ext_sg.SECURITYGROUPS])
            need_notify = True
        else:
            updated_port[ext_sg.SECURITYGROUPS] = (
                original_port[ext_sg.SECURITYGROUPS])
        return need_notify


_deprecate._MovedGlobals()
Example #3
0
#
#    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.

from neutron_lib.db import model_base as lib_mb
import sqlalchemy as sa

from neutron.common import _deprecate


_deprecate._moved_global('HasTenant', new_module=lib_mb, new_name='HasProject')


def get_unique_keys(model):
    try:
        constraints = model.__table__.constraints
    except AttributeError:
        constraints = []
    return [[c.name for c in constraint.columns]
            for constraint in constraints
            if isinstance(constraint, sa.UniqueConstraint)]

# This shim is used to deprecate the old contents.
_deprecate._MovedGlobals(lib_mb)
# 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.

"""
Used by test cases in test__deprecate.py
"""

from neutron.common import _deprecate

from neutron.tests.unit.common import moved_globals_target

# a has been moved to moved_globals_target.a
b = 'barasingha'
# c has been renamed to d
d = 'capybara'
# e has been moved to moved_globals_target.f
g = 'gelada'

_deprecate._moved_global('c', new_name='d')
_deprecate._moved_global('e', new_name='f', new_module=moved_globals_target)

_deprecate._MovedGlobals(moved_globals_target)
Example #5
0
# 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.

"""
Used by test cases in test__deprecate.py
"""

from neutron.common import _deprecate

from neutron.tests.unit.common import moved_globals_target

global1 = 'foo'

_deprecate._MovedGlobals(moved_globals_target)
global2 = 'bar'
Example #6
0
def _delete_segments_for_network(resource, event, trigger, context,
                                 network_id):
    admin_ctx = context.elevated()
    global segments_plugin
    if not segments_plugin:
        segments_plugin = manager.NeutronManager.load_class_for_provider(
            'neutron.service_plugins', 'segments')()
    segments = segments_plugin.get_segments(
        admin_ctx, filters={'network_id': [network_id]})
    for segment in segments:
        segments_plugin.delete_segment(admin_ctx,
                                       segment['id'],
                                       for_net_delete=True)


def subscribe():
    registry.subscribe(_update_segment_host_mapping_for_agent, resources.AGENT,
                       events.AFTER_CREATE)
    registry.subscribe(_update_segment_host_mapping_for_agent, resources.AGENT,
                       events.AFTER_UPDATE)
    registry.subscribe(_add_segment_host_mapping_for_segment,
                       resources.SEGMENT, events.PRECOMMIT_CREATE)
    registry.subscribe(_delete_segments_for_network, resources.NETWORK,
                       events.PRECOMMIT_DELETE)


subscribe()

_deprecate._MovedGlobals()
Example #7
0
# Copyright (c) 2015 Red Hat, Inc.
#
#    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.

from ovsdbapp.backend.ovs_idl import idlutils

from neutron.common import _deprecate

_deprecate._MovedGlobals(idlutils)