Beispiel #1
0
import netaddr
from neutron_lib.utils import helpers
from oslo_config import cfg
from oslo_log import log as logging

from neutron._i18n import _
from neutron.common import _deprecate
from neutron.db import db_base_plugin_v2
from neutron.db import l3_db
from neutron.db.models import l3 as l3_models
from neutron.db import models_v2
from neutron.extensions import extraroute
from neutron.extensions import l3

_deprecate._moved_global('RouterRoute', new_module=l3_models)

LOG = logging.getLogger(__name__)

extra_route_opts = [
    #TODO(nati): use quota framework when it support quota for attributes
    cfg.IntOpt('max_routes', default=30,
               help=_("Maximum number of routes per router")),
]

cfg.CONF.register_opts(extra_route_opts)


class ExtraRoute_dbonly_mixin(l3_db.L3_NAT_dbonly_mixin):
    """Mixin class to support extra route configuration on router."""
Beispiel #2
0
from oslo_utils import uuidutils
from sqlalchemy.orm import exc

from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import _deprecate
from neutron.db import api as db_api
from neutron.db import common_db_mixin
from neutron.db.models import segment as segment_model
from neutron.db import segments_db as db
from neutron.extensions import segment as extension
from neutron import manager
from neutron.services.segments import exceptions

_deprecate._moved_global('SegmentHostMapping', new_module=segment_model)


class SegmentDbMixin(common_db_mixin.CommonDbMixin):
    """Mixin class to add segment."""

    def _make_segment_dict(self, segment_db, fields=None):
        res = {'id': segment_db['id'],
               'network_id': segment_db['network_id'],
               'name': segment_db['name'],
               'description': segment_db['description'],
               db.PHYSICAL_NETWORK: segment_db[db.PHYSICAL_NETWORK],
               db.NETWORK_TYPE: segment_db[db.NETWORK_TYPE],
               db.SEGMENTATION_ID: segment_db[db.SEGMENTATION_ID],
               'hosts': [mapping.host for mapping in
                         segment_db.segment_host_mapping],
Beispiel #3
0
#    under the License.

from debtcollector import moves
from neutron_lib.api import converters as lib_converters
from neutron_lib.api import validators as lib_validators
from neutron_lib import constants
import six
import webob.exc

from neutron._i18n import _
from neutron.common import _deprecate

# Defining a constant to avoid repeating string literal in several modules
SHARED = 'shared'

_deprecate._moved_global('UNLIMITED', new_module=lib_validators)

# TODO(HenryG): use DB field sizes (neutron-lib 0.1.1)
NAME_MAX_LEN = 255
TENANT_ID_MAX_LEN = 255
DESCRIPTION_MAX_LEN = 255
LONG_DESCRIPTION_MAX_LEN = 1024
DEVICE_ID_MAX_LEN = 255
DEVICE_OWNER_MAX_LEN = 255


def _lib(old_name):
    """Deprecate a function moved to neutron_lib.api.converters/validators."""
    new_func = getattr(lib_validators, old_name, None)
    if not new_func:
        # Try non-private name (without leading underscore)
Beispiel #4
0
from neutron.db.availability_zone import router as router_az_db
from neutron.db import common_db_mixin
from neutron.db import l3_dvr_db
from neutron.db.l3_dvr_db import is_distributed_router
from neutron.db.models import agent as agent_model
from neutron.db.models import l3 as l3_models
from neutron.db.models import l3_attrs
from neutron.db.models import l3ha as l3ha_model
from neutron.extensions import l3
from neutron.extensions import l3_ext_ha_mode as l3_ha
from neutron.extensions import portbindings
from neutron.extensions import providernet
from neutron.plugins.common import utils as p_utils


_deprecate._moved_global('L3HARouterAgentPortBinding', new_module=l3ha_model)
_deprecate._moved_global('L3HARouterNetwork', new_module=l3ha_model)
_deprecate._moved_global('L3HARouterVRIdAllocation', new_module=l3ha_model)

VR_ID_RANGE = set(range(1, 255))
MAX_ALLOCATION_TRIES = 10
UNLIMITED_AGENTS_PER_ROUTER = 0

LOG = logging.getLogger(__name__)

L3_HA_OPTS = [
    cfg.BoolOpt('l3_ha',
                default=False,
                help=_('Enable HA mode for virtual routers.')),
    cfg.IntOpt('max_l3_agents_per_router',
               default=3,
Beispiel #5
0
from sqlalchemy import sql

from neutron._i18n import _, _LI
from neutron.agent.common import utils as agent_utils
from neutron.common import _deprecate
from neutron.common import utils as n_utils
from neutron.db import agentschedulers_db
from neutron.db.models import agent as agent_model
from neutron.db.models import l3_attrs
from neutron.db.models import l3agent as rb_model
from neutron.extensions import l3agentscheduler
from neutron.extensions import router_availability_zone as router_az
from neutron import manager
from neutron.plugins.common import constants as service_constants

_deprecate._moved_global('RouterL3AgentBinding', new_module=rb_model)

LOG = logging.getLogger(__name__)

L3_AGENTS_SCHEDULER_OPTS = [
    cfg.StrOpt('router_scheduler_driver',
               default='neutron.scheduler.l3_agent_scheduler.'
               'LeastRoutersScheduler',
               help=_('Driver to use for scheduling '
                      'router to a default L3 agent')),
    cfg.BoolOpt('router_auto_schedule',
                default=True,
                help=_('Allow auto scheduling of routers to L3 agent.')),
    cfg.BoolOpt('allow_automatic_l3agent_failover',
                default=False,
                help=_('Automatically reschedule routers from offline L3 '
#    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.

# TODO(ihrachys): consider renaming the module since now it does not contain
# any models at all

from neutron.api.v2 import attributes
from neutron.common import _deprecate
from neutron.db import common_db_mixin
from neutron.db.models import subnet_service_type as sst_model


_deprecate._moved_global('SubnetServiceType', new_module=sst_model)


class SubnetServiceTypeMixin(object):
    """Mixin class to extend subnet with service type attribute"""

    def _extend_subnet_service_types(self, subnet_res, subnet_db):
        subnet_res['service_types'] = [service_type['service_type'] for
                                       service_type in
                                       subnet_db.service_types]

    common_db_mixin.CommonDbMixin.register_dict_extend_funcs(
        attributes.SUBNETS, [_extend_subnet_service_types])


_deprecate._MovedGlobals()
Beispiel #7
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 oslo_config import cfg

from neutron._i18n import _
from neutron.common import _deprecate
from neutron.db import db_base_plugin_v2
from neutron.db.models import l3_attrs
from neutron.extensions import availability_zone as az
from neutron.extensions import l3

_deprecate._moved_global('RouterExtraAttributes', new_module=l3_attrs)


def get_attr_info():
    """Returns api visible attr names and their default values."""
    return {'distributed': {'default': cfg.CONF.router_distributed},
            'ha': {'default': cfg.CONF.l3_ha},
            'ha_vr_id': {'default': 0},
            'availability_zone_hints': {
                'default': '[]',
                'transform_to_db': az.convert_az_list_to_string,
                'transform_from_db': az.convert_az_string_to_list}
            }


class ExtraAttributesMixin(object):
from neutron_lib import constants
from neutron_lib.db import model_base
import sqlalchemy as sa
from sqlalchemy import orm
from sqlalchemy import sql

from neutron.api.v2 import attributes as attr
from neutron.common import _deprecate
from neutron.db.network_dhcp_agent_binding import models as ndab_model
from neutron.db import rbac_db_models
from neutron.db import standard_attr

# NOTE(kevinbenton): these are here for external projects that expect them
# to be found in this module.
_deprecate._moved_global('HasTenant',
                         new_name='HasProject',
                         new_module=model_base)
_deprecate._moved_global('HasId', new_module=model_base)
_deprecate._moved_global('HasStatusDescription', new_module=model_base)


class IPAvailabilityRange(model_base.BASEV2):
    """Internal representation of available IPs for Neutron subnets.

    Allocation - first entry from the range will be allocated.
    If the first entry is equal to the last entry then this row
    will be deleted.
    Recycling ips involves reading the IPAllocationPool and IPAllocation tables
    and inserting ranges representing available ips.  This happens after the
    final allocation is pulled from this table and a new ip allocation is
    requested.  Any contiguous ranges of available ips will be inserted as a
Beispiel #9
0
#    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.api import validators

from neutron.api.v2 import attributes
from neutron.common import _deprecate
from neutron.db import db_base_plugin_v2
from neutron.db.models import portbinding as pmodels
from neutron.db import models_v2
from neutron.db import portbindings_base
from neutron.extensions import portbindings

_deprecate._moved_global('PortBindingPort', new_module=pmodels)


class PortBindingMixin(portbindings_base.PortBindingBaseMixin):
    extra_binding_dict = None

    def _port_model_hook(self, context, original_model, query):
        query = query.outerjoin(
            pmodels.PortBindingPort,
            (original_model.id == pmodels.PortBindingPort.port_id))
        return query

    def _port_result_filter_hook(self, query, filters):
        values = filters and filters.get(portbindings.HOST_ID, [])
        if not values:
            return query
Beispiel #10
0
from neutron_lib import exceptions as n_exc
from oslo_config import cfg
from oslo_log import log

from neutron._i18n import _LE
from neutron.common import _deprecate
from neutron.conf.plugins.ml2.drivers import driver_type
from neutron.db.models.plugins.ml2 import geneveallocation \
     as geneve_model
from neutron.plugins.common import constants as p_const
from neutron.plugins.ml2.drivers import type_tunnel

LOG = log.getLogger(__name__)

_deprecate._moved_global('GeneveAllocation', new_module=geneve_model)
_deprecate._moved_global('GeneveEndpoints', new_module=geneve_model)

driver_type.register_ml2_drivers_geneve_opts()


class GeneveTypeDriver(type_tunnel.EndpointTunnelTypeDriver):

    def __init__(self):
        super(GeneveTypeDriver, self).__init__(geneve_model.GeneveAllocation,
                                               geneve_model.GeneveEndpoints)
        self.max_encap_size = cfg.CONF.ml2_type_geneve.max_header_size

    def get_type(self):
        return p_const.TYPE_GENEVE
Beispiel #11
0
#    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.api import validators

from neutron.api.v2 import attributes
from neutron.common import _deprecate
from neutron.db import db_base_plugin_v2
from neutron.db.models import portbinding as pmodels
from neutron.db import models_v2
from neutron.db import portbindings_base
from neutron.extensions import portbindings


_deprecate._moved_global('PortBindingPort', new_module=pmodels)


class PortBindingMixin(portbindings_base.PortBindingBaseMixin):
    extra_binding_dict = None

    def _port_model_hook(self, context, original_model, query):
        query = query.outerjoin(
            pmodels.PortBindingPort,
            (original_model.id == pmodels.PortBindingPort.port_id))
        return query

    def _port_result_filter_hook(self, query, filters):
        values = filters and filters.get(portbindings.HOST_ID, [])
        if not values:
            return query
Beispiel #12
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 sqlalchemy.orm import aliased

from neutron.common import _deprecate
from neutron.db.models import tag as tag_model

_deprecate._moved_global('Tag', new_module=tag_model)


def _get_tag_list(tag_strings):
    tags = set()
    for tag_str in tag_strings:
        tags |= set(tag_str.split(','))
    return list(tags)


def apply_tag_filters(model, query, filters):
    """Apply tag filters

    There are four types of filter:
    `tags` -- One or more strings that will be used to filter results
            in an AND expression: T1 AND T2
Beispiel #13
0
#    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 oslo_log import log as logging
from oslo_utils import uuidutils
from sqlalchemy.orm import exc

from neutron._i18n import _LI
from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import _deprecate
from neutron.db.models import segment as segments_model

_deprecate._moved_global('NetworkSegment', new_module=segments_model)

LOG = logging.getLogger(__name__)

NETWORK_TYPE = segments_model.NetworkSegment.network_type.name
PHYSICAL_NETWORK = segments_model.NetworkSegment.physical_network.name
SEGMENTATION_ID = segments_model.NetworkSegment.segmentation_id.name


def _make_segment_dict(record):
    """Make a segment dictionary out of a DB record."""
    return {'id': record.id,
            NETWORK_TYPE: record.network_type,
            PHYSICAL_NETWORK: record.physical_network,
            SEGMENTATION_ID: record.segmentation_id}
Beispiel #14
0
from neutron.common import _deprecate
from neutron.db import _utils as db_utils
from neutron.db import db_base_plugin_v2
from neutron.db.models import external_net as ext_net_models
from neutron.db.models import l3 as l3_models
from neutron.db import models_v2
from neutron.db import rbac_db_models as rbac_db
from neutron.extensions import external_net
from neutron.extensions import rbac as rbac_ext
from neutron import manager
from neutron.plugins.common import constants as service_constants


DEVICE_OWNER_ROUTER_GW = lib_constants.DEVICE_OWNER_ROUTER_GW

_deprecate._moved_global('ExternalNetwork', new_module=ext_net_models)


class External_net_db_mixin(object):
    """Mixin class to add external network methods to db_base_plugin_v2."""

    def _network_model_hook(self, context, original_model, query):
        query = query.outerjoin(ext_net_models.ExternalNetwork,
                                (original_model.id ==
                                 ext_net_models.ExternalNetwork.network_id))
        return query

    @staticmethod
    def _network_filter_hook(context, original_model, conditions):
        if conditions is not None and not hasattr(conditions, '__iter__'):
            conditions = (conditions, )
Beispiel #15
0
from neutron._i18n import _, _LE
from neutron.common import _deprecate
from neutron.common import utils
from neutron.db import db_base_plugin_v2
from neutron.db.models import dns as dns_models
from neutron.extensions import dns
from neutron.extensions import l3
from neutron.objects import floatingip as fip_obj
from neutron.objects import network
from neutron.objects import ports as port_obj
from neutron.services.externaldns import driver

LOG = logging.getLogger(__name__)

_deprecate._moved_global('PortDNS', new_module=dns_models)
_deprecate._moved_global('NetworkDNSDomain', new_module=dns_models)
_deprecate._moved_global('FloatingIPDNS', new_module=dns_models)


class DNSActionsData(object):
    def __init__(self,
                 current_dns_name=None,
                 current_dns_domain=None,
                 previous_dns_name=None,
                 previous_dns_domain=None):
        self.current_dns_name = current_dns_name
        self.current_dns_domain = current_dns_domain
        self.previous_dns_name = previous_dns_name
        self.previous_dns_domain = previous_dns_domain
Beispiel #16
0
#    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 oslo_log import log as logging
from oslo_utils import uuidutils
from sqlalchemy.orm import exc

from neutron._i18n import _LI
from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import _deprecate
from neutron.db.models import segment as segments_model

_deprecate._moved_global('NetworkSegment', new_module=segments_model)

LOG = logging.getLogger(__name__)

NETWORK_TYPE = segments_model.NetworkSegment.network_type.name
PHYSICAL_NETWORK = segments_model.NetworkSegment.physical_network.name
SEGMENTATION_ID = segments_model.NetworkSegment.segmentation_id.name


def _make_segment_dict(record):
    """Make a segment dictionary out of a DB record."""
    return {
        'id': record.id,
        NETWORK_TYPE: record.network_type,
        PHYSICAL_NETWORK: record.physical_network,
        SEGMENTATION_ID: record.segmentation_id
Beispiel #17
0
from neutron._i18n import _, _LE
from neutron.common import _deprecate
from neutron.common import utils
from neutron.db import db_base_plugin_v2
from neutron.db.models import dns as dns_models
from neutron.extensions import dns
from neutron.extensions import l3
from neutron.objects import floatingip as fip_obj
from neutron.objects import network
from neutron.objects import ports as port_obj
from neutron.services.externaldns import driver

LOG = logging.getLogger(__name__)


_deprecate._moved_global('PortDNS', new_module=dns_models)
_deprecate._moved_global('NetworkDNSDomain', new_module=dns_models)
_deprecate._moved_global('FloatingIPDNS', new_module=dns_models)


class DNSActionsData(object):

    def __init__(self, current_dns_name=None, current_dns_domain=None,
                 previous_dns_name=None, previous_dns_domain=None):
        self.current_dns_name = current_dns_name
        self.current_dns_domain = current_dns_domain
        self.previous_dns_name = previous_dns_name
        self.previous_dns_domain = previous_dns_domain


class DNSDbMixin(object):
Beispiel #18
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)
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.db import api as db_api

from neutron.common import _deprecate
from neutron.db.models import provisioning_block as pb_model
from neutron.db import models_v2

LOG = logging.getLogger(__name__)
PROVISIONING_COMPLETE = 'provisioning_complete'
# identifiers for the various entities that participate in provisioning
DHCP_ENTITY = 'DHCP'
L2_AGENT_ENTITY = 'L2'
_RESOURCE_TO_MODEL_MAP = {resources.PORT: models_v2.Port}

_deprecate._moved_global('ProvisioningBlock', new_module=pb_model)


def add_model_for_resource(resource, model):
    """Adds a mapping between a callback resource and a DB model."""
    _RESOURCE_TO_MODEL_MAP[resource] = model


@db_api.retry_if_session_inactive()
def add_provisioning_component(context, object_id, object_type, entity):
    """Adds a provisioning block by an entity to a given object.

    Adds a provisioning block to the DB for object_id with an identifier
    of the entity that is doing the provisioning. While an object has these
    provisioning blocks present, this module will not emit any callback events
    indicating that provisioning has completed. Any logic that depends on
Beispiel #20
0
from debtcollector import moves
from neutron_lib.api import converters as lib_converters
from neutron_lib.api import validators as lib_validators
from neutron_lib import constants
import six
import webob.exc

from neutron._i18n import _
from neutron.common import _deprecate


# Defining a constant to avoid repeating string literal in several modules
SHARED = 'shared'

_deprecate._moved_global('UNLIMITED', new_module=lib_validators)

# TODO(HenryG): use DB field sizes (neutron-lib 0.1.1)
NAME_MAX_LEN = 255
TENANT_ID_MAX_LEN = 255
DESCRIPTION_MAX_LEN = 255
LONG_DESCRIPTION_MAX_LEN = 1024
DEVICE_ID_MAX_LEN = 255
DEVICE_OWNER_MAX_LEN = 255


def _lib(old_name):
    """Deprecate a function moved to neutron_lib.api.converters/validators."""
    new_func = getattr(lib_validators, old_name, None)
    if not new_func:
        # Try non-private name (without leading underscore)
Beispiel #21
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.

# TODO(ihrachys): consider renaming the module since now it does not contain
# any models at all

from neutron.api.v2 import attributes
from neutron.common import _deprecate
from neutron.db import common_db_mixin
from neutron.db.models import subnet_service_type as sst_model

_deprecate._moved_global('SubnetServiceType', new_module=sst_model)


class SubnetServiceTypeMixin(object):
    """Mixin class to extend subnet with service type attribute"""
    def _extend_subnet_service_types(self, subnet_res, subnet_db):
        subnet_res['service_types'] = [
            service_type['service_type']
            for service_type in subnet_db.service_types
        ]

    common_db_mixin.CommonDbMixin.register_dict_extend_funcs(
        attributes.SUBNETS, [_extend_subnet_service_types])


_deprecate._MovedGlobals()
Beispiel #22
0
#    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 itertools import chain

from oslo_log import log as logging

from neutron.common import _deprecate
from neutron.db.models import servicetype as st_model
from neutron.objects import servicetype as servicetype_obj
from neutron.services import provider_configuration as pconf

LOG = logging.getLogger(__name__)

_deprecate._moved_global('ProviderResourceAssociation', new_module=st_model)


class ServiceTypeManager(object):
    """Manage service type objects in Neutron."""

    _instance = None

    @classmethod
    def get_instance(cls):
        if cls._instance is None:
            cls._instance = cls()
        return cls._instance

    def __init__(self):
        self.config = {}
Beispiel #23
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 sqlalchemy.orm import aliased

from neutron.common import _deprecate
from neutron.db.models import tag as tag_model

_deprecate._moved_global('Tag', new_module=tag_model)


def _get_tag_list(tag_strings):
    tags = set()
    for tag_str in tag_strings:
        tags |= set(tag_str.split(','))
    return list(tags)


def apply_tag_filters(model, query, filters):
    """Apply tag filters

    There are four types of filter:
    `tags` -- One or more strings that will be used to filter results
            in an AND expression: T1 AND T2
Beispiel #24
0
from sqlalchemy import or_
from sqlalchemy.orm import exc

from neutron._i18n import _, _LE
from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import _deprecate
from neutron.common import utils
from neutron.db import api as db_api
from neutron.db.models import dvr as dvr_models
from neutron.db import models_v2
from neutron.extensions import dvr as ext_dvr
from neutron.extensions import portbindings

_deprecate._moved_global('DistributedVirtualRouterMacAddress',
                         new_module=dvr_models)

LOG = logging.getLogger(__name__)

dvr_mac_address_opts = [
    cfg.StrOpt('dvr_base_mac',
               default="fa:16:3f:00:00:00",
               help=_("The base mac address used for unique "
                      "DVR instances by Neutron. The first 3 octets will "
                      "remain unchanged. If the 4th octet is not 00, it will "
                      "also be used. The others will be randomly generated. "
                      "The 'dvr_base_mac' *must* be different from "
                      "'base_mac' to avoid mixing them up with MAC's "
                      "allocated for tenant ports. A 4 octet example would be "
                      "dvr_base_mac = fa:16:3f:4f:00:00. The default is 3 "
                      "octet")),
Beispiel #25
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.

from neutron.common import _deprecate
from neutron.db.models import allowed_address_pair as aap_models


_deprecate._moved_global('AllowedAddressPair', new_module=aap_models)


_deprecate._MovedGlobals()
Beispiel #26
0
#    under the License.

from neutron_lib import exceptions as n_exc
from oslo_config import cfg
from oslo_log import log

from neutron._i18n import _LE
from neutron.common import _deprecate
from neutron.conf.plugins.ml2.drivers import driver_type
from neutron.db.models.plugins.ml2 import vxlanallocation as vxlan_model
from neutron.plugins.common import constants as p_const
from neutron.plugins.ml2.drivers import type_tunnel

LOG = log.getLogger(__name__)

_deprecate._moved_global('VxlanAllocation', new_module=vxlan_model)
_deprecate._moved_global('VxlanEndpoints', new_module=vxlan_model)

driver_type.register_ml2_drivers_vxlan_opts()


class VxlanTypeDriver(type_tunnel.EndpointTunnelTypeDriver):

    def __init__(self):
        super(VxlanTypeDriver, self).__init__(
            vxlan_model.VxlanAllocation, vxlan_model.VxlanEndpoints)

    def get_type(self):
        return p_const.TYPE_VXLAN

    def initialize(self):
Beispiel #27
0
from neutron._i18n import _
from neutron.api.v2 import attributes
from neutron.callbacks import events
from neutron.callbacks import exceptions
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import _deprecate
from neutron.common import constants as n_const
from neutron.common import utils
from neutron.db import api as db_api
from neutron.db import db_base_plugin_v2
from neutron.db.models import securitygroup as sg_models
from neutron.extensions import securitygroup as ext_sg


_deprecate._moved_global("DefaultSecurityGroup", new_module=sg_models)
_deprecate._moved_global("SecurityGroupPortBinding", new_module=sg_models)
_deprecate._moved_global("SecurityGroupRule", new_module=sg_models)


class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
    """Mixin class to add security group to db_base_plugin_v2."""

    __native_bulk_support = True

    def create_security_group_bulk(self, context, security_group_rule):
        return self._create_bulk("security_group", context, security_group_rule)

    def _registry_notify(self, res, event, id=None, exc_cls=None, **kwargs):
        # NOTE(armax): a callback exception here will prevent the request
        # from being processed. This is a hook point for backend's validation;
Beispiel #28
0
from neutron_lib import constants
from oslo_utils import uuidutils

from neutron._i18n import _
from neutron.api.v2 import attributes as attr
from neutron.common import _deprecate
from neutron.db import _utils as db_utils
from neutron.db import api as db_api
from neutron.db import db_base_plugin_v2
from neutron.db.models import address_scope as address_scope_model
from neutron.extensions import address_scope as ext_address_scope
from neutron.objects import address_scope as obj_addr_scope
from neutron.objects import base as base_obj
from neutron.objects import subnetpool as subnetpool_obj

_deprecate._moved_global('AddressScope', new_module=address_scope_model)


class AddressScopeDbMixin(ext_address_scope.AddressScopePluginBase):
    """Mixin class to add address scope to db_base_plugin_v2."""

    __native_bulk_support = True

    @staticmethod
    def _make_address_scope_dict(address_scope, fields=None):
        res = {
            'id': address_scope['id'],
            'name': address_scope['name'],
            'tenant_id': address_scope['tenant_id'],
            'shared': address_scope['shared'],
            'ip_version': address_scope['ip_version']
Beispiel #29
0
from oslo_utils import uuidutils

from neutron._i18n import _
from neutron.api.v2 import attributes as attr
from neutron.common import _deprecate
from neutron.db import _utils as db_utils
from neutron.db import api as db_api
from neutron.db import db_base_plugin_v2
from neutron.db.models import address_scope as address_scope_model
from neutron.extensions import address_scope as ext_address_scope
from neutron.objects import address_scope as obj_addr_scope
from neutron.objects import base as base_obj
from neutron.objects import subnetpool as subnetpool_obj


_deprecate._moved_global('AddressScope', new_module=address_scope_model)


class AddressScopeDbMixin(ext_address_scope.AddressScopePluginBase):
    """Mixin class to add address scope to db_base_plugin_v2."""

    __native_bulk_support = True

    @staticmethod
    def _make_address_scope_dict(address_scope, fields=None):
        res = {'id': address_scope['id'],
               'name': address_scope['name'],
               'tenant_id': address_scope['tenant_id'],
               'shared': address_scope['shared'],
               'ip_version': address_scope['ip_version']}
        return db_utils.resource_fields(res, fields)
Beispiel #30
0
from neutron.common import _deprecate
from neutron.common import exceptions as n_exc
from neutron.conf.plugins.ml2.drivers import driver_type
from neutron.db.models.plugins.ml2 import flatallocation as type_flat_model
from neutron.objects import exceptions as obj_base
from neutron.objects.plugins.ml2 import flatallocation as flat_obj
from neutron.plugins.common import constants as p_const
from neutron.plugins.ml2 import driver_api as api
from neutron.plugins.ml2.drivers import helpers

LOG = log.getLogger(__name__)

driver_type.register_ml2_drivers_flat_opts()


_deprecate._moved_global('FlatAllocation', new_module=type_flat_model)


class FlatTypeDriver(helpers.BaseTypeDriver):
    """Manage state for flat networks with ML2.

    The FlatTypeDriver implements the 'flat' network_type. Flat
    network segments provide connectivity between VMs and other
    devices using any connected IEEE 802.1D conformant
    physical_network, without the use of VLAN tags, tunneling, or
    other segmentation mechanisms. Therefore at most one flat network
    segment can exist on each available physical_network.
    """

    def __init__(self):
        super(FlatTypeDriver, self).__init__()
Beispiel #31
0
#    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 itertools import chain

from oslo_log import log as logging

from neutron.common import _deprecate
from neutron.db.models import servicetype as st_model
from neutron.services import provider_configuration as pconf

LOG = logging.getLogger(__name__)

_deprecate._moved_global('ProviderResourceAssociation', new_module=st_model)


class ServiceTypeManager(object):
    """Manage service type objects in Neutron."""

    _instance = None

    @classmethod
    def get_instance(cls):
        if cls._instance is None:
            cls._instance = cls()
        return cls._instance

    def __init__(self):
        self.config = {}
Beispiel #32
0
from sqlalchemy.orm import exc

from neutron._i18n import _, _LE
from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import _deprecate
from neutron.common import utils
from neutron.db import api as db_api
from neutron.db.models import dvr as dvr_models
from neutron.db import models_v2
from neutron.extensions import dvr as ext_dvr
from neutron.extensions import portbindings
from neutron import manager

_deprecate._moved_global('DistributedVirtualRouterMacAddress',
                         new_module=dvr_models)

LOG = logging.getLogger(__name__)


dvr_mac_address_opts = [
    cfg.StrOpt('dvr_base_mac',
               default="fa:16:3f:00:00:00",
               help=_("The base mac address used for unique "
                      "DVR instances by Neutron. The first 3 octets will "
                      "remain unchanged. If the 4th octet is not 00, it will "
                      "also be used. The others will be randomly generated. "
                      "The 'dvr_base_mac' *must* be different from "
                      "'base_mac' to avoid mixing them up with MAC's "
                      "allocated for tenant ports. A 4 octet example would be "
                      "dvr_base_mac = fa:16:3f:4f:00:00. The default is 3 "
Beispiel #33
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.

from neutron.common import _deprecate
from neutron.db.models import allowed_address_pair as aap_models

_deprecate._moved_global('AllowedAddressPair', new_module=aap_models)

_deprecate._MovedGlobals()
# 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)
Beispiel #35
0
from neutron_lib import constants
from neutron_lib.db import model_base
import sqlalchemy as sa
from sqlalchemy import orm
from sqlalchemy import sql

from neutron.api.v2 import attributes as attr
from neutron.common import _deprecate
from neutron.db.network_dhcp_agent_binding import models as ndab_model
from neutron.db import rbac_db_models
from neutron.db import standard_attr


# NOTE(kevinbenton): these are here for external projects that expect them
# to be found in this module.
_deprecate._moved_global('HasTenant', new_name='HasProject',
                         new_module=model_base)
_deprecate._moved_global('HasId', new_module=model_base)
_deprecate._moved_global('HasStatusDescription', new_module=model_base)


class IPAllocationPool(model_base.BASEV2, model_base.HasId):
    """Representation of an allocation pool in a Neutron subnet."""

    subnet_id = sa.Column(sa.String(36), sa.ForeignKey('subnets.id',
                                                       ondelete="CASCADE"),
                          nullable=True)
    first_ip = sa.Column(sa.String(64), nullable=False)
    last_ip = sa.Column(sa.String(64), nullable=False)

    def __repr__(self):
        return "%s - %s" % (self.first_ip, self.last_ip)
Beispiel #36
0
from neutron.plugins.common import constants as p_const
from neutron.plugins.ml2.drivers import type_tunnel

LOG = log.getLogger(__name__)

gre_opts = [
    cfg.ListOpt('tunnel_id_ranges',
                default=[],
                help=_("Comma-separated list of <tun_min>:<tun_max> tuples "
                       "enumerating ranges of GRE tunnel IDs that are "
                       "available for tenant network allocation"))
]

cfg.CONF.register_opts(gre_opts, "ml2_type_gre")

_deprecate._moved_global('GreAllocation', new_module=gre_model)
_deprecate._moved_global('GreEndpoints', new_module=gre_model)


class GreTypeDriver(type_tunnel.EndpointTunnelTypeDriver):
    def __init__(self):
        super(GreTypeDriver, self).__init__(gre_model.GreAllocation,
                                            gre_model.GreEndpoints)

    def get_type(self):
        return p_const.TYPE_GRE

    def initialize(self):
        try:
            self._initialize(cfg.CONF.ml2_type_gre.tunnel_id_ranges)
        except n_exc.NetworkTunnelRangeError:
Beispiel #37
0
# License for the specific language governing permissions and limitations
# under the License.

import netaddr
from oslo_utils import uuidutils
from sqlalchemy import orm

from neutron.api.rpc.agentnotifiers import metering_rpc_agent_api
from neutron.common import _deprecate
from neutron.common import constants
from neutron.db import common_db_mixin as base_db
from neutron.db.models import l3 as l3_models
from neutron.db.models import metering as metering_models
from neutron.extensions import metering

_deprecate._moved_global('MeteringLabelRule', new_module=metering_models)
_deprecate._moved_global('MeteringLabel', new_module=metering_models)


class MeteringDbMixin(metering.MeteringPluginBase, base_db.CommonDbMixin):
    def __init__(self):
        self.meter_rpc = metering_rpc_agent_api.MeteringAgentNotifyAPI()

    def _make_metering_label_dict(self, metering_label, fields=None):
        res = {
            'id': metering_label['id'],
            'name': metering_label['name'],
            'description': metering_label['description'],
            'shared': metering_label['shared'],
            'tenant_id': metering_label['tenant_id']
        }
Beispiel #38
0
from six import moves

from neutron._i18n import _, _LE, _LI, _LW
from neutron.common import _deprecate
from neutron.conf.plugins.ml2.drivers import driver_type
from neutron import context
from neutron.db import api as db_api
from neutron.db.models.plugins.ml2 import vlanallocation as vlan_alloc_model
from neutron.plugins.common import constants as p_const
from neutron.plugins.common import utils as plugin_utils
from neutron.plugins.ml2 import driver_api as api
from neutron.plugins.ml2.drivers import helpers

LOG = log.getLogger(__name__)

_deprecate._moved_global('VlanAllocation', new_module=vlan_alloc_model)

driver_type.register_ml2_drivers_vlan_opts()


class VlanTypeDriver(helpers.SegmentTypeDriver):
    """Manage state for VLAN networks with ML2.

    The VlanTypeDriver implements the 'vlan' network_type. VLAN
    network segments provide connectivity between VMs and other
    devices using any connected IEEE 802.1Q conformant
    physical_network segmented into virtual networks via IEEE 802.1Q
    headers. Up to 4094 VLAN network segments can exist on each
    available physical_network.
    """
    def __init__(self):
Beispiel #39
0
                      'Example: dhcp_load_type=networks')),
    cfg.BoolOpt('enable_new_agents', default=True,
                help=_("Agent starts with admin_state_up=False when "
                       "enable_new_agents=False. In the case, user's "
                       "resources will not be scheduled automatically to the "
                       "agent until admin changes admin_state_up to True.")),
]
cfg.CONF.register_opts(AGENT_OPTS)

# this is the ratio from agent_down_time to the time we use to consider
# the agents down for considering their resource versions in the
# version_manager callback
DOWNTIME_VERSIONS_RATIO = 2


_deprecate._moved_global('Agent', new_module=agent_model)


class AgentAvailabilityZoneMixin(az_ext.AvailabilityZonePluginBase):
    """Mixin class to add availability_zone extension to AgentDbMixin."""

    def _list_availability_zones(self, context, filters=None):
        result = {}
        query = self._get_collection_query(context, agent_model.Agent,
                                           filters=filters)
        columns = (agent_model.Agent.admin_state_up,
                   agent_model.Agent.availability_zone,
                   agent_model.Agent.agent_type)
        for agent in query.with_entities(*columns).group_by(*columns):
            if not agent.availability_zone:
                continue
Beispiel #40
0
from neutron.api.v2 import attributes
from neutron.callbacks import events
from neutron.callbacks import exceptions
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import _deprecate
from neutron.common import constants as n_const
from neutron.common import utils
from neutron.db import _utils as db_utils
from neutron.db import api as db_api
from neutron.db import db_base_plugin_v2
from neutron.db.models import securitygroup as sg_models
from neutron.extensions import securitygroup as ext_sg


_deprecate._moved_global('DefaultSecurityGroup', new_module=sg_models)
_deprecate._moved_global('SecurityGroupPortBinding', new_module=sg_models)
_deprecate._moved_global('SecurityGroupRule', new_module=sg_models)


class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
    """Mixin class to add security group to db_base_plugin_v2."""

    __native_bulk_support = True

    def create_security_group_bulk(self, context, security_groups):
        return self._create_bulk('security_group', context,
                                 security_groups)

    def _registry_notify(self, res, event, id=None, exc_cls=None, **kwargs):
        # NOTE(armax): a callback exception here will prevent the request
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.db import api as db_api

from neutron.common import _deprecate
from neutron.db.models import provisioning_block as pb_model
from neutron.db import models_v2

LOG = logging.getLogger(__name__)
PROVISIONING_COMPLETE = 'provisioning_complete'
# identifiers for the various entities that participate in provisioning
DHCP_ENTITY = 'DHCP'
L2_AGENT_ENTITY = 'L2'
_RESOURCE_TO_MODEL_MAP = {resources.PORT: models_v2.Port}

_deprecate._moved_global('ProvisioningBlock', new_module=pb_model)


def add_model_for_resource(resource, model):
    """Adds a mapping between a callback resource and a DB model."""
    _RESOURCE_TO_MODEL_MAP[resource] = model


@db_api.retry_if_session_inactive()
def add_provisioning_component(context, object_id, object_type, entity):
    """Adds a provisioning block by an entity to a given object.

    Adds a provisioning block to the DB for object_id with an identifier
    of the entity that is doing the provisioning. While an object has these
    provisioning blocks present, this module will not emit any callback events
    indicating that provisioning has completed. Any logic that depends on
Beispiel #42
0
from neutron.plugins.ml2.drivers import type_tunnel

LOG = log.getLogger(__name__)

gre_opts = [
    cfg.ListOpt('tunnel_id_ranges',
                default=[],
                help=_("Comma-separated list of <tun_min>:<tun_max> tuples "
                       "enumerating ranges of GRE tunnel IDs that are "
                       "available for tenant network allocation"))
]

cfg.CONF.register_opts(gre_opts, "ml2_type_gre")


_deprecate._moved_global('GreAllocation', new_module=gre_model)
_deprecate._moved_global('GreEndpoints', new_module=gre_model)


class GreTypeDriver(type_tunnel.EndpointTunnelTypeDriver):

    def __init__(self):
        super(GreTypeDriver, self).__init__(
            gre_model.GreAllocation, gre_model.GreEndpoints)

    def get_type(self):
        return p_const.TYPE_GRE

    def initialize(self):
        try:
            self._initialize(cfg.CONF.ml2_type_gre.tunnel_id_ranges)
Beispiel #43
0
from oslo_log import log
from six import moves

from neutron._i18n import _, _LE, _LI, _LW
from neutron.common import _deprecate
from neutron.conf.plugins.ml2.drivers import driver_type
from neutron.db import api as db_api
from neutron.db.models.plugins.ml2 import vlanallocation as vlan_alloc_model
from neutron.plugins.common import constants as p_const
from neutron.plugins.common import utils as plugin_utils
from neutron.plugins.ml2 import driver_api as api
from neutron.plugins.ml2.drivers import helpers

LOG = log.getLogger(__name__)

_deprecate._moved_global('VlanAllocation', new_module=vlan_alloc_model)

driver_type.register_ml2_drivers_vlan_opts()


class VlanTypeDriver(helpers.SegmentTypeDriver):
    """Manage state for VLAN networks with ML2.

    The VlanTypeDriver implements the 'vlan' network_type. VLAN
    network segments provide connectivity between VMs and other
    devices using any connected IEEE 802.1Q conformant
    physical_network segmented into virtual networks via IEEE 802.1Q
    headers. Up to 4094 VLAN network segments can exist on each
    available physical_network.
    """
Beispiel #44
0
                      'Example: dhcp_load_type=networks')),
    cfg.BoolOpt('enable_new_agents',
                default=True,
                help=_("Agent starts with admin_state_up=False when "
                       "enable_new_agents=False. In the case, user's "
                       "resources will not be scheduled automatically to the "
                       "agent until admin changes admin_state_up to True.")),
]
cfg.CONF.register_opts(AGENT_OPTS)

# this is the ratio from agent_down_time to the time we use to consider
# the agents down for considering their resource versions in the
# version_manager callback
DOWNTIME_VERSIONS_RATIO = 2

_deprecate._moved_global('Agent', new_module=agent_model)


class AgentAvailabilityZoneMixin(az_ext.AvailabilityZonePluginBase):
    """Mixin class to add availability_zone extension to AgentDbMixin."""
    def _list_availability_zones(self, context, filters=None):
        result = {}
        query = self._get_collection_query(context,
                                           agent_model.Agent,
                                           filters=filters)
        columns = (agent_model.Agent.admin_state_up,
                   agent_model.Agent.availability_zone,
                   agent_model.Agent.agent_type)
        for agent in query.with_entities(*columns).group_by(*columns):
            if not agent.availability_zone:
                continue
Beispiel #45
0
import netaddr
from oslo_config import cfg
from oslo_log import log as logging

from neutron._i18n import _
from neutron.common import _deprecate
from neutron.common import utils
from neutron.db import db_base_plugin_v2
from neutron.db import l3_db
from neutron.db.models import l3 as l3_models
from neutron.db import models_v2
from neutron.extensions import extraroute
from neutron.extensions import l3

_deprecate._moved_global('RouterRoute', new_module=l3_models)

LOG = logging.getLogger(__name__)

extra_route_opts = [
    #TODO(nati): use quota framework when it support quota for attributes
    cfg.IntOpt('max_routes',
               default=30,
               help=_("Maximum number of routes per router")),
]

cfg.CONF.register_opts(extra_route_opts)


class ExtraRoute_dbonly_mixin(l3_db.L3_NAT_dbonly_mixin):
    """Mixin class to support extra route configuration on router."""
Beispiel #46
0
from neutron.db import api as db_api
from neutron.db.availability_zone import router as router_az_db
from neutron.db import l3_dvr_db
from neutron.db.l3_dvr_db import is_distributed_router
from neutron.db.models import agent as agent_model
from neutron.db.models import l3 as l3_models
from neutron.db.models import l3_attrs
from neutron.db.models import l3ha as l3ha_model
from neutron.extensions import l3
from neutron.extensions import l3_ext_ha_mode as l3_ha
from neutron.extensions import portbindings
from neutron.extensions import providernet
from neutron.plugins.common import utils as p_utils


_deprecate._moved_global('L3HARouterAgentPortBinding', new_module=l3ha_model)
_deprecate._moved_global('L3HARouterNetwork', new_module=l3ha_model)
_deprecate._moved_global('L3HARouterVRIdAllocation', new_module=l3ha_model)

VR_ID_RANGE = set(range(1, 255))
MAX_ALLOCATION_TRIES = 10
UNLIMITED_AGENTS_PER_ROUTER = 0

LOG = logging.getLogger(__name__)

L3_HA_OPTS = [
    cfg.BoolOpt('l3_ha',
                default=False,
                help=_('Enable HA mode for virtual routers.')),
    cfg.IntOpt('max_l3_agents_per_router',
               default=3,
Beispiel #47
0
#    under the License.

from oslo_db import exception as db_exc
from oslo_log import log as logging
from oslo_utils import uuidutils
from sqlalchemy.orm import exc as sa_exc

from neutron.common import _deprecate
from neutron.db import _utils as db_utils
from neutron.db import api as db_api
from neutron.db import common_db_mixin
from neutron.db.models import flavor as flavor_models
from neutron.db import servicetype_db as sdb
from neutron.extensions import flavors as ext_flavors

_deprecate._moved_global("Flavor", new_module=flavor_models)
_deprecate._moved_global("ServiceProfile", new_module=flavor_models)
_deprecate._moved_global("FlavorServiceProfileBinding", new_module=flavor_models)


LOG = logging.getLogger(__name__)


class FlavorsDbMixin(common_db_mixin.CommonDbMixin):

    """Class to support flavors and service profiles."""

    def _get_flavor(self, context, flavor_id):
        try:
            return self._get_by_id(context, flavor_models.Flavor, flavor_id)
        except sa_exc.NoResultFound:
Beispiel #48
0
#    License for the specific language governing permissions and limitations
#    under the License.

from oslo_db import exception as db_exc
from oslo_log import log as logging
from oslo_utils import uuidutils
from sqlalchemy.orm import exc as sa_exc

from neutron.common import _deprecate
from neutron.db import _utils as db_utils
from neutron.db import common_db_mixin
from neutron.db.models import flavor as flavor_models
from neutron.db import servicetype_db as sdb
from neutron.extensions import flavors as ext_flavors

_deprecate._moved_global('Flavor', new_module=flavor_models)
_deprecate._moved_global('ServiceProfile', new_module=flavor_models)
_deprecate._moved_global('FlavorServiceProfileBinding',
                         new_module=flavor_models)

LOG = logging.getLogger(__name__)


class FlavorsDbMixin(common_db_mixin.CommonDbMixin):
    """Class to support flavors and service profiles."""
    def _get_flavor(self, context, flavor_id):
        try:
            return self._get_by_id(context, flavor_models.Flavor, flavor_id)
        except sa_exc.NoResultFound:
            raise ext_flavors.FlavorNotFound(flavor_id=flavor_id)
Beispiel #49
0
# under the License.

import netaddr
from oslo_utils import uuidutils
from sqlalchemy import orm

from neutron.api.rpc.agentnotifiers import metering_rpc_agent_api
from neutron.common import _deprecate
from neutron.common import constants
from neutron.db import common_db_mixin as base_db
from neutron.db.models import l3 as l3_models
from neutron.db.models import metering as metering_models
from neutron.extensions import metering


_deprecate._moved_global('MeteringLabelRule', new_module=metering_models)
_deprecate._moved_global('MeteringLabel', new_module=metering_models)


class MeteringDbMixin(metering.MeteringPluginBase,
                      base_db.CommonDbMixin):

    def __init__(self):
        self.meter_rpc = metering_rpc_agent_api.MeteringAgentNotifyAPI()

    def _make_metering_label_dict(self, metering_label, fields=None):
        res = {'id': metering_label['id'],
               'name': metering_label['name'],
               'description': metering_label['description'],
               'shared': metering_label['shared'],
               'tenant_id': metering_label['tenant_id']}
Beispiel #50
0
from oslo_utils import uuidutils
from sqlalchemy.orm import exc

from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import _deprecate
from neutron.db import api as db_api
from neutron.db import common_db_mixin
from neutron.db.models import segment as segment_model
from neutron.db import segments_db as db
from neutron.extensions import segment as extension
from neutron import manager
from neutron.services.segments import exceptions

_deprecate._moved_global('SegmentHostMapping', new_module=segment_model)


class SegmentDbMixin(common_db_mixin.CommonDbMixin):
    """Mixin class to add segment."""
    def _make_segment_dict(self, segment_db, fields=None):
        res = {
            'id': segment_db['id'],
            'network_id': segment_db['network_id'],
            'name': segment_db['name'],
            'description': segment_db['description'],
            db.PHYSICAL_NETWORK: segment_db[db.PHYSICAL_NETWORK],
            db.NETWORK_TYPE: segment_db[db.NETWORK_TYPE],
            db.SEGMENTATION_ID: segment_db[db.SEGMENTATION_ID],
            'hosts':
            [mapping.host for mapping in segment_db.segment_host_mapping],
Beispiel #51
0
from sqlalchemy.orm import joinedload
from sqlalchemy import sql

from neutron._i18n import _, _LI
from neutron.agent.common import utils as agent_utils
from neutron.common import _deprecate
from neutron.common import utils as n_utils
from neutron.db import agentschedulers_db
from neutron.db.models import agent as agent_model
from neutron.db.models import l3_attrs
from neutron.db.models import l3agent as rb_model
from neutron.extensions import l3agentscheduler
from neutron.extensions import router_availability_zone as router_az


_deprecate._moved_global('RouterL3AgentBinding',
                         new_module=rb_model)

LOG = logging.getLogger(__name__)


L3_AGENTS_SCHEDULER_OPTS = [
    cfg.StrOpt('router_scheduler_driver',
               default='neutron.scheduler.l3_agent_scheduler.'
                       'LeastRoutersScheduler',
               help=_('Driver to use for scheduling '
                      'router to a default L3 agent')),
    cfg.BoolOpt('router_auto_schedule', default=True,
                help=_('Allow auto scheduling of routers to L3 agent.')),
    cfg.BoolOpt('allow_automatic_l3agent_failover', default=False,
                help=_('Automatically reschedule routers from offline L3 '
                       'agents to online L3 agents.')),
Beispiel #52
0
from neutron.api.v2 import attributes
from neutron.callbacks import events
from neutron.callbacks import exceptions
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import _deprecate
from neutron.common import constants as n_const
from neutron.common import utils
from neutron.db import _utils as db_utils
from neutron.db import api as db_api
from neutron.db import db_base_plugin_v2
from neutron.db.models import securitygroup as sg_models
from neutron.extensions import securitygroup as ext_sg


_deprecate._moved_global('DefaultSecurityGroup', new_module=sg_models)
_deprecate._moved_global('SecurityGroupPortBinding', new_module=sg_models)
_deprecate._moved_global('SecurityGroupRule', new_module=sg_models)


class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
    """Mixin class to add security group to db_base_plugin_v2."""

    __native_bulk_support = True

    def create_security_group_bulk(self, context, security_group_rule):
        return self._create_bulk('security_group', context,
                                 security_group_rule)

    def _registry_notify(self, res, event, id=None, exc_cls=None, **kwargs):
        # NOTE(armax): a callback exception here will prevent the request
Beispiel #53
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 oslo_config import cfg

from neutron._i18n import _
from neutron.common import _deprecate
from neutron.db import db_base_plugin_v2
from neutron.db.models import l3_attrs
from neutron.extensions import availability_zone as az
from neutron.extensions import l3

_deprecate._moved_global('RouterExtraAttributes', new_module=l3_attrs)


def get_attr_info():
    """Returns api visible attr names and their default values."""
    return {
        'distributed': {
            'default': cfg.CONF.router_distributed
        },
        'ha': {
            'default': cfg.CONF.l3_ha
        },
        'ha_vr_id': {
            'default': 0
        },
        'availability_zone_hints': {