diff --git a/neutron/db/agents_db.py b/neutron/db/agents_db.py deleted file mode 100644 index 57712066a..000000000 --- a/neutron/db/agents_db.py +++ /dev/null @@ -1,219 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation. -# 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. - -from eventlet import greenthread - -from oslo.config import cfg -import sqlalchemy as sa -from sqlalchemy.orm import exc - -from neutron.common import rpc_compat -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.extensions import agent as ext_agent -from neutron import manager -from neutron.openstack.common.db import exception as db_exc -from neutron.openstack.common import excutils -from neutron.openstack.common import jsonutils -from neutron.openstack.common import log as logging -from neutron.openstack.common import timeutils - -LOG = logging.getLogger(__name__) -cfg.CONF.register_opt( - cfg.IntOpt('agent_down_time', default=75, - help=_("Seconds to regard the agent is down; should be at " - "least twice report_interval, to be sure the " - "agent is down for good."))) - - -class Agent(model_base.BASEV2, models_v2.HasId): - """Represents agents running in neutron deployments.""" - - __table_args__ = ( - sa.UniqueConstraint('agent_type', 'host', - name='uniq_agents0agent_type0host'), - ) - - # L3 agent, DHCP agent, OVS agent, LinuxBridge - agent_type = sa.Column(sa.String(255), nullable=False) - binary = sa.Column(sa.String(255), nullable=False) - # TOPIC is a fanout exchange topic - topic = sa.Column(sa.String(255), nullable=False) - # TOPIC.host is a target topic - host = sa.Column(sa.String(255), nullable=False) - admin_state_up = sa.Column(sa.Boolean, default=True, - nullable=False) - # the time when first report came from agents - created_at = sa.Column(sa.DateTime, nullable=False) - # the time when first report came after agents start - started_at = sa.Column(sa.DateTime, nullable=False) - # updated when agents report - heartbeat_timestamp = sa.Column(sa.DateTime, nullable=False) - # description is note for admin user - description = sa.Column(sa.String(255)) - # configurations: a json dict string, I think 4095 is enough - configurations = sa.Column(sa.String(4095), nullable=False) - - @property - def is_active(self): - return not AgentDbMixin.is_agent_down(self.heartbeat_timestamp) - - -class AgentDbMixin(ext_agent.AgentPluginBase): - """Mixin class to add agent extension to db_base_plugin_v2.""" - - def _get_agent(self, context, id): - try: - agent = self._get_by_id(context, Agent, id) - except exc.NoResultFound: - raise ext_agent.AgentNotFound(id=id) - return agent - - @classmethod - def is_agent_down(cls, heart_beat_time): - return timeutils.is_older_than(heart_beat_time, - cfg.CONF.agent_down_time) - - def get_configuration_dict(self, agent_db): - try: - conf = jsonutils.loads(agent_db.configurations) - except Exception: - msg = _('Configuration for agent %(agent_type)s on host %(host)s' - ' is invalid.') - LOG.warn(msg, {'agent_type': agent_db.agent_type, - 'host': agent_db.host}) - conf = {} - return conf - - def _make_agent_dict(self, agent, fields=None): - attr = ext_agent.RESOURCE_ATTRIBUTE_MAP.get( - ext_agent.RESOURCE_NAME + 's') - res = dict((k, agent[k]) for k in attr - if k not in ['alive', 'configurations']) - res['alive'] = not AgentDbMixin.is_agent_down( - res['heartbeat_timestamp']) - res['configurations'] = self.get_configuration_dict(agent) - return self._fields(res, fields) - - def delete_agent(self, context, id): - with context.session.begin(subtransactions=True): - agent = self._get_agent(context, id) - context.session.delete(agent) - - def update_agent(self, context, id, agent): - agent_data = agent['agent'] - with context.session.begin(subtransactions=True): - agent = self._get_agent(context, id) - agent.update(agent_data) - return self._make_agent_dict(agent) - - def get_agents_db(self, context, filters=None): - query = self._get_collection_query(context, Agent, filters=filters) - return query.all() - - def get_agents(self, context, filters=None, fields=None): - return self._get_collection(context, Agent, - self._make_agent_dict, - filters=filters, fields=fields) - - def _get_agent_by_type_and_host(self, context, agent_type, host): - query = self._model_query(context, Agent) - try: - agent_db = query.filter(Agent.agent_type == agent_type, - Agent.host == host).one() - return agent_db - except exc.NoResultFound: - raise ext_agent.AgentNotFoundByTypeHost(agent_type=agent_type, - host=host) - except exc.MultipleResultsFound: - raise ext_agent.MultipleAgentFoundByTypeHost(agent_type=agent_type, - host=host) - - def get_agent(self, context, id, fields=None): - agent = self._get_agent(context, id) - return self._make_agent_dict(agent, fields) - - def _create_or_update_agent(self, context, agent): - with context.session.begin(subtransactions=True): - res_keys = ['agent_type', 'binary', 'host', 'topic'] - res = dict((k, agent[k]) for k in res_keys) - - configurations_dict = agent.get('configurations', {}) - res['configurations'] = jsonutils.dumps(configurations_dict) - current_time = timeutils.utcnow() - try: - agent_db = self._get_agent_by_type_and_host( - context, agent['agent_type'], agent['host']) - res['heartbeat_timestamp'] = current_time - if agent.get('start_flag'): - res['started_at'] = current_time - greenthread.sleep(0) - agent_db.update(res) - except ext_agent.AgentNotFoundByTypeHost: - greenthread.sleep(0) - res['created_at'] = current_time - res['started_at'] = current_time - res['heartbeat_timestamp'] = current_time - res['admin_state_up'] = True - agent_db = Agent(**res) - greenthread.sleep(0) - context.session.add(agent_db) - greenthread.sleep(0) - - def create_or_update_agent(self, context, agent): - """Create or update agent according to report.""" - - try: - return self._create_or_update_agent(context, agent) - except db_exc.DBDuplicateEntry as e: - with excutils.save_and_reraise_exception() as ctxt: - if e.columns == ['agent_type', 'host']: - # It might happen that two or more concurrent transactions - # are trying to insert new rows having the same value of - # (agent_type, host) pair at the same time (if there has - # been no such entry in the table and multiple agent status - # updates are being processed at the moment). In this case - # having a unique constraint on (agent_type, host) columns - # guarantees that only one transaction will succeed and - # insert a new agent entry, others will fail and be rolled - # back. That means we must retry them one more time: no - # INSERTs will be issued, because - # _get_agent_by_type_and_host() will return the existing - # agent entry, which will be updated multiple times - ctxt.reraise = False - return self._create_or_update_agent(context, agent) - - -class AgentExtRpcCallback(rpc_compat.RpcCallback): - """Processes the rpc report in plugin implementations.""" - - RPC_API_VERSION = '1.0' - START_TIME = timeutils.utcnow() - - def __init__(self, plugin=None): - super(AgentExtRpcCallback, self).__init__() - self.plugin = plugin - - def report_state(self, context, **kwargs): - """Report state from agent to server.""" - time = kwargs['time'] - time = timeutils.parse_strtime(time) - if self.START_TIME > time: - LOG.debug(_("Message with invalid timestamp received")) - return - agent_state = kwargs['agent_state']['agent_state'] - if not self.plugin: - self.plugin = manager.NeutronManager.get_plugin() - self.plugin.create_or_update_agent(context, agent_state) diff --git a/neutron/db/agentschedulers_db.py b/neutron/db/agentschedulers_db.py deleted file mode 100644 index 2022dbe3e..000000000 --- a/neutron/db/agentschedulers_db.py +++ /dev/null @@ -1,226 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation. -# 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. - -from oslo.config import cfg -import sqlalchemy as sa -from sqlalchemy import orm -from sqlalchemy.orm import exc -from sqlalchemy.orm import joinedload - -from neutron.common import constants -from neutron.common import utils -from neutron.db import agents_db -from neutron.db import model_base -from neutron.extensions import agent as ext_agent -from neutron.extensions import dhcpagentscheduler -from neutron.openstack.common import log as logging - - -LOG = logging.getLogger(__name__) - -AGENTS_SCHEDULER_OPTS = [ - cfg.StrOpt('network_scheduler_driver', - default='neutron.scheduler.' - 'dhcp_agent_scheduler.ChanceScheduler', - help=_('Driver to use for scheduling network to DHCP agent')), - cfg.BoolOpt('network_auto_schedule', default=True, - help=_('Allow auto scheduling networks to DHCP agent.')), - cfg.IntOpt('dhcp_agents_per_network', default=1, - help=_('Number of DHCP agents scheduled to host a network.')), -] - -cfg.CONF.register_opts(AGENTS_SCHEDULER_OPTS) - - -class NetworkDhcpAgentBinding(model_base.BASEV2): - """Represents binding between neutron networks and DHCP agents.""" - - network_id = sa.Column(sa.String(36), - sa.ForeignKey("networks.id", ondelete='CASCADE'), - primary_key=True) - dhcp_agent = orm.relation(agents_db.Agent) - dhcp_agent_id = sa.Column(sa.String(36), - sa.ForeignKey("agents.id", - ondelete='CASCADE'), - primary_key=True) - - -class AgentSchedulerDbMixin(agents_db.AgentDbMixin): - """Common class for agent scheduler mixins.""" - - # agent notifiers to handle agent update operations; - # should be updated by plugins; - agent_notifiers = { - constants.AGENT_TYPE_DHCP: None, - constants.AGENT_TYPE_L3: None, - constants.AGENT_TYPE_LOADBALANCER: None, - } - - @staticmethod - def is_eligible_agent(active, agent): - if active is None: - # filtering by activeness is disabled, all agents are eligible - return True - else: - # note(rpodolyaka): original behaviour is saved here: if active - # filter is set, only agents which are 'up' - # (i.e. have a recent heartbeat timestamp) - # are eligible, even if active is False - return not agents_db.AgentDbMixin.is_agent_down( - agent['heartbeat_timestamp']) - - def update_agent(self, context, id, agent): - original_agent = self.get_agent(context, id) - result = super(AgentSchedulerDbMixin, self).update_agent( - context, id, agent) - agent_data = agent['agent'] - agent_notifier = self.agent_notifiers.get(original_agent['agent_type']) - if (agent_notifier and - 'admin_state_up' in agent_data and - original_agent['admin_state_up'] != agent_data['admin_state_up']): - agent_notifier.agent_updated(context, - agent_data['admin_state_up'], - original_agent['host']) - return result - - -class DhcpAgentSchedulerDbMixin(dhcpagentscheduler - .DhcpAgentSchedulerPluginBase, - AgentSchedulerDbMixin): - """Mixin class to add DHCP agent scheduler extension to db_base_plugin_v2. - """ - - network_scheduler = None - - def get_dhcp_agents_hosting_networks( - self, context, network_ids, active=None): - if not network_ids: - return [] - query = context.session.query(NetworkDhcpAgentBinding) - query = query.options(joinedload('dhcp_agent')) - if len(network_ids) == 1: - query = query.filter( - NetworkDhcpAgentBinding.network_id == network_ids[0]) - elif network_ids: - query = query.filter( - NetworkDhcpAgentBinding.network_id in network_ids) - if active is not None: - query = (query.filter(agents_db.Agent.admin_state_up == active)) - - return [binding.dhcp_agent - for binding in query - if AgentSchedulerDbMixin.is_eligible_agent(active, - binding.dhcp_agent)] - - def add_network_to_dhcp_agent(self, context, id, network_id): - self._get_network(context, network_id) - with context.session.begin(subtransactions=True): - agent_db = self._get_agent(context, id) - if (agent_db['agent_type'] != constants.AGENT_TYPE_DHCP or - not agent_db['admin_state_up']): - raise dhcpagentscheduler.InvalidDHCPAgent(id=id) - dhcp_agents = self.get_dhcp_agents_hosting_networks( - context, [network_id]) - for dhcp_agent in dhcp_agents: - if id == dhcp_agent.id: - raise dhcpagentscheduler.NetworkHostedByDHCPAgent( - network_id=network_id, agent_id=id) - binding = NetworkDhcpAgentBinding() - binding.dhcp_agent_id = id - binding.network_id = network_id - context.session.add(binding) - dhcp_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_DHCP) - if dhcp_notifier: - dhcp_notifier.network_added_to_agent( - context, network_id, agent_db.host) - - def remove_network_from_dhcp_agent(self, context, id, network_id): - agent = self._get_agent(context, id) - with context.session.begin(subtransactions=True): - try: - query = context.session.query(NetworkDhcpAgentBinding) - binding = query.filter( - NetworkDhcpAgentBinding.network_id == network_id, - NetworkDhcpAgentBinding.dhcp_agent_id == id).one() - except exc.NoResultFound: - raise dhcpagentscheduler.NetworkNotHostedByDhcpAgent( - network_id=network_id, agent_id=id) - - # reserve the port, so the ip is reused on a subsequent add - device_id = utils.get_dhcp_agent_device_id(network_id, - agent['host']) - filters = dict(device_id=[device_id]) - ports = self.get_ports(context, filters=filters) - for port in ports: - port['device_id'] = constants.DEVICE_ID_RESERVED_DHCP_PORT - self.update_port(context, port['id'], dict(port=port)) - - context.session.delete(binding) - dhcp_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_DHCP) - if dhcp_notifier: - dhcp_notifier.network_removed_from_agent( - context, network_id, agent.host) - - def list_networks_on_dhcp_agent(self, context, id): - query = context.session.query(NetworkDhcpAgentBinding.network_id) - query = query.filter(NetworkDhcpAgentBinding.dhcp_agent_id == id) - - net_ids = [item[0] for item in query] - if net_ids: - return {'networks': - self.get_networks(context, filters={'id': net_ids})} - else: - return {'networks': []} - - def list_active_networks_on_active_dhcp_agent(self, context, host): - try: - agent = self._get_agent_by_type_and_host( - context, constants.AGENT_TYPE_DHCP, host) - except ext_agent.AgentNotFoundByTypeHost: - LOG.debug("DHCP Agent not found on host %s", host) - return [] - - if not agent.admin_state_up: - return [] - query = context.session.query(NetworkDhcpAgentBinding.network_id) - query = query.filter(NetworkDhcpAgentBinding.dhcp_agent_id == agent.id) - - net_ids = [item[0] for item in query] - if net_ids: - return self.get_networks( - context, - filters={'id': net_ids, 'admin_state_up': [True]} - ) - else: - return [] - - def list_dhcp_agents_hosting_network(self, context, network_id): - dhcp_agents = self.get_dhcp_agents_hosting_networks( - context, [network_id]) - agent_ids = [dhcp_agent.id for dhcp_agent in dhcp_agents] - if agent_ids: - return { - 'agents': self.get_agents(context, filters={'id': agent_ids})} - else: - return {'agents': []} - - def schedule_network(self, context, created_network): - if self.network_scheduler: - return self.network_scheduler.schedule( - self, context, created_network) - - def auto_schedule_networks(self, context, host): - if self.network_scheduler: - self.network_scheduler.auto_schedule_networks(self, context, host) diff --git a/neutron/db/allowedaddresspairs_db.py b/neutron/db/allowedaddresspairs_db.py deleted file mode 100644 index b648c8c47..000000000 --- a/neutron/db/allowedaddresspairs_db.py +++ /dev/null @@ -1,147 +0,0 @@ -# Copyright 2013 VMware, 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. -# - -import sqlalchemy as sa -from sqlalchemy import orm - -from neutron.api.v2 import attributes as attr -from neutron.db import db_base_plugin_v2 -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.extensions import allowedaddresspairs as addr_pair - - -class AllowedAddressPair(model_base.BASEV2): - port_id = sa.Column(sa.String(36), - sa.ForeignKey('ports.id', ondelete="CASCADE"), - primary_key=True) - mac_address = sa.Column(sa.String(32), nullable=False, primary_key=True) - ip_address = sa.Column(sa.String(64), nullable=False, primary_key=True) - - port = orm.relationship( - models_v2.Port, - backref=orm.backref("allowed_address_pairs", - lazy="joined", cascade="delete")) - - -class AllowedAddressPairsMixin(object): - """Mixin class for allowed address pairs.""" - - def _process_create_allowed_address_pairs(self, context, port, - allowed_address_pairs): - if not attr.is_attr_set(allowed_address_pairs): - return [] - with context.session.begin(subtransactions=True): - for address_pair in allowed_address_pairs: - # use port.mac_address if no mac address in address pair - if 'mac_address' not in address_pair: - address_pair['mac_address'] = port['mac_address'] - db_pair = AllowedAddressPair( - port_id=port['id'], - mac_address=address_pair['mac_address'], - ip_address=address_pair['ip_address']) - context.session.add(db_pair) - - return allowed_address_pairs - - def get_allowed_address_pairs(self, context, port_id): - pairs = (context.session.query(AllowedAddressPair). - filter_by(port_id=port_id)) - return [self._make_allowed_address_pairs_dict(pair) - for pair in pairs] - - def _extend_port_dict_allowed_address_pairs(self, port_res, port_db): - # If port_db is provided, allowed address pairs will be accessed via - # sqlalchemy models. As they're loaded together with ports this - # will not cause an extra query. - allowed_address_pairs = [ - self._make_allowed_address_pairs_dict(address_pair) for - address_pair in port_db.allowed_address_pairs] - port_res[addr_pair.ADDRESS_PAIRS] = allowed_address_pairs - return port_res - - # Register dict extend functions for ports - db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attr.PORTS, ['_extend_port_dict_allowed_address_pairs']) - - def _delete_allowed_address_pairs(self, context, id): - query = self._model_query(context, AllowedAddressPair) - with context.session.begin(subtransactions=True): - query.filter(AllowedAddressPair.port_id == id).delete() - - def _make_allowed_address_pairs_dict(self, allowed_address_pairs, - fields=None): - res = {'mac_address': allowed_address_pairs['mac_address'], - 'ip_address': allowed_address_pairs['ip_address']} - return self._fields(res, fields) - - def _has_address_pairs(self, port): - return (attr.is_attr_set(port['port'][addr_pair.ADDRESS_PAIRS]) - and port['port'][addr_pair.ADDRESS_PAIRS] != []) - - def _check_update_has_allowed_address_pairs(self, port): - """Determine if request has an allowed address pair. - - Return True if the port parameter has a non-empty - 'allowed_address_pairs' attribute. Otherwise returns False. - """ - return (addr_pair.ADDRESS_PAIRS in port['port'] and - self._has_address_pairs(port)) - - def _check_update_deletes_allowed_address_pairs(self, port): - """Determine if request deletes address pair. - - Return True if port has as a allowed address pair and its value - is either [] or not is_attr_set, otherwise return False - """ - return (addr_pair.ADDRESS_PAIRS in port['port'] and - not self._has_address_pairs(port)) - - def is_address_pairs_attribute_updated(self, port, update_attrs): - """Check if the address pairs attribute is being updated. - - Returns True if there is an update. This can be used to decide - if a port update notification should be sent to agents or third - party controllers. - """ - - new_pairs = update_attrs.get(addr_pair.ADDRESS_PAIRS) - if new_pairs is None: - return False - old_pairs = port.get(addr_pair.ADDRESS_PAIRS) - - # Missing or unchanged address pairs in attributes mean no update - return new_pairs != old_pairs - - def update_address_pairs_on_port(self, context, port_id, port, - original_port, updated_port): - """Update allowed address pairs on port. - - Returns True if an update notification is required. Notification - is not done here because other changes on the port may need - notification. This method is expected to be called within - a transaction. - """ - new_pairs = port['port'].get(addr_pair.ADDRESS_PAIRS) - - if self.is_address_pairs_attribute_updated(original_port, - port['port']): - updated_port[addr_pair.ADDRESS_PAIRS] = new_pairs - self._delete_allowed_address_pairs(context, port_id) - self._process_create_allowed_address_pairs( - context, updated_port, new_pairs) - return True - - return False diff --git a/neutron/db/dhcp_rpc_base.py b/neutron/db/dhcp_rpc_base.py deleted file mode 100644 index e42099c63..000000000 --- a/neutron/db/dhcp_rpc_base.py +++ /dev/null @@ -1,287 +0,0 @@ -# Copyright (c) 2012 OpenStack Foundation. -# -# 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 oslo.config import cfg - -from neutron.api.v2 import attributes -from neutron.common import constants -from neutron.common import exceptions as n_exc -from neutron.common import utils -from neutron.extensions import portbindings -from neutron import manager -from neutron.openstack.common.db import exception as db_exc -from neutron.openstack.common import excutils -from neutron.openstack.common import log as logging - - -LOG = logging.getLogger(__name__) - - -class DhcpRpcCallbackMixin(object): - """A mix-in that enable DHCP agent support in plugin implementations.""" - - def _get_active_networks(self, context, **kwargs): - """Retrieve and return a list of the active networks.""" - host = kwargs.get('host') - plugin = manager.NeutronManager.get_plugin() - if utils.is_extension_supported( - plugin, constants.DHCP_AGENT_SCHEDULER_EXT_ALIAS): - if cfg.CONF.network_auto_schedule: - plugin.auto_schedule_networks(context, host) - nets = plugin.list_active_networks_on_active_dhcp_agent( - context, host) - else: - filters = dict(admin_state_up=[True]) - nets = plugin.get_networks(context, filters=filters) - return nets - - def _port_action(self, plugin, context, port, action): - """Perform port operations taking care of concurrency issues.""" - try: - if action == 'create_port': - return plugin.create_port(context, port) - elif action == 'update_port': - return plugin.update_port(context, port['id'], port['port']) - else: - msg = _('Unrecognized action') - raise n_exc.Invalid(message=msg) - except (db_exc.DBError, n_exc.NetworkNotFound, - n_exc.SubnetNotFound, n_exc.IpAddressGenerationFailure) as e: - with excutils.save_and_reraise_exception(reraise=False) as ctxt: - if isinstance(e, n_exc.IpAddressGenerationFailure): - # Check if the subnet still exists and if it does not, - # this is the reason why the ip address generation failed. - # In any other unlikely event re-raise - try: - subnet_id = port['port']['fixed_ips'][0]['subnet_id'] - plugin.get_subnet(context, subnet_id) - except n_exc.SubnetNotFound: - pass - else: - ctxt.reraise = True - net_id = port['port']['network_id'] - LOG.warn(_("Action %(action)s for network %(net_id)s " - "could not complete successfully: %(reason)s") - % {"action": action, "net_id": net_id, 'reason': e}) - - def get_active_networks(self, context, **kwargs): - """Retrieve and return a list of the active network ids.""" - # NOTE(arosen): This method is no longer used by the DHCP agent but is - # left so that neutron-dhcp-agents will still continue to work if - # neutron-server is upgraded and not the agent. - host = kwargs.get('host') - LOG.debug(_('get_active_networks requested from %s'), host) - nets = self._get_active_networks(context, **kwargs) - return [net['id'] for net in nets] - - def get_active_networks_info(self, context, **kwargs): - """Returns all the networks/subnets/ports in system.""" - host = kwargs.get('host') - LOG.debug(_('get_active_networks_info from %s'), host) - networks = self._get_active_networks(context, **kwargs) - plugin = manager.NeutronManager.get_plugin() - filters = {'network_id': [network['id'] for network in networks]} - ports = plugin.get_ports(context, filters=filters) - filters['enable_dhcp'] = [True] - subnets = plugin.get_subnets(context, filters=filters) - - for network in networks: - network['subnets'] = [subnet for subnet in subnets - if subnet['network_id'] == network['id']] - network['ports'] = [port for port in ports - if port['network_id'] == network['id']] - - return networks - - def get_network_info(self, context, **kwargs): - """Retrieve and return a extended information about a network.""" - network_id = kwargs.get('network_id') - host = kwargs.get('host') - LOG.debug(_('Network %(network_id)s requested from ' - '%(host)s'), {'network_id': network_id, - 'host': host}) - plugin = manager.NeutronManager.get_plugin() - try: - network = plugin.get_network(context, network_id) - except n_exc.NetworkNotFound: - LOG.warn(_("Network %s could not be found, it might have " - "been deleted concurrently."), network_id) - return - filters = dict(network_id=[network_id]) - network['subnets'] = plugin.get_subnets(context, filters=filters) - network['ports'] = plugin.get_ports(context, filters=filters) - return network - - def get_dhcp_port(self, context, **kwargs): - """Allocate a DHCP port for the host and return port information. - - This method will re-use an existing port if one already exists. When a - port is re-used, the fixed_ip allocation will be updated to the current - network state. If an expected failure occurs, a None port is returned. - - """ - host = kwargs.get('host') - network_id = kwargs.get('network_id') - device_id = kwargs.get('device_id') - # There could be more than one dhcp server per network, so create - # a device id that combines host and network ids - - LOG.debug(_('Port %(device_id)s for %(network_id)s requested from ' - '%(host)s'), {'device_id': device_id, - 'network_id': network_id, - 'host': host}) - plugin = manager.NeutronManager.get_plugin() - retval = None - - filters = dict(network_id=[network_id]) - subnets = dict([(s['id'], s) for s in - plugin.get_subnets(context, filters=filters)]) - - dhcp_enabled_subnet_ids = [s['id'] for s in - subnets.values() if s['enable_dhcp']] - - try: - filters = dict(network_id=[network_id], device_id=[device_id]) - ports = plugin.get_ports(context, filters=filters) - if ports: - # Ensure that fixed_ips cover all dhcp_enabled subnets. - port = ports[0] - for fixed_ip in port['fixed_ips']: - if fixed_ip['subnet_id'] in dhcp_enabled_subnet_ids: - dhcp_enabled_subnet_ids.remove(fixed_ip['subnet_id']) - port['fixed_ips'].extend( - [dict(subnet_id=s) for s in dhcp_enabled_subnet_ids]) - - retval = plugin.update_port(context, port['id'], - dict(port=port)) - - except n_exc.NotFound as e: - LOG.warning(e) - - if retval is None: - # No previous port exists, so create a new one. - LOG.debug(_('DHCP port %(device_id)s on network %(network_id)s ' - 'does not exist on %(host)s'), - {'device_id': device_id, - 'network_id': network_id, - 'host': host}) - try: - network = plugin.get_network(context, network_id) - except n_exc.NetworkNotFound: - LOG.warn(_("Network %s could not be found, it might have " - "been deleted concurrently."), network_id) - return - - port_dict = dict( - admin_state_up=True, - device_id=device_id, - network_id=network_id, - tenant_id=network['tenant_id'], - mac_address=attributes.ATTR_NOT_SPECIFIED, - name='', - device_owner=constants.DEVICE_OWNER_DHCP, - fixed_ips=[dict(subnet_id=s) for s in dhcp_enabled_subnet_ids]) - - retval = self._port_action(plugin, context, {'port': port_dict}, - 'create_port') - if not retval: - return - - # Convert subnet_id to subnet dict - for fixed_ip in retval['fixed_ips']: - subnet_id = fixed_ip.pop('subnet_id') - fixed_ip['subnet'] = subnets[subnet_id] - - return retval - - def release_dhcp_port(self, context, **kwargs): - """Release the port currently being used by a DHCP agent.""" - host = kwargs.get('host') - network_id = kwargs.get('network_id') - device_id = kwargs.get('device_id') - - LOG.debug(_('DHCP port deletion for %(network_id)s request from ' - '%(host)s'), - {'network_id': network_id, 'host': host}) - plugin = manager.NeutronManager.get_plugin() - plugin.delete_ports_by_device_id(context, device_id, network_id) - - def release_port_fixed_ip(self, context, **kwargs): - """Release the fixed_ip associated the subnet on a port.""" - host = kwargs.get('host') - network_id = kwargs.get('network_id') - device_id = kwargs.get('device_id') - subnet_id = kwargs.get('subnet_id') - - LOG.debug(_('DHCP port remove fixed_ip for %(subnet_id)s request ' - 'from %(host)s'), - {'subnet_id': subnet_id, 'host': host}) - plugin = manager.NeutronManager.get_plugin() - filters = dict(network_id=[network_id], device_id=[device_id]) - ports = plugin.get_ports(context, filters=filters) - - if ports: - port = ports[0] - - fixed_ips = port.get('fixed_ips', []) - for i in range(len(fixed_ips)): - if fixed_ips[i]['subnet_id'] == subnet_id: - del fixed_ips[i] - break - plugin.update_port(context, port['id'], dict(port=port)) - - def update_lease_expiration(self, context, **kwargs): - """Release the fixed_ip associated the subnet on a port.""" - # NOTE(arosen): This method is no longer used by the DHCP agent but is - # left so that neutron-dhcp-agents will still continue to work if - # neutron-server is upgraded and not the agent. - host = kwargs.get('host') - - LOG.warning(_('Updating lease expiration is now deprecated. Issued ' - 'from host %s.'), host) - - def create_dhcp_port(self, context, **kwargs): - """Create and return dhcp port information. - - If an expected failure occurs, a None port is returned. - - """ - host = kwargs.get('host') - port = kwargs.get('port') - LOG.debug(_('Create dhcp port %(port)s ' - 'from %(host)s.'), - {'port': port, - 'host': host}) - - port['port']['device_owner'] = constants.DEVICE_OWNER_DHCP - port['port'][portbindings.HOST_ID] = host - if 'mac_address' not in port['port']: - port['port']['mac_address'] = attributes.ATTR_NOT_SPECIFIED - plugin = manager.NeutronManager.get_plugin() - return self._port_action(plugin, context, port, 'create_port') - - def update_dhcp_port(self, context, **kwargs): - """Update the dhcp port.""" - host = kwargs.get('host') - port_id = kwargs.get('port_id') - port = kwargs.get('port') - LOG.debug(_('Update dhcp port %(port)s ' - 'from %(host)s.'), - {'port': port, - 'host': host}) - plugin = manager.NeutronManager.get_plugin() - return self._port_action(plugin, context, - {'id': port_id, 'port': port}, - 'update_port') diff --git a/neutron/db/external_net_db.py b/neutron/db/external_net_db.py deleted file mode 100644 index 53f389536..000000000 --- a/neutron/db/external_net_db.py +++ /dev/null @@ -1,163 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation. -# 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. - -import sqlalchemy as sa -from sqlalchemy import orm -from sqlalchemy.orm import exc -from sqlalchemy.sql import expression as expr - -from neutron.api.v2 import attributes -from neutron.common import constants as l3_constants -from neutron.common import exceptions as n_exc -from neutron.db import db_base_plugin_v2 -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.extensions import external_net -from neutron import manager -from neutron.plugins.common import constants as service_constants - - -DEVICE_OWNER_ROUTER_GW = l3_constants.DEVICE_OWNER_ROUTER_GW - - -class ExternalNetwork(model_base.BASEV2): - network_id = sa.Column(sa.String(36), - sa.ForeignKey('networks.id', ondelete="CASCADE"), - primary_key=True) - - # Add a relationship to the Network model in order to instruct - # SQLAlchemy to eagerly load this association - network = orm.relationship( - models_v2.Network, - backref=orm.backref("external", lazy='joined', - uselist=False, cascade='delete')) - - -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(ExternalNetwork, - (original_model.id == - ExternalNetwork.network_id)) - return query - - def _network_filter_hook(self, context, original_model, conditions): - if conditions is not None and not hasattr(conditions, '__iter__'): - conditions = (conditions, ) - # Apply the external network filter only in non-admin context - if not context.is_admin and hasattr(original_model, 'tenant_id'): - conditions = expr.or_(ExternalNetwork.network_id != expr.null(), - *conditions) - return conditions - - def _network_result_filter_hook(self, query, filters): - vals = filters and filters.get(external_net.EXTERNAL, []) - if not vals: - return query - if vals[0]: - return query.filter((ExternalNetwork.network_id != expr.null())) - return query.filter((ExternalNetwork.network_id == expr.null())) - - # TODO(salvatore-orlando): Perform this operation without explicitly - # referring to db_base_plugin_v2, as plugins that do not extend from it - # might exist in the future - db_base_plugin_v2.NeutronDbPluginV2.register_model_query_hook( - models_v2.Network, - "external_net", - '_network_model_hook', - '_network_filter_hook', - '_network_result_filter_hook') - - def _network_is_external(self, context, net_id): - try: - context.session.query(ExternalNetwork).filter_by( - network_id=net_id).one() - return True - except exc.NoResultFound: - return False - - def _extend_network_dict_l3(self, network_res, network_db): - # Comparing with None for converting uuid into bool - network_res[external_net.EXTERNAL] = network_db.external is not None - return network_res - - # Register dict extend functions for networks - db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attributes.NETWORKS, ['_extend_network_dict_l3']) - - def _process_l3_create(self, context, net_data, req_data): - external = req_data.get(external_net.EXTERNAL) - external_set = attributes.is_attr_set(external) - - if not external_set: - return - - if external: - # expects to be called within a plugin's session - context.session.add(ExternalNetwork(network_id=net_data['id'])) - net_data[external_net.EXTERNAL] = external - - def _process_l3_update(self, context, net_data, req_data): - - new_value = req_data.get(external_net.EXTERNAL) - net_id = net_data['id'] - if not attributes.is_attr_set(new_value): - return - - if net_data.get(external_net.EXTERNAL) == new_value: - return - - if new_value: - context.session.add(ExternalNetwork(network_id=net_id)) - net_data[external_net.EXTERNAL] = True - else: - # must make sure we do not have any external gateway ports - # (and thus, possible floating IPs) on this network before - # allow it to be update to external=False - port = context.session.query(models_v2.Port).filter_by( - device_owner=DEVICE_OWNER_ROUTER_GW, - network_id=net_data['id']).first() - if port: - raise external_net.ExternalNetworkInUse(net_id=net_id) - - context.session.query(ExternalNetwork).filter_by( - network_id=net_id).delete() - net_data[external_net.EXTERNAL] = False - - def _process_l3_delete(self, context, network_id): - l3plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) - if l3plugin: - l3plugin.delete_disassociated_floatingips(context, network_id) - - def _filter_nets_l3(self, context, nets, filters): - vals = filters and filters.get(external_net.EXTERNAL, []) - if not vals: - return nets - - ext_nets = set(en['network_id'] - for en in context.session.query(ExternalNetwork)) - if vals[0]: - return [n for n in nets if n['id'] in ext_nets] - else: - return [n for n in nets if n['id'] not in ext_nets] - - def get_external_network_id(self, context): - nets = self.get_networks(context, {external_net.EXTERNAL: [True]}) - if len(nets) > 1: - raise n_exc.TooManyExternalNetworks() - else: - return nets[0]['id'] if nets else None diff --git a/neutron/db/extradhcpopt_db.py b/neutron/db/extradhcpopt_db.py deleted file mode 100644 index 4693457f7..000000000 --- a/neutron/db/extradhcpopt_db.py +++ /dev/null @@ -1,127 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation. -# 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: Don Kehn, dekehn@gmail.com -# -import sqlalchemy as sa -from sqlalchemy import orm - -from neutron.api.v2 import attributes -from neutron.db import db_base_plugin_v2 -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.extensions import extra_dhcp_opt as edo_ext -from neutron.openstack.common import log as logging - -LOG = logging.getLogger(__name__) - - -class ExtraDhcpOpt(model_base.BASEV2, models_v2.HasId): - """Represent a generic concept of extra options associated to a port. - - Each port may have none to many dhcp opts associated to it that can - define specifically different or extra options to DHCP clients. - These will be written to the /opts files, and each option's - tag will be referenced in the /host file. - """ - port_id = sa.Column(sa.String(36), - sa.ForeignKey('ports.id', ondelete="CASCADE"), - nullable=False) - opt_name = sa.Column(sa.String(64), nullable=False) - opt_value = sa.Column(sa.String(255), nullable=False) - __table_args__ = (sa.UniqueConstraint('port_id', - 'opt_name', - name='uidx_portid_optname'), - model_base.BASEV2.__table_args__,) - - # Add a relationship to the Port model in order to instruct SQLAlchemy to - # eagerly load extra_dhcp_opts bindings - ports = orm.relationship( - models_v2.Port, - backref=orm.backref("dhcp_opts", lazy='joined', cascade='delete')) - - -class ExtraDhcpOptMixin(object): - """Mixin class to add extra options to the DHCP opts file - and associate them to a port. - """ - def _process_port_create_extra_dhcp_opts(self, context, port, - extra_dhcp_opts): - if not extra_dhcp_opts: - return port - with context.session.begin(subtransactions=True): - for dopt in extra_dhcp_opts: - if dopt['opt_value']: - db = ExtraDhcpOpt( - port_id=port['id'], - opt_name=dopt['opt_name'], - opt_value=dopt['opt_value']) - context.session.add(db) - return self._extend_port_extra_dhcp_opts_dict(context, port) - - def _extend_port_extra_dhcp_opts_dict(self, context, port): - port[edo_ext.EXTRADHCPOPTS] = self._get_port_extra_dhcp_opts_binding( - context, port['id']) - - def _get_port_extra_dhcp_opts_binding(self, context, port_id): - query = self._model_query(context, ExtraDhcpOpt) - binding = query.filter(ExtraDhcpOpt.port_id == port_id) - return [{'opt_name': r.opt_name, 'opt_value': r.opt_value} - for r in binding] - - def _update_extra_dhcp_opts_on_port(self, context, id, port, - updated_port=None): - # It is not necessary to update in a transaction, because - # its called from within one from ovs_neutron_plugin. - dopts = port['port'].get(edo_ext.EXTRADHCPOPTS) - - if dopts: - opt_db = self._model_query( - context, ExtraDhcpOpt).filter_by(port_id=id).all() - # if there are currently no dhcp_options associated to - # this port, Then just insert the new ones and be done. - with context.session.begin(subtransactions=True): - for upd_rec in dopts: - for opt in opt_db: - if opt['opt_name'] == upd_rec['opt_name']: - # to handle deleting of a opt from the port. - if upd_rec['opt_value'] is None: - context.session.delete(opt) - elif opt['opt_value'] != upd_rec['opt_value']: - opt.update( - {'opt_value': upd_rec['opt_value']}) - break - else: - if upd_rec['opt_value'] is not None: - db = ExtraDhcpOpt( - port_id=id, - opt_name=upd_rec['opt_name'], - opt_value=upd_rec['opt_value']) - context.session.add(db) - - if updated_port: - edolist = self._get_port_extra_dhcp_opts_binding(context, id) - updated_port[edo_ext.EXTRADHCPOPTS] = edolist - - return bool(dopts) - - def _extend_port_dict_extra_dhcp_opt(self, res, port): - res[edo_ext.EXTRADHCPOPTS] = [{'opt_name': dho.opt_name, - 'opt_value': dho.opt_value} - for dho in port.dhcp_opts] - return res - - db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attributes.PORTS, ['_extend_port_dict_extra_dhcp_opt']) diff --git a/neutron/db/extraroute_db.py b/neutron/db/extraroute_db.py deleted file mode 100644 index c4d2ada8a..000000000 --- a/neutron/db/extraroute_db.py +++ /dev/null @@ -1,185 +0,0 @@ -# Copyright 2013, Nachi Ueno, NTT MCL, 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. - -import netaddr -from oslo.config import cfg -import sqlalchemy as sa -from sqlalchemy import orm - -from neutron.common import utils -from neutron.db import db_base_plugin_v2 -from neutron.db import l3_db -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.extensions import extraroute -from neutron.extensions import l3 -from neutron.openstack.common import log as logging - - -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")), -] - -cfg.CONF.register_opts(extra_route_opts) - - -class RouterRoute(model_base.BASEV2, models_v2.Route): - router_id = sa.Column(sa.String(36), - sa.ForeignKey('routers.id', - ondelete="CASCADE"), - primary_key=True) - - router = orm.relationship(l3_db.Router, - backref=orm.backref("route_list", - lazy='joined', - cascade='delete')) - - -class ExtraRoute_db_mixin(l3_db.L3_NAT_db_mixin): - """Mixin class to support extra route configuration on router.""" - - def _extend_router_dict_extraroute(self, router_res, router_db): - router_res['routes'] = (ExtraRoute_db_mixin. - _make_extra_route_list( - router_db['route_list'] - )) - - db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - l3.ROUTERS, ['_extend_router_dict_extraroute']) - - def update_router(self, context, id, router): - r = router['router'] - with context.session.begin(subtransactions=True): - #check if route exists and have permission to access - router_db = self._get_router(context, id) - if 'routes' in r: - self._update_extra_routes(context, router_db, r['routes']) - routes = self._get_extra_routes_by_router_id(context, id) - router_updated = super(ExtraRoute_db_mixin, self).update_router( - context, id, router) - router_updated['routes'] = routes - - return router_updated - - def _get_subnets_by_cidr(self, context, cidr): - query_subnets = context.session.query(models_v2.Subnet) - return query_subnets.filter_by(cidr=cidr).all() - - def _validate_routes_nexthop(self, cidrs, ips, routes, nexthop): - #Note(nati): Nexthop should be connected, - # so we need to check - # nexthop belongs to one of cidrs of the router ports - if not netaddr.all_matching_cidrs(nexthop, cidrs): - raise extraroute.InvalidRoutes( - routes=routes, - reason=_('the nexthop is not connected with router')) - #Note(nati) nexthop should not be same as fixed_ips - if nexthop in ips: - raise extraroute.InvalidRoutes( - routes=routes, - reason=_('the nexthop is used by router')) - - def _validate_routes(self, context, - router_id, routes): - if len(routes) > cfg.CONF.max_routes: - raise extraroute.RoutesExhausted( - router_id=router_id, - quota=cfg.CONF.max_routes) - - filters = {'device_id': [router_id]} - ports = self._core_plugin.get_ports(context, filters) - cidrs = [] - ips = [] - for port in ports: - for ip in port['fixed_ips']: - cidrs.append(self._core_plugin._get_subnet( - context, ip['subnet_id'])['cidr']) - ips.append(ip['ip_address']) - for route in routes: - self._validate_routes_nexthop( - cidrs, ips, routes, route['nexthop']) - - def _update_extra_routes(self, context, router, routes): - self._validate_routes(context, router['id'], - routes) - old_routes, routes_dict = self._get_extra_routes_dict_by_router_id( - context, router['id']) - added, removed = utils.diff_list_of_dict(old_routes, - routes) - LOG.debug(_('Added routes are %s'), added) - for route in added: - router_routes = RouterRoute( - router_id=router['id'], - destination=route['destination'], - nexthop=route['nexthop']) - context.session.add(router_routes) - - LOG.debug(_('Removed routes are %s'), removed) - for route in removed: - context.session.delete( - routes_dict[(route['destination'], route['nexthop'])]) - - @staticmethod - def _make_extra_route_list(extra_routes): - return [{'destination': route['destination'], - 'nexthop': route['nexthop']} - for route in extra_routes] - - def _get_extra_routes_by_router_id(self, context, id): - query = context.session.query(RouterRoute) - query = query.filter_by(router_id=id) - return self._make_extra_route_list(query) - - def _get_extra_routes_dict_by_router_id(self, context, id): - query = context.session.query(RouterRoute) - query = query.filter_by(router_id=id) - routes = [] - routes_dict = {} - for route in query: - routes.append({'destination': route['destination'], - 'nexthop': route['nexthop']}) - routes_dict[(route['destination'], route['nexthop'])] = route - return routes, routes_dict - - def get_router(self, context, id, fields=None): - with context.session.begin(subtransactions=True): - router = super(ExtraRoute_db_mixin, self).get_router( - context, id, fields) - return router - - def get_routers(self, context, filters=None, fields=None, - sorts=None, limit=None, marker=None, - page_reverse=False): - with context.session.begin(subtransactions=True): - routers = super(ExtraRoute_db_mixin, self).get_routers( - context, filters, fields, sorts=sorts, limit=limit, - marker=marker, page_reverse=page_reverse) - return routers - - def _confirm_router_interface_not_in_use(self, context, router_id, - subnet_id): - super(ExtraRoute_db_mixin, self)._confirm_router_interface_not_in_use( - context, router_id, subnet_id) - subnet_db = self._core_plugin._get_subnet(context, subnet_id) - subnet_cidr = netaddr.IPNetwork(subnet_db['cidr']) - extra_routes = self._get_extra_routes_by_router_id(context, router_id) - for route in extra_routes: - if netaddr.all_matching_cidrs(route['nexthop'], [subnet_cidr]): - raise extraroute.RouterInterfaceInUseByRoute( - router_id=router_id, subnet_id=subnet_id) diff --git a/neutron/db/firewall/__init__.py b/neutron/db/firewall/__init__.py deleted file mode 100644 index d1e364161..000000000 --- a/neutron/db/firewall/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# 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. diff --git a/neutron/db/firewall/firewall_db.py b/neutron/db/firewall/firewall_db.py deleted file mode 100644 index 5636a8cbf..000000000 --- a/neutron/db/firewall/firewall_db.py +++ /dev/null @@ -1,481 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 Big Switch 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: Sumit Naiksatam, sumitnaiksatam@gmail.com, Big Switch Networks, Inc. - -import sqlalchemy as sa -from sqlalchemy.ext.orderinglist import ordering_list -from sqlalchemy import orm -from sqlalchemy.orm import exc - -from neutron.db import db_base_plugin_v2 as base_db -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.extensions import firewall -from neutron import manager -from neutron.openstack.common import log as logging -from neutron.openstack.common import uuidutils -from neutron.plugins.common import constants as const - - -LOG = logging.getLogger(__name__) - - -class FirewallRule(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): - """Represents a Firewall rule.""" - __tablename__ = 'firewall_rules' - name = sa.Column(sa.String(255)) - description = sa.Column(sa.String(1024)) - firewall_policy_id = sa.Column(sa.String(36), - sa.ForeignKey('firewall_policies.id'), - nullable=True) - shared = sa.Column(sa.Boolean) - protocol = sa.Column(sa.String(40)) - ip_version = sa.Column(sa.Integer, nullable=False) - source_ip_address = sa.Column(sa.String(46)) - destination_ip_address = sa.Column(sa.String(46)) - source_port_range_min = sa.Column(sa.Integer) - source_port_range_max = sa.Column(sa.Integer) - destination_port_range_min = sa.Column(sa.Integer) - destination_port_range_max = sa.Column(sa.Integer) - action = sa.Column(sa.Enum('allow', 'deny', name='firewallrules_action')) - enabled = sa.Column(sa.Boolean) - position = sa.Column(sa.Integer) - - -class Firewall(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): - """Represents a Firewall resource.""" - __tablename__ = 'firewalls' - name = sa.Column(sa.String(255)) - description = sa.Column(sa.String(1024)) - shared = sa.Column(sa.Boolean) - admin_state_up = sa.Column(sa.Boolean) - status = sa.Column(sa.String(16)) - firewall_policy_id = sa.Column(sa.String(36), - sa.ForeignKey('firewall_policies.id'), - nullable=True) - - -class FirewallPolicy(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): - """Represents a Firewall Policy resource.""" - __tablename__ = 'firewall_policies' - name = sa.Column(sa.String(255)) - description = sa.Column(sa.String(1024)) - shared = sa.Column(sa.Boolean) - firewall_rules = orm.relationship( - FirewallRule, - backref=orm.backref('firewall_policies', cascade='all, delete'), - order_by='FirewallRule.position', - collection_class=ordering_list('position', count_from=1)) - audited = sa.Column(sa.Boolean) - firewalls = orm.relationship(Firewall, backref='firewall_policies') - - -class Firewall_db_mixin(firewall.FirewallPluginBase, base_db.CommonDbMixin): - """Mixin class for Firewall DB implementation.""" - - @property - def _core_plugin(self): - return manager.NeutronManager.get_plugin() - - def _get_firewall(self, context, id): - try: - return self._get_by_id(context, Firewall, id) - except exc.NoResultFound: - raise firewall.FirewallNotFound(firewall_id=id) - - def _get_firewall_policy(self, context, id): - try: - return self._get_by_id(context, FirewallPolicy, id) - except exc.NoResultFound: - raise firewall.FirewallPolicyNotFound(firewall_policy_id=id) - - def _get_firewall_rule(self, context, id): - try: - return self._get_by_id(context, FirewallRule, id) - except exc.NoResultFound: - raise firewall.FirewallRuleNotFound(firewall_rule_id=id) - - def _make_firewall_dict(self, fw, fields=None): - res = {'id': fw['id'], - 'tenant_id': fw['tenant_id'], - 'name': fw['name'], - 'description': fw['description'], - 'shared': fw['shared'], - 'admin_state_up': fw['admin_state_up'], - 'status': fw['status'], - 'firewall_policy_id': fw['firewall_policy_id']} - return self._fields(res, fields) - - def _make_firewall_policy_dict(self, firewall_policy, fields=None): - fw_rules = [rule['id'] for rule in firewall_policy['firewall_rules']] - firewalls = [fw['id'] for fw in firewall_policy['firewalls']] - res = {'id': firewall_policy['id'], - 'tenant_id': firewall_policy['tenant_id'], - 'name': firewall_policy['name'], - 'description': firewall_policy['description'], - 'shared': firewall_policy['shared'], - 'audited': firewall_policy['audited'], - 'firewall_rules': fw_rules, - 'firewall_list': firewalls} - return self._fields(res, fields) - - def _make_firewall_rule_dict(self, firewall_rule, fields=None): - position = None - # We return the position only if the firewall_rule is bound to a - # firewall_policy. - if firewall_rule['firewall_policy_id']: - position = firewall_rule['position'] - src_port_range = self._get_port_range_from_min_max_ports( - firewall_rule['source_port_range_min'], - firewall_rule['source_port_range_max']) - dst_port_range = self._get_port_range_from_min_max_ports( - firewall_rule['destination_port_range_min'], - firewall_rule['destination_port_range_max']) - res = {'id': firewall_rule['id'], - 'tenant_id': firewall_rule['tenant_id'], - 'name': firewall_rule['name'], - 'description': firewall_rule['description'], - 'firewall_policy_id': firewall_rule['firewall_policy_id'], - 'shared': firewall_rule['shared'], - 'protocol': firewall_rule['protocol'], - 'ip_version': firewall_rule['ip_version'], - 'source_ip_address': firewall_rule['source_ip_address'], - 'destination_ip_address': - firewall_rule['destination_ip_address'], - 'source_port': src_port_range, - 'destination_port': dst_port_range, - 'action': firewall_rule['action'], - 'position': position, - 'enabled': firewall_rule['enabled']} - return self._fields(res, fields) - - def _set_rules_for_policy(self, context, firewall_policy_db, rule_id_list): - fwp_db = firewall_policy_db - with context.session.begin(subtransactions=True): - if not rule_id_list: - fwp_db.firewall_rules = [] - fwp_db.audited = False - return - # We will first check if the new list of rules is valid - filters = {'id': [r_id for r_id in rule_id_list]} - rules_in_db = self._get_collection_query(context, FirewallRule, - filters=filters) - rules_dict = dict((fwr_db['id'], fwr_db) for fwr_db in rules_in_db) - for fwrule_id in rule_id_list: - if fwrule_id not in rules_dict: - # If we find an invalid rule in the list we - # do not perform the update since this breaks - # the integrity of this list. - raise firewall.FirewallRuleNotFound(firewall_rule_id= - fwrule_id) - elif rules_dict[fwrule_id]['firewall_policy_id']: - if (rules_dict[fwrule_id]['firewall_policy_id'] != - fwp_db['id']): - raise firewall.FirewallRuleInUse( - firewall_rule_id=fwrule_id) - # New list of rules is valid so we will first reset the existing - # list and then add each rule in order. - # Note that the list could be empty in which case we interpret - # it as clearing existing rules. - fwp_db.firewall_rules = [] - for fwrule_id in rule_id_list: - fwp_db.firewall_rules.append(rules_dict[fwrule_id]) - fwp_db.firewall_rules.reorder() - fwp_db.audited = False - - def _process_rule_for_policy(self, context, firewall_policy_id, - firewall_rule_db, position): - with context.session.begin(subtransactions=True): - fwp_query = context.session.query( - FirewallPolicy).with_lockmode('update') - fwp_db = fwp_query.filter_by(id=firewall_policy_id).one() - if position: - # Note that although position numbering starts at 1, - # internal ordering of the list starts at 0, so we compensate. - fwp_db.firewall_rules.insert(position - 1, firewall_rule_db) - else: - fwp_db.firewall_rules.remove(firewall_rule_db) - fwp_db.firewall_rules.reorder() - fwp_db.audited = False - return self._make_firewall_policy_dict(fwp_db) - - def _get_min_max_ports_from_range(self, port_range): - if not port_range: - return [None, None] - min_port, sep, max_port = port_range.partition(":") - if not max_port: - max_port = min_port - return [int(min_port), int(max_port)] - - def _get_port_range_from_min_max_ports(self, min_port, max_port): - if not min_port: - return None - if min_port == max_port: - return str(min_port) - else: - return '%d:%d' % (min_port, max_port) - - def _validate_fwr_protocol_parameters(self, fwr): - protocol = fwr['protocol'] - if protocol not in (const.TCP, const.UDP): - if fwr['source_port'] or fwr['destination_port']: - raise firewall.FirewallRuleInvalidICMPParameter( - param="Source, destination port") - - def create_firewall(self, context, firewall): - LOG.debug(_("create_firewall() called")) - fw = firewall['firewall'] - tenant_id = self._get_tenant_id_for_create(context, fw) - with context.session.begin(subtransactions=True): - firewall_db = Firewall(id=uuidutils.generate_uuid(), - tenant_id=tenant_id, - name=fw['name'], - description=fw['description'], - firewall_policy_id= - fw['firewall_policy_id'], - admin_state_up=fw['admin_state_up'], - status=const.PENDING_CREATE) - context.session.add(firewall_db) - return self._make_firewall_dict(firewall_db) - - def update_firewall(self, context, id, firewall): - LOG.debug(_("update_firewall() called")) - fw = firewall['firewall'] - with context.session.begin(subtransactions=True): - fw_query = context.session.query( - Firewall).with_lockmode('update') - firewall_db = fw_query.filter_by(id=id).one() - firewall_db.update(fw) - return self._make_firewall_dict(firewall_db) - - def delete_firewall(self, context, id): - LOG.debug(_("delete_firewall() called")) - with context.session.begin(subtransactions=True): - fw_query = context.session.query( - Firewall).with_lockmode('update') - firewall_db = fw_query.filter_by(id=id).one() - # Note: Plugin should ensure that it's okay to delete if the - # firewall is active - context.session.delete(firewall_db) - - def get_firewall(self, context, id, fields=None): - LOG.debug(_("get_firewall() called")) - fw = self._get_firewall(context, id) - return self._make_firewall_dict(fw, fields) - - def get_firewalls(self, context, filters=None, fields=None): - LOG.debug(_("get_firewalls() called")) - return self._get_collection(context, Firewall, - self._make_firewall_dict, - filters=filters, fields=fields) - - def get_firewalls_count(self, context, filters=None): - LOG.debug(_("get_firewalls_count() called")) - return self._get_collection_count(context, Firewall, - filters=filters) - - def create_firewall_policy(self, context, firewall_policy): - LOG.debug(_("create_firewall_policy() called")) - fwp = firewall_policy['firewall_policy'] - tenant_id = self._get_tenant_id_for_create(context, fwp) - with context.session.begin(subtransactions=True): - fwp_db = FirewallPolicy(id=uuidutils.generate_uuid(), - tenant_id=tenant_id, - name=fwp['name'], - description=fwp['description'], - shared=fwp['shared']) - context.session.add(fwp_db) - self._set_rules_for_policy(context, fwp_db, - fwp['firewall_rules']) - fwp_db.audited = fwp['audited'] - return self._make_firewall_policy_dict(fwp_db) - - def update_firewall_policy(self, context, id, firewall_policy): - LOG.debug(_("update_firewall_policy() called")) - fwp = firewall_policy['firewall_policy'] - with context.session.begin(subtransactions=True): - fwp_db = self._get_firewall_policy(context, id) - if 'firewall_rules' in fwp: - self._set_rules_for_policy(context, fwp_db, - fwp['firewall_rules']) - del fwp['firewall_rules'] - fwp_db.update(fwp) - return self._make_firewall_policy_dict(fwp_db) - - def delete_firewall_policy(self, context, id): - LOG.debug(_("delete_firewall_policy() called")) - with context.session.begin(subtransactions=True): - fwp = self._get_firewall_policy(context, id) - # Ensure that the firewall_policy is not - # being used - qry = context.session.query(Firewall) - if qry.filter_by(firewall_policy_id=id).first(): - raise firewall.FirewallPolicyInUse(firewall_policy_id=id) - else: - context.session.delete(fwp) - - def get_firewall_policy(self, context, id, fields=None): - LOG.debug(_("get_firewall_policy() called")) - fwp = self._get_firewall_policy(context, id) - return self._make_firewall_policy_dict(fwp, fields) - - def get_firewall_policies(self, context, filters=None, fields=None): - LOG.debug(_("get_firewall_policies() called")) - return self._get_collection(context, FirewallPolicy, - self._make_firewall_policy_dict, - filters=filters, fields=fields) - - def get_firewalls_policies_count(self, context, filters=None): - LOG.debug(_("get_firewall_policies_count() called")) - return self._get_collection_count(context, FirewallPolicy, - filters=filters) - - def create_firewall_rule(self, context, firewall_rule): - LOG.debug(_("create_firewall_rule() called")) - fwr = firewall_rule['firewall_rule'] - self._validate_fwr_protocol_parameters(fwr) - tenant_id = self._get_tenant_id_for_create(context, fwr) - src_port_min, src_port_max = self._get_min_max_ports_from_range( - fwr['source_port']) - dst_port_min, dst_port_max = self._get_min_max_ports_from_range( - fwr['destination_port']) - with context.session.begin(subtransactions=True): - fwr_db = FirewallRule(id=uuidutils.generate_uuid(), - tenant_id=tenant_id, - name=fwr['name'], - description=fwr['description'], - shared=fwr['shared'], - protocol=fwr['protocol'], - ip_version=fwr['ip_version'], - source_ip_address=fwr['source_ip_address'], - destination_ip_address= - fwr['destination_ip_address'], - source_port_range_min=src_port_min, - source_port_range_max=src_port_max, - destination_port_range_min=dst_port_min, - destination_port_range_max=dst_port_max, - action=fwr['action'], - enabled=fwr['enabled']) - context.session.add(fwr_db) - return self._make_firewall_rule_dict(fwr_db) - - def update_firewall_rule(self, context, id, firewall_rule): - LOG.debug(_("update_firewall_rule() called")) - fwr = firewall_rule['firewall_rule'] - if 'source_port' in fwr: - src_port_min, src_port_max = self._get_min_max_ports_from_range( - fwr['source_port']) - fwr['source_port_range_min'] = src_port_min - fwr['source_port_range_max'] = src_port_max - del fwr['source_port'] - if 'destination_port' in fwr: - dst_port_min, dst_port_max = self._get_min_max_ports_from_range( - fwr['destination_port']) - fwr['destination_port_range_min'] = dst_port_min - fwr['destination_port_range_max'] = dst_port_max - del fwr['destination_port'] - with context.session.begin(subtransactions=True): - fwr_db = self._get_firewall_rule(context, id) - fwr_db.update(fwr) - if fwr_db.firewall_policy_id: - fwp_db = self._get_firewall_policy(context, - fwr_db.firewall_policy_id) - fwp_db.audited = False - return self._make_firewall_rule_dict(fwr_db) - - def delete_firewall_rule(self, context, id): - LOG.debug(_("delete_firewall_rule() called")) - with context.session.begin(subtransactions=True): - fwr = self._get_firewall_rule(context, id) - if fwr.firewall_policy_id: - raise firewall.FirewallRuleInUse(firewall_rule_id=id) - context.session.delete(fwr) - - def get_firewall_rule(self, context, id, fields=None): - LOG.debug(_("get_firewall_rule() called")) - fwr = self._get_firewall_rule(context, id) - return self._make_firewall_rule_dict(fwr, fields) - - def get_firewall_rules(self, context, filters=None, fields=None): - LOG.debug(_("get_firewall_rules() called")) - return self._get_collection(context, FirewallRule, - self._make_firewall_rule_dict, - filters=filters, fields=fields) - - def get_firewalls_rules_count(self, context, filters=None): - LOG.debug(_("get_firewall_rules_count() called")) - return self._get_collection_count(context, FirewallRule, - filters=filters) - - def _validate_insert_remove_rule_request(self, id, rule_info): - if not rule_info or 'firewall_rule_id' not in rule_info: - raise firewall.FirewallRuleInfoMissing() - - def insert_rule(self, context, id, rule_info): - LOG.debug(_("insert_rule() called")) - self._validate_insert_remove_rule_request(id, rule_info) - firewall_rule_id = rule_info['firewall_rule_id'] - insert_before = True - ref_firewall_rule_id = None - if not firewall_rule_id: - raise firewall.FirewallRuleNotFound(firewall_rule_id=None) - if 'insert_before' in rule_info: - ref_firewall_rule_id = rule_info['insert_before'] - if not ref_firewall_rule_id and 'insert_after' in rule_info: - # If insert_before is set, we will ignore insert_after. - ref_firewall_rule_id = rule_info['insert_after'] - insert_before = False - with context.session.begin(subtransactions=True): - fwr_db = self._get_firewall_rule(context, firewall_rule_id) - if fwr_db.firewall_policy_id: - raise firewall.FirewallRuleInUse(firewall_rule_id=fwr_db['id']) - if ref_firewall_rule_id: - # If reference_firewall_rule_id is set, the new rule - # is inserted depending on the value of insert_before. - # If insert_before is set, the new rule is inserted before - # reference_firewall_rule_id, and if it is not set the new - # rule is inserted after reference_firewall_rule_id. - ref_fwr_db = self._get_firewall_rule( - context, ref_firewall_rule_id) - if insert_before: - position = ref_fwr_db.position - else: - position = ref_fwr_db.position + 1 - else: - # If reference_firewall_rule_id is not set, it is assumed - # that the new rule needs to be inserted at the top. - # insert_before field is ignored. - # So default insertion is always at the top. - # Also note that position numbering starts at 1. - position = 1 - return self._process_rule_for_policy(context, id, fwr_db, - position) - - def remove_rule(self, context, id, rule_info): - LOG.debug(_("remove_rule() called")) - self._validate_insert_remove_rule_request(id, rule_info) - firewall_rule_id = rule_info['firewall_rule_id'] - if not firewall_rule_id: - raise firewall.FirewallRuleNotFound(firewall_rule_id=None) - with context.session.begin(subtransactions=True): - fwr_db = self._get_firewall_rule(context, firewall_rule_id) - if fwr_db.firewall_policy_id != id: - raise firewall.FirewallRuleNotAssociatedWithPolicy( - firewall_rule_id=fwr_db['id'], - firewall_policy_id=id) - return self._process_rule_for_policy(context, id, fwr_db, None) diff --git a/neutron/db/l3_agentschedulers_db.py b/neutron/db/l3_agentschedulers_db.py deleted file mode 100644 index 19969cb60..000000000 --- a/neutron/db/l3_agentschedulers_db.py +++ /dev/null @@ -1,291 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation. -# 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. - -from oslo.config import cfg -import sqlalchemy as sa -from sqlalchemy import func -from sqlalchemy import orm -from sqlalchemy.orm import exc -from sqlalchemy.orm import joinedload - -from neutron.common import constants -from neutron.db import agents_db -from neutron.db import agentschedulers_db -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.extensions import l3agentscheduler - - -L3_AGENTS_SCHEDULER_OPTS = [ - cfg.StrOpt('router_scheduler_driver', - default='neutron.scheduler.l3_agent_scheduler.ChanceScheduler', - 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.CONF.register_opts(L3_AGENTS_SCHEDULER_OPTS) - - -class RouterL3AgentBinding(model_base.BASEV2, models_v2.HasId): - """Represents binding between neutron routers and L3 agents.""" - - router_id = sa.Column(sa.String(36), - sa.ForeignKey("routers.id", ondelete='CASCADE')) - l3_agent = orm.relation(agents_db.Agent) - l3_agent_id = sa.Column(sa.String(36), - sa.ForeignKey("agents.id", - ondelete='CASCADE')) - - -class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, - agentschedulers_db.AgentSchedulerDbMixin): - """Mixin class to add l3 agent scheduler extension to plugins - using the l3 agent for routing. - """ - - router_scheduler = None - - def add_router_to_l3_agent(self, context, agent_id, router_id): - """Add a l3 agent to host a router.""" - router = self.get_router(context, router_id) - with context.session.begin(subtransactions=True): - agent_db = self._get_agent(context, agent_id) - if (agent_db['agent_type'] != constants.AGENT_TYPE_L3 or - not agent_db['admin_state_up'] or - not self.get_l3_agent_candidates(router, [agent_db])): - raise l3agentscheduler.InvalidL3Agent(id=agent_id) - query = context.session.query(RouterL3AgentBinding) - try: - binding = query.filter_by(router_id=router_id).one() - - raise l3agentscheduler.RouterHostedByL3Agent( - router_id=router_id, - agent_id=binding.l3_agent_id) - except exc.NoResultFound: - pass - - result = self.auto_schedule_routers(context, - agent_db.host, - [router_id]) - if not result: - raise l3agentscheduler.RouterSchedulingFailed( - router_id=router_id, agent_id=agent_id) - - l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3) - if l3_notifier: - l3_notifier.router_added_to_agent( - context, [router_id], agent_db.host) - - def remove_router_from_l3_agent(self, context, agent_id, router_id): - """Remove the router from l3 agent. - - After removal, the router will be non-hosted until there is update - which leads to re-schedule or be added to another agent manually. - """ - agent = self._get_agent(context, agent_id) - self._unbind_router(context, router_id, agent_id) - l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3) - if l3_notifier: - l3_notifier.router_removed_from_agent( - context, router_id, agent.host) - - def _unbind_router(self, context, router_id, agent_id): - with context.session.begin(subtransactions=True): - query = context.session.query(RouterL3AgentBinding) - query = query.filter( - RouterL3AgentBinding.router_id == router_id, - RouterL3AgentBinding.l3_agent_id == agent_id) - try: - binding = query.one() - except exc.NoResultFound: - raise l3agentscheduler.RouterNotHostedByL3Agent( - router_id=router_id, agent_id=agent_id) - context.session.delete(binding) - - def reschedule_router(self, context, router_id, candidates=None): - """Reschedule router to a new l3 agent - - Remove the router from the agent(s) currently hosting it and - schedule it again - """ - cur_agents = self.list_l3_agents_hosting_router( - context, router_id)['agents'] - with context.session.begin(subtransactions=True): - for agent in cur_agents: - self._unbind_router(context, router_id, agent['id']) - - new_agent = self.schedule_router(context, router_id, - candidates=candidates) - if not new_agent: - raise l3agentscheduler.RouterReschedulingFailed( - router_id=router_id) - - l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3) - if l3_notifier: - for agent in cur_agents: - l3_notifier.router_removed_from_agent( - context, router_id, agent['host']) - l3_notifier.router_added_to_agent( - context, [router_id], new_agent.host) - - def list_routers_on_l3_agent(self, context, agent_id): - query = context.session.query(RouterL3AgentBinding.router_id) - query = query.filter(RouterL3AgentBinding.l3_agent_id == agent_id) - - router_ids = [item[0] for item in query] - if router_ids: - return {'routers': - self.get_routers(context, filters={'id': router_ids})} - else: - return {'routers': []} - - def list_active_sync_routers_on_active_l3_agent( - self, context, host, router_ids): - agent = self._get_agent_by_type_and_host( - context, constants.AGENT_TYPE_L3, host) - if not agent.admin_state_up: - return [] - query = context.session.query(RouterL3AgentBinding.router_id) - query = query.filter( - RouterL3AgentBinding.l3_agent_id == agent.id) - - if not router_ids: - pass - else: - query = query.filter( - RouterL3AgentBinding.router_id.in_(router_ids)) - router_ids = [item[0] for item in query] - if router_ids: - return self.get_sync_data(context, router_ids=router_ids, - active=True) - else: - return [] - - def get_l3_agents_hosting_routers(self, context, router_ids, - admin_state_up=None, - active=None): - if not router_ids: - return [] - query = context.session.query(RouterL3AgentBinding) - if len(router_ids) > 1: - query = query.options(joinedload('l3_agent')).filter( - RouterL3AgentBinding.router_id.in_(router_ids)) - else: - query = query.options(joinedload('l3_agent')).filter( - RouterL3AgentBinding.router_id == router_ids[0]) - if admin_state_up is not None: - query = (query.filter(agents_db.Agent.admin_state_up == - admin_state_up)) - l3_agents = [binding.l3_agent for binding in query] - if active is not None: - l3_agents = [l3_agent for l3_agent in - l3_agents if not - agents_db.AgentDbMixin.is_agent_down( - l3_agent['heartbeat_timestamp'])] - return l3_agents - - def _get_l3_bindings_hosting_routers(self, context, router_ids): - if not router_ids: - return [] - query = context.session.query(RouterL3AgentBinding) - if len(router_ids) > 1: - query = query.options(joinedload('l3_agent')).filter( - RouterL3AgentBinding.router_id.in_(router_ids)) - else: - query = query.options(joinedload('l3_agent')).filter( - RouterL3AgentBinding.router_id == router_ids[0]) - return query.all() - - def list_l3_agents_hosting_router(self, context, router_id): - with context.session.begin(subtransactions=True): - bindings = self._get_l3_bindings_hosting_routers( - context, [router_id]) - results = [] - for binding in bindings: - l3_agent_dict = self._make_agent_dict(binding.l3_agent) - results.append(l3_agent_dict) - if results: - return {'agents': results} - else: - return {'agents': []} - - def get_l3_agents(self, context, active=None, filters=None): - query = context.session.query(agents_db.Agent) - query = query.filter( - agents_db.Agent.agent_type == constants.AGENT_TYPE_L3) - if active is not None: - query = (query.filter(agents_db.Agent.admin_state_up == active)) - if filters: - for key, value in filters.iteritems(): - column = getattr(agents_db.Agent, key, None) - if column: - query = query.filter(column.in_(value)) - - return [l3_agent - for l3_agent in query - if agentschedulers_db.AgentSchedulerDbMixin.is_eligible_agent( - active, l3_agent)] - - def get_l3_agent_candidates(self, sync_router, l3_agents): - """Get the valid l3 agents for the router from a list of l3_agents.""" - candidates = [] - for l3_agent in l3_agents: - if not l3_agent.admin_state_up: - continue - agent_conf = self.get_configuration_dict(l3_agent) - router_id = agent_conf.get('router_id', None) - use_namespaces = agent_conf.get('use_namespaces', True) - handle_internal_only_routers = agent_conf.get( - 'handle_internal_only_routers', True) - gateway_external_network_id = agent_conf.get( - 'gateway_external_network_id', None) - if not use_namespaces and router_id != sync_router['id']: - continue - ex_net_id = (sync_router['external_gateway_info'] or {}).get( - 'network_id') - if ((not ex_net_id and not handle_internal_only_routers) or - (ex_net_id and gateway_external_network_id and - ex_net_id != gateway_external_network_id)): - continue - candidates.append(l3_agent) - return candidates - - def auto_schedule_routers(self, context, host, router_ids): - if self.router_scheduler: - return self.router_scheduler.auto_schedule_routers( - self, context, host, router_ids) - - def schedule_router(self, context, router, candidates=None): - if self.router_scheduler: - return self.router_scheduler.schedule( - self, context, router, candidates) - - def schedule_routers(self, context, routers): - """Schedule the routers to l3 agents.""" - for router in routers: - self.schedule_router(context, router) - - def get_l3_agent_with_min_routers(self, context, agent_ids): - """Return l3 agent with the least number of routers.""" - query = context.session.query( - agents_db.Agent, - func.count( - RouterL3AgentBinding.router_id - ).label('count')).outerjoin(RouterL3AgentBinding).group_by( - RouterL3AgentBinding.l3_agent_id).order_by('count') - res = query.filter(agents_db.Agent.id.in_(agent_ids)).first() - return res[0] diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py deleted file mode 100644 index 5d2aa6e1a..000000000 --- a/neutron/db/l3_db.py +++ /dev/null @@ -1,1039 +0,0 @@ -# Copyright 2012 VMware, 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. - -import netaddr -import sqlalchemy as sa -from sqlalchemy import orm -from sqlalchemy.orm import exc - -from neutron.api.rpc.agentnotifiers import l3_rpc_agent_api -from neutron.api.v2 import attributes -from neutron.common import constants as l3_constants -from neutron.common import exceptions as n_exc -from neutron.common import rpc as n_rpc -from neutron.common import utils -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.extensions import external_net -from neutron.extensions import l3 -from neutron import manager -from neutron.openstack.common import log as logging -from neutron.openstack.common import uuidutils -from neutron.plugins.common import constants - -LOG = logging.getLogger(__name__) - - -DEVICE_OWNER_ROUTER_INTF = l3_constants.DEVICE_OWNER_ROUTER_INTF -DEVICE_OWNER_ROUTER_GW = l3_constants.DEVICE_OWNER_ROUTER_GW -DEVICE_OWNER_FLOATINGIP = l3_constants.DEVICE_OWNER_FLOATINGIP -EXTERNAL_GW_INFO = l3.EXTERNAL_GW_INFO - -# Maps API field to DB column -# API parameter name and Database column names may differ. -# Useful to keep the filtering between API and Database. -API_TO_DB_COLUMN_MAP = {'port_id': 'fixed_port_id'} -CORE_ROUTER_ATTRS = ('id', 'name', 'tenant_id', 'admin_state_up', 'status') - - -class Router(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): - """Represents a v2 neutron router.""" - - name = sa.Column(sa.String(255)) - status = sa.Column(sa.String(16)) - admin_state_up = sa.Column(sa.Boolean) - gw_port_id = sa.Column(sa.String(36), sa.ForeignKey('ports.id')) - gw_port = orm.relationship(models_v2.Port, lazy='joined') - - -class FloatingIP(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): - """Represents a floating IP address. - - This IP address may or may not be allocated to a tenant, and may or - may not be associated with an internal port/ip address/router. - """ - - floating_ip_address = sa.Column(sa.String(64), nullable=False) - floating_network_id = sa.Column(sa.String(36), nullable=False) - floating_port_id = sa.Column(sa.String(36), sa.ForeignKey('ports.id'), - nullable=False) - fixed_port_id = sa.Column(sa.String(36), sa.ForeignKey('ports.id')) - fixed_ip_address = sa.Column(sa.String(64)) - router_id = sa.Column(sa.String(36), sa.ForeignKey('routers.id')) - # Additional attribute for keeping track of the router where the floating - # ip was associated in order to be able to ensure consistency even if an - # aysnchronous backend is unavailable when the floating IP is disassociated - last_known_router_id = sa.Column(sa.String(36)) - status = sa.Column(sa.String(16)) - - -class L3_NAT_db_mixin(l3.RouterPluginBase): - """Mixin class to add L3/NAT router methods to db_base_plugin_v2.""" - - router_device_owners = ( - DEVICE_OWNER_ROUTER_INTF, - DEVICE_OWNER_ROUTER_GW, - DEVICE_OWNER_FLOATINGIP - ) - - @property - def l3_rpc_notifier(self): - if not hasattr(self, '_l3_rpc_notifier'): - self._l3_rpc_notifier = l3_rpc_agent_api.L3AgentNotifyAPI() - return self._l3_rpc_notifier - - @l3_rpc_notifier.setter - def l3_rpc_notifier(self, value): - self._l3_rpc_notifier = value - - @property - def _core_plugin(self): - return manager.NeutronManager.get_plugin() - - def _get_router(self, context, router_id): - try: - router = self._get_by_id(context, Router, router_id) - except exc.NoResultFound: - raise l3.RouterNotFound(router_id=router_id) - return router - - def _make_router_dict(self, router, fields=None, process_extensions=True): - res = dict((key, router[key]) for key in CORE_ROUTER_ATTRS) - if router['gw_port_id']: - ext_gw_info = {'network_id': router.gw_port['network_id']} - else: - ext_gw_info = None - res.update({ - EXTERNAL_GW_INFO: ext_gw_info, - 'gw_port_id': router['gw_port_id'], - }) - # NOTE(salv-orlando): The following assumes this mixin is used in a - # class inheriting from CommonDbMixin, which is true for all existing - # plugins. - if process_extensions: - self._apply_dict_extend_functions(l3.ROUTERS, res, router) - return self._fields(res, fields) - - def _create_router_db(self, context, router, tenant_id, gw_info): - """Create the DB object and update gw info, if available.""" - with context.session.begin(subtransactions=True): - # pre-generate id so it will be available when - # configuring external gw port - router_db = Router(id=uuidutils.generate_uuid(), - tenant_id=tenant_id, - name=router['name'], - admin_state_up=router['admin_state_up'], - status="ACTIVE") - context.session.add(router_db) - return router_db - - def create_router(self, context, router): - r = router['router'] - gw_info = r.pop(EXTERNAL_GW_INFO, None) - tenant_id = self._get_tenant_id_for_create(context, r) - with context.session.begin(subtransactions=True): - router_db = self._create_router_db(context, r, tenant_id, gw_info) - if gw_info: - self._update_router_gw_info(context, router_db['id'], gw_info) - return self._make_router_dict(router_db) - - def _update_router_db(self, context, router_id, data, gw_info): - """Update the DB object and related gw info, if available.""" - with context.session.begin(subtransactions=True): - if gw_info != attributes.ATTR_NOT_SPECIFIED: - self._update_router_gw_info(context, router_id, gw_info) - router_db = self._get_router(context, router_id) - if data: - router_db.update(data) - return router_db - - def update_router(self, context, id, router): - r = router['router'] - gw_info = r.pop(EXTERNAL_GW_INFO, attributes.ATTR_NOT_SPECIFIED) - # check whether router needs and can be rescheduled to the proper - # l3 agent (associated with given external network); - # do check before update in DB as an exception will be raised - # in case no proper l3 agent found - candidates = None - if gw_info != attributes.ATTR_NOT_SPECIFIED: - candidates = self._check_router_needs_rescheduling( - context, id, gw_info) - router_db = self._update_router_db(context, id, r, gw_info) - if candidates: - l3_plugin = manager.NeutronManager.get_service_plugins().get( - constants.L3_ROUTER_NAT) - l3_plugin.reschedule_router(context, id, candidates) - - self.l3_rpc_notifier.routers_updated(context, [router_db['id']]) - return self._make_router_dict(router_db) - - def _check_router_needs_rescheduling(self, context, router_id, gw_info): - """Checks whether router's l3 agent can handle the given network - - When external_network_bridge is set, each L3 agent can be associated - with at most one external network. If router's new external gateway - is on other network then the router needs to be rescheduled to the - proper l3 agent. - If external_network_bridge is not set then the agent - can support multiple external networks and rescheduling is not needed - - :return: list of candidate agents if rescheduling needed, - None otherwise; raises exception if there is no eligible l3 agent - associated with target external network - """ - # TODO(obondarev): rethink placement of this func as l3 db manager is - # not really a proper place for agent scheduling stuff - network_id = gw_info.get('network_id') if gw_info else None - if not network_id: - return - - nets = self._core_plugin.get_networks( - context, {external_net.EXTERNAL: [True]}) - # nothing to do if there is only one external network - if len(nets) <= 1: - return - - # first get plugin supporting l3 agent scheduling - # (either l3 service plugin or core_plugin) - l3_plugin = manager.NeutronManager.get_service_plugins().get( - constants.L3_ROUTER_NAT) - if (not utils.is_extension_supported( - l3_plugin, - l3_constants.L3_AGENT_SCHEDULER_EXT_ALIAS) or - l3_plugin.router_scheduler is None): - # that might mean that we are dealing with non-agent-based - # implementation of l3 services - return - - cur_agents = l3_plugin.list_l3_agents_hosting_router( - context, router_id)['agents'] - for agent in cur_agents: - ext_net_id = agent['configurations'].get( - 'gateway_external_network_id') - ext_bridge = agent['configurations'].get( - 'external_network_bridge', 'br-ex') - if (ext_net_id == network_id or - (not ext_net_id and not ext_bridge)): - return - - # otherwise find l3 agent with matching gateway_external_network_id - active_agents = l3_plugin.get_l3_agents(context, active=True) - router = { - 'id': router_id, - 'external_gateway_info': {'network_id': network_id} - } - candidates = l3_plugin.get_l3_agent_candidates( - router, active_agents) - if not candidates: - msg = (_('No eligible l3 agent associated with external network ' - '%s found') % network_id) - raise n_exc.BadRequest(resource='router', msg=msg) - - return candidates - - def _create_router_gw_port(self, context, router, network_id): - # Port has no 'tenant-id', as it is hidden from user - gw_port = self._core_plugin.create_port(context.elevated(), { - 'port': {'tenant_id': '', # intentionally not set - 'network_id': network_id, - 'mac_address': attributes.ATTR_NOT_SPECIFIED, - 'fixed_ips': attributes.ATTR_NOT_SPECIFIED, - 'device_id': router['id'], - 'device_owner': DEVICE_OWNER_ROUTER_GW, - 'admin_state_up': True, - 'name': ''}}) - - if not gw_port['fixed_ips']: - self._core_plugin.delete_port(context.elevated(), gw_port['id'], - l3_port_check=False) - msg = (_('No IPs available for external network %s') % - network_id) - raise n_exc.BadRequest(resource='router', msg=msg) - - with context.session.begin(subtransactions=True): - router.gw_port = self._core_plugin._get_port(context.elevated(), - gw_port['id']) - context.session.add(router) - - def _validate_gw_info(self, context, gw_port, info): - network_id = info['network_id'] if info else None - if network_id: - network_db = self._core_plugin._get_network(context, network_id) - if not network_db.external: - msg = _("Network %s is not an external network") % network_id - raise n_exc.BadRequest(resource='router', msg=msg) - return network_id - - def _delete_current_gw_port(self, context, router_id, router, new_network): - """Delete gw port, if it is attached to an old network.""" - is_gw_port_attached_to_existing_network = ( - router.gw_port and router.gw_port['network_id'] != new_network) - admin_ctx = context.elevated() - if is_gw_port_attached_to_existing_network: - if self.get_floatingips_count( - admin_ctx, {'router_id': [router_id]}): - raise l3.RouterExternalGatewayInUseByFloatingIp( - router_id=router_id, net_id=router.gw_port['network_id']) - with context.session.begin(subtransactions=True): - gw_port_id = router.gw_port['id'] - router.gw_port = None - context.session.add(router) - self._core_plugin.delete_port( - admin_ctx, gw_port_id, l3_port_check=False) - - def _create_gw_port(self, context, router_id, router, new_network): - new_valid_gw_port_attachment = ( - new_network and (not router.gw_port or - router.gw_port['network_id'] != new_network)) - if new_valid_gw_port_attachment: - subnets = self._core_plugin._get_subnets_by_network(context, - new_network) - for subnet in subnets: - self._check_for_dup_router_subnet(context, router_id, - new_network, subnet['id'], - subnet['cidr']) - self._create_router_gw_port(context, router, new_network) - - def _update_router_gw_info(self, context, router_id, info, router=None): - # TODO(salvatore-orlando): guarantee atomic behavior also across - # operations that span beyond the model classes handled by this - # class (e.g.: delete_port) - router = router or self._get_router(context, router_id) - gw_port = router.gw_port - network_id = self._validate_gw_info(context, gw_port, info) - self._delete_current_gw_port(context, router_id, router, network_id) - self._create_gw_port(context, router_id, router, network_id) - - def _ensure_router_not_in_use(self, context, router_id): - admin_ctx = context.elevated() - router = self._get_router(context, router_id) - if self.get_floatingips_count( - admin_ctx, filters={'router_id': [router_id]}): - raise l3.RouterInUse(router_id=router_id) - device_owner = self._get_device_owner(context, router) - device_filter = {'device_id': [router_id], - 'device_owner': [device_owner]} - port_count = self._core_plugin.get_ports_count( - admin_ctx, filters=device_filter) - if port_count: - raise l3.RouterInUse(router_id=router_id) - return router - - def delete_router(self, context, id): - with context.session.begin(subtransactions=True): - router = self._ensure_router_not_in_use(context, id) - - #TODO(nati) Refactor here when we have router insertion model - vpnservice = manager.NeutronManager.get_service_plugins().get( - constants.VPN) - if vpnservice: - vpnservice.check_router_in_use(context, id) - - context.session.delete(router) - - # Delete the gw port after the router has been removed to - # avoid a constraint violation. - device_filter = {'device_id': [id], - 'device_owner': [DEVICE_OWNER_ROUTER_GW]} - ports = self._core_plugin.get_ports(context.elevated(), - filters=device_filter) - if ports: - self._core_plugin._delete_port(context.elevated(), - ports[0]['id']) - - self.l3_rpc_notifier.router_deleted(context, id) - - def get_router(self, context, id, fields=None): - router = self._get_router(context, id) - return self._make_router_dict(router, fields) - - def get_routers(self, context, filters=None, fields=None, - sorts=None, limit=None, marker=None, - page_reverse=False): - marker_obj = self._get_marker_obj(context, 'router', limit, marker) - return self._get_collection(context, Router, - self._make_router_dict, - filters=filters, fields=fields, - sorts=sorts, - limit=limit, - marker_obj=marker_obj, - page_reverse=page_reverse) - - def get_routers_count(self, context, filters=None): - return self._get_collection_count(context, Router, - filters=filters) - - def _check_for_dup_router_subnet(self, context, router_id, - network_id, subnet_id, subnet_cidr): - try: - rport_qry = context.session.query(models_v2.Port) - rports = rport_qry.filter_by(device_id=router_id) - # It's possible these ports are on the same network, but - # different subnets. - new_ipnet = netaddr.IPNetwork(subnet_cidr) - for p in rports: - for ip in p['fixed_ips']: - if ip['subnet_id'] == subnet_id: - msg = (_("Router already has a port on subnet %s") - % subnet_id) - raise n_exc.BadRequest(resource='router', msg=msg) - sub_id = ip['subnet_id'] - cidr = self._core_plugin._get_subnet(context.elevated(), - sub_id)['cidr'] - ipnet = netaddr.IPNetwork(cidr) - match1 = netaddr.all_matching_cidrs(new_ipnet, [cidr]) - match2 = netaddr.all_matching_cidrs(ipnet, [subnet_cidr]) - if match1 or match2: - data = {'subnet_cidr': subnet_cidr, - 'subnet_id': subnet_id, - 'cidr': cidr, - 'sub_id': sub_id} - msg = (_("Cidr %(subnet_cidr)s of subnet " - "%(subnet_id)s overlaps with cidr %(cidr)s " - "of subnet %(sub_id)s") % data) - raise n_exc.BadRequest(resource='router', msg=msg) - except exc.NoResultFound: - pass - - def _get_device_owner(self, context, router=None): - """Get device_owner for the specified router.""" - # NOTE(armando-migliaccio): in the base case this is invariant - return DEVICE_OWNER_ROUTER_INTF - - def _validate_interface_info(self, interface_info): - if not interface_info: - msg = _("Either subnet_id or port_id must be specified") - raise n_exc.BadRequest(resource='router', msg=msg) - port_id_specified = 'port_id' in interface_info - subnet_id_specified = 'subnet_id' in interface_info - if port_id_specified and subnet_id_specified: - msg = _("Cannot specify both subnet-id and port-id") - raise n_exc.BadRequest(resource='router', msg=msg) - return port_id_specified, subnet_id_specified - - def _add_interface_by_port(self, context, router_id, port_id, owner): - with context.session.begin(subtransactions=True): - port = self._core_plugin._get_port(context, port_id) - if port['device_id']: - raise n_exc.PortInUse(net_id=port['network_id'], - port_id=port['id'], - device_id=port['device_id']) - fixed_ips = [ip for ip in port['fixed_ips']] - if len(fixed_ips) != 1: - msg = _('Router port must have exactly one fixed IP') - raise n_exc.BadRequest(resource='router', msg=msg) - subnet_id = fixed_ips[0]['subnet_id'] - subnet = self._core_plugin._get_subnet(context, subnet_id) - self._check_for_dup_router_subnet(context, router_id, - port['network_id'], - subnet['id'], - subnet['cidr']) - port.update({'device_id': router_id, 'device_owner': owner}) - return port - - def _add_interface_by_subnet(self, context, router_id, subnet_id, owner): - subnet = self._core_plugin._get_subnet(context, subnet_id) - if not subnet['gateway_ip']: - msg = _('Subnet for router interface must have a gateway IP') - raise n_exc.BadRequest(resource='router', msg=msg) - self._check_for_dup_router_subnet(context, router_id, - subnet['network_id'], - subnet_id, - subnet['cidr']) - fixed_ip = {'ip_address': subnet['gateway_ip'], - 'subnet_id': subnet['id']} - return self._core_plugin.create_port(context, { - 'port': - {'tenant_id': subnet['tenant_id'], - 'network_id': subnet['network_id'], - 'fixed_ips': [fixed_ip], - 'mac_address': attributes.ATTR_NOT_SPECIFIED, - 'admin_state_up': True, - 'device_id': router_id, - 'device_owner': owner, - 'name': ''}}) - - def add_router_interface(self, context, router_id, interface_info): - add_by_port, add_by_sub = self._validate_interface_info(interface_info) - device_owner = self._get_device_owner(context, router_id) - - if add_by_port: - port = self._add_interface_by_port( - context, router_id, interface_info['port_id'], device_owner) - elif add_by_sub: - port = self._add_interface_by_subnet( - context, router_id, interface_info['subnet_id'], device_owner) - - self.l3_rpc_notifier.routers_updated( - context, [router_id], 'add_router_interface') - info = {'id': router_id, - 'tenant_id': port['tenant_id'], - 'port_id': port['id'], - 'subnet_id': port['fixed_ips'][0]['subnet_id']} - notifier = n_rpc.get_notifier('network') - notifier.info( - context, 'router.interface.create', {'router_interface': info}) - return info - - def _confirm_router_interface_not_in_use(self, context, router_id, - subnet_id): - subnet_db = self._core_plugin._get_subnet(context, subnet_id) - subnet_cidr = netaddr.IPNetwork(subnet_db['cidr']) - fip_qry = context.session.query(FloatingIP) - for fip_db in fip_qry.filter_by(router_id=router_id): - if netaddr.IPAddress(fip_db['fixed_ip_address']) in subnet_cidr: - raise l3.RouterInterfaceInUseByFloatingIP( - router_id=router_id, subnet_id=subnet_id) - - def _remove_interface_by_port(self, context, router_id, - port_id, subnet_id, owner): - port_db = self._core_plugin._get_port(context, port_id) - if not (port_db['device_owner'] == owner and - port_db['device_id'] == router_id): - raise l3.RouterInterfaceNotFound(router_id=router_id, - port_id=port_id) - port_subnet_id = port_db['fixed_ips'][0]['subnet_id'] - if subnet_id and port_subnet_id != subnet_id: - raise n_exc.SubnetMismatchForPort( - port_id=port_id, subnet_id=subnet_id) - subnet = self._core_plugin._get_subnet(context, port_subnet_id) - self._confirm_router_interface_not_in_use( - context, router_id, port_subnet_id) - self._core_plugin.delete_port(context, port_db['id'], - l3_port_check=False) - return (port_db, subnet) - - def _remove_interface_by_subnet(self, context, - router_id, subnet_id, owner): - self._confirm_router_interface_not_in_use( - context, router_id, subnet_id) - subnet = self._core_plugin._get_subnet(context, subnet_id) - - try: - rport_qry = context.session.query(models_v2.Port) - ports = rport_qry.filter_by( - device_id=router_id, - device_owner=owner, - network_id=subnet['network_id']) - - for p in ports: - if p['fixed_ips'][0]['subnet_id'] == subnet_id: - self._core_plugin.delete_port(context, p['id'], - l3_port_check=False) - return (p, subnet) - except exc.NoResultFound: - pass - raise l3.RouterInterfaceNotFoundForSubnet(router_id=router_id, - subnet_id=subnet_id) - - def remove_router_interface(self, context, router_id, interface_info): - if not interface_info: - msg = _("Either subnet_id or port_id must be specified") - raise n_exc.BadRequest(resource='router', msg=msg) - port_id = interface_info.get('port_id') - subnet_id = interface_info.get('subnet_id') - device_owner = self._get_device_owner(context, router_id) - if port_id: - port, subnet = self._remove_interface_by_port(context, router_id, - port_id, subnet_id, - device_owner) - elif subnet_id: - port, subnet = self._remove_interface_by_subnet( - context, router_id, subnet_id, device_owner) - - self.l3_rpc_notifier.routers_updated( - context, [router_id], 'remove_router_interface') - info = {'id': router_id, - 'tenant_id': port['tenant_id'], - 'port_id': port['id'], - 'subnet_id': subnet['id']} - notifier = n_rpc.get_notifier('network') - notifier.info( - context, 'router.interface.delete', {'router_interface': info}) - return info - - def _get_floatingip(self, context, id): - try: - floatingip = self._get_by_id(context, FloatingIP, id) - except exc.NoResultFound: - raise l3.FloatingIPNotFound(floatingip_id=id) - return floatingip - - def _make_floatingip_dict(self, floatingip, fields=None): - res = {'id': floatingip['id'], - 'tenant_id': floatingip['tenant_id'], - 'floating_ip_address': floatingip['floating_ip_address'], - 'floating_network_id': floatingip['floating_network_id'], - 'router_id': floatingip['router_id'], - 'port_id': floatingip['fixed_port_id'], - 'fixed_ip_address': floatingip['fixed_ip_address'], - 'status': floatingip['status']} - return self._fields(res, fields) - - def _get_interface_ports_for_network(self, context, network_id): - router_intf_qry = context.session.query(models_v2.Port) - return router_intf_qry.filter_by( - network_id=network_id, - device_owner=DEVICE_OWNER_ROUTER_INTF) - - def _get_router_for_floatingip(self, context, internal_port, - internal_subnet_id, - external_network_id): - subnet_db = self._core_plugin._get_subnet(context, - internal_subnet_id) - if not subnet_db['gateway_ip']: - msg = (_('Cannot add floating IP to port on subnet %s ' - 'which has no gateway_ip') % internal_subnet_id) - raise n_exc.BadRequest(resource='floatingip', msg=msg) - - router_intf_ports = self._get_interface_ports_for_network( - context, internal_port['network_id']) - - for intf_p in router_intf_ports: - if intf_p['fixed_ips'][0]['subnet_id'] == internal_subnet_id: - router_id = intf_p['device_id'] - router_gw_qry = context.session.query(models_v2.Port) - has_gw_port = router_gw_qry.filter_by( - network_id=external_network_id, - device_id=router_id, - device_owner=DEVICE_OWNER_ROUTER_GW).count() - if has_gw_port: - return router_id - - raise l3.ExternalGatewayForFloatingIPNotFound( - subnet_id=internal_subnet_id, - external_network_id=external_network_id, - port_id=internal_port['id']) - - def _internal_fip_assoc_data(self, context, fip): - """Retrieve internal port data for floating IP. - - Retrieve information concerning the internal port where - the floating IP should be associated to. - """ - internal_port = self._core_plugin._get_port(context, fip['port_id']) - if not internal_port['tenant_id'] == fip['tenant_id']: - port_id = fip['port_id'] - if 'id' in fip: - floatingip_id = fip['id'] - data = {'port_id': port_id, - 'floatingip_id': floatingip_id} - msg = (_('Port %(port_id)s is associated with a different ' - 'tenant than Floating IP %(floatingip_id)s and ' - 'therefore cannot be bound.') % data) - else: - msg = (_('Cannot create floating IP and bind it to ' - 'Port %s, since that port is owned by a ' - 'different tenant.') % port_id) - raise n_exc.BadRequest(resource='floatingip', msg=msg) - - internal_subnet_id = None - if 'fixed_ip_address' in fip and fip['fixed_ip_address']: - internal_ip_address = fip['fixed_ip_address'] - for ip in internal_port['fixed_ips']: - if ip['ip_address'] == internal_ip_address: - internal_subnet_id = ip['subnet_id'] - if not internal_subnet_id: - msg = (_('Port %(id)s does not have fixed ip %(address)s') % - {'id': internal_port['id'], - 'address': internal_ip_address}) - raise n_exc.BadRequest(resource='floatingip', msg=msg) - else: - ips = [ip['ip_address'] for ip in internal_port['fixed_ips']] - if not ips: - msg = (_('Cannot add floating IP to port %s that has' - 'no fixed IP addresses') % internal_port['id']) - raise n_exc.BadRequest(resource='floatingip', msg=msg) - if len(ips) > 1: - msg = (_('Port %s has multiple fixed IPs. Must provide' - ' a specific IP when assigning a floating IP') % - internal_port['id']) - raise n_exc.BadRequest(resource='floatingip', msg=msg) - internal_ip_address = internal_port['fixed_ips'][0]['ip_address'] - internal_subnet_id = internal_port['fixed_ips'][0]['subnet_id'] - return internal_port, internal_subnet_id, internal_ip_address - - def get_assoc_data(self, context, fip, floating_network_id): - """Determine/extract data associated with the internal port. - - When a floating IP is associated with an internal port, - we need to extract/determine some data associated with the - internal port, including the internal_ip_address, and router_id. - We also need to confirm that this internal port is owned by the - tenant who owns the floating IP. - """ - (internal_port, internal_subnet_id, - internal_ip_address) = self._internal_fip_assoc_data(context, fip) - router_id = self._get_router_for_floatingip(context, - internal_port, - internal_subnet_id, - floating_network_id) - # confirm that this router has a floating - # ip enabled gateway with support for this floating IP network - try: - port_qry = context.elevated().session.query(models_v2.Port) - port_qry.filter_by( - network_id=floating_network_id, - device_id=router_id, - device_owner=DEVICE_OWNER_ROUTER_GW).one() - except exc.NoResultFound: - raise l3.ExternalGatewayForFloatingIPNotFound( - subnet_id=internal_subnet_id, - port_id=internal_port['id']) - - return (fip['port_id'], internal_ip_address, router_id) - - def _update_fip_assoc(self, context, fip, floatingip_db, external_port): - previous_router_id = floatingip_db.router_id - port_id = internal_ip_address = router_id = None - if (('fixed_ip_address' in fip and fip['fixed_ip_address']) and - not ('port_id' in fip and fip['port_id'])): - msg = _("fixed_ip_address cannot be specified without a port_id") - raise n_exc.BadRequest(resource='floatingip', msg=msg) - if 'port_id' in fip and fip['port_id']: - port_id, internal_ip_address, router_id = self.get_assoc_data( - context, - fip, - floatingip_db['floating_network_id']) - fip_qry = context.session.query(FloatingIP) - try: - fip_qry.filter_by( - fixed_port_id=fip['port_id'], - floating_network_id=floatingip_db['floating_network_id'], - fixed_ip_address=internal_ip_address).one() - raise l3.FloatingIPPortAlreadyAssociated( - port_id=fip['port_id'], - fip_id=floatingip_db['id'], - floating_ip_address=floatingip_db['floating_ip_address'], - fixed_ip=internal_ip_address, - net_id=floatingip_db['floating_network_id']) - except exc.NoResultFound: - pass - floatingip_db.update({'fixed_ip_address': internal_ip_address, - 'fixed_port_id': port_id, - 'router_id': router_id, - 'last_known_router_id': previous_router_id}) - - def create_floatingip( - self, context, floatingip, - initial_status=l3_constants.FLOATINGIP_STATUS_ACTIVE): - fip = floatingip['floatingip'] - tenant_id = self._get_tenant_id_for_create(context, fip) - fip_id = uuidutils.generate_uuid() - - f_net_id = fip['floating_network_id'] - if not self._core_plugin._network_is_external(context, f_net_id): - msg = _("Network %s is not a valid external network") % f_net_id - raise n_exc.BadRequest(resource='floatingip', msg=msg) - - with context.session.begin(subtransactions=True): - # This external port is never exposed to the tenant. - # it is used purely for internal system and admin use when - # managing floating IPs. - external_port = self._core_plugin.create_port(context.elevated(), { - 'port': - {'tenant_id': '', # tenant intentionally not set - 'network_id': f_net_id, - 'mac_address': attributes.ATTR_NOT_SPECIFIED, - 'fixed_ips': attributes.ATTR_NOT_SPECIFIED, - 'admin_state_up': True, - 'device_id': fip_id, - 'device_owner': DEVICE_OWNER_FLOATINGIP, - 'name': ''}}) - # Ensure IP addresses are allocated on external port - if not external_port['fixed_ips']: - raise n_exc.ExternalIpAddressExhausted(net_id=f_net_id) - - floating_fixed_ip = external_port['fixed_ips'][0] - floating_ip_address = floating_fixed_ip['ip_address'] - floatingip_db = FloatingIP( - id=fip_id, - tenant_id=tenant_id, - status=initial_status, - floating_network_id=fip['floating_network_id'], - floating_ip_address=floating_ip_address, - floating_port_id=external_port['id']) - fip['tenant_id'] = tenant_id - # Update association with internal port - # and define external IP address - self._update_fip_assoc(context, fip, - floatingip_db, external_port) - context.session.add(floatingip_db) - - router_id = floatingip_db['router_id'] - if router_id: - self.l3_rpc_notifier.routers_updated( - context, [router_id], - 'create_floatingip') - return self._make_floatingip_dict(floatingip_db) - - def update_floatingip(self, context, id, floatingip): - fip = floatingip['floatingip'] - with context.session.begin(subtransactions=True): - floatingip_db = self._get_floatingip(context, id) - fip['tenant_id'] = floatingip_db['tenant_id'] - fip['id'] = id - fip_port_id = floatingip_db['floating_port_id'] - before_router_id = floatingip_db['router_id'] - self._update_fip_assoc(context, fip, floatingip_db, - self._core_plugin.get_port( - context.elevated(), fip_port_id)) - router_ids = [] - if before_router_id: - router_ids.append(before_router_id) - router_id = floatingip_db['router_id'] - if router_id and router_id != before_router_id: - router_ids.append(router_id) - if router_ids: - self.l3_rpc_notifier.routers_updated( - context, router_ids, 'update_floatingip') - return self._make_floatingip_dict(floatingip_db) - - def update_floatingip_status(self, context, floatingip_id, status): - """Update operational status for floating IP in neutron DB.""" - fip_query = self._model_query(context, FloatingIP).filter( - FloatingIP.id == floatingip_id) - fip_query.update({'status': status}, synchronize_session=False) - - def delete_floatingip(self, context, id): - floatingip = self._get_floatingip(context, id) - router_id = floatingip['router_id'] - with context.session.begin(subtransactions=True): - context.session.delete(floatingip) - self._core_plugin.delete_port(context.elevated(), - floatingip['floating_port_id'], - l3_port_check=False) - if router_id: - self.l3_rpc_notifier.routers_updated( - context, [router_id], - 'delete_floatingip') - - def get_floatingip(self, context, id, fields=None): - floatingip = self._get_floatingip(context, id) - return self._make_floatingip_dict(floatingip, fields) - - def get_floatingips(self, context, filters=None, fields=None, - sorts=None, limit=None, marker=None, - page_reverse=False): - marker_obj = self._get_marker_obj(context, 'floatingip', limit, - marker) - if filters is not None: - for key, val in API_TO_DB_COLUMN_MAP.iteritems(): - if key in filters: - filters[val] = filters.pop(key) - - return self._get_collection(context, FloatingIP, - self._make_floatingip_dict, - filters=filters, fields=fields, - sorts=sorts, - limit=limit, - marker_obj=marker_obj, - page_reverse=page_reverse) - - def delete_disassociated_floatingips(self, context, network_id): - query = self._model_query(context, FloatingIP) - query = query.filter_by(floating_network_id=network_id, - fixed_port_id=None, - router_id=None) - for fip in query: - self.delete_floatingip(context, fip.id) - - def get_floatingips_count(self, context, filters=None): - return self._get_collection_count(context, FloatingIP, - filters=filters) - - def prevent_l3_port_deletion(self, context, port_id): - """Checks to make sure a port is allowed to be deleted. - - Raises an exception if this is not the case. This should be called by - any plugin when the API requests the deletion of a port, since some - ports for L3 are not intended to be deleted directly via a DELETE - to /ports, but rather via other API calls that perform the proper - deletion checks. - """ - port_db = self._core_plugin._get_port(context, port_id) - if port_db['device_owner'] in self.router_device_owners: - # Raise port in use only if the port has IP addresses - # Otherwise it's a stale port that can be removed - fixed_ips = port_db['fixed_ips'] - if fixed_ips: - raise l3.L3PortInUse(port_id=port_id, - device_owner=port_db['device_owner']) - else: - LOG.debug(_("Port %(port_id)s has owner %(port_owner)s, but " - "no IP address, so it can be deleted"), - {'port_id': port_db['id'], - 'port_owner': port_db['device_owner']}) - - def disassociate_floatingips(self, context, port_id): - router_ids = set() - - with context.session.begin(subtransactions=True): - fip_qry = context.session.query(FloatingIP) - floating_ips = fip_qry.filter_by(fixed_port_id=port_id) - for floating_ip in floating_ips: - router_ids.add(floating_ip['router_id']) - floating_ip.update({'fixed_port_id': None, - 'fixed_ip_address': None, - 'router_id': None}) - - if router_ids: - self.l3_rpc_notifier.routers_updated( - context, list(router_ids), - 'disassociate_floatingips') - - def _build_routers_list(self, routers, gw_ports): - gw_port_id_gw_port_dict = dict((gw_port['id'], gw_port) - for gw_port in gw_ports) - for router in routers: - gw_port_id = router['gw_port_id'] - if gw_port_id: - router['gw_port'] = gw_port_id_gw_port_dict[gw_port_id] - return routers - - def _get_sync_routers(self, context, router_ids=None, active=None): - """Query routers and their gw ports for l3 agent. - - Query routers with the router_ids. The gateway ports, if any, - will be queried too. - l3 agent has an option to deal with only one router id. In addition, - when we need to notify the agent the data about only one router - (when modification of router, its interfaces, gw_port and floatingips), - we will have router_ids. - @param router_ids: the list of router ids which we want to query. - if it is None, all of routers will be queried. - @return: a list of dicted routers with dicted gw_port populated if any - """ - filters = {'id': router_ids} if router_ids else {} - if active is not None: - filters['admin_state_up'] = [active] - router_dicts = self.get_routers(context, filters=filters) - gw_port_ids = [] - if not router_dicts: - return [] - for router_dict in router_dicts: - gw_port_id = router_dict['gw_port_id'] - if gw_port_id: - gw_port_ids.append(gw_port_id) - gw_ports = [] - if gw_port_ids: - gw_ports = self.get_sync_gw_ports(context, gw_port_ids) - return self._build_routers_list(router_dicts, gw_ports) - - def _get_sync_floating_ips(self, context, router_ids): - """Query floating_ips that relate to list of router_ids.""" - if not router_ids: - return [] - return self.get_floatingips(context, {'router_id': router_ids}) - - def get_sync_gw_ports(self, context, gw_port_ids): - if not gw_port_ids: - return [] - filters = {'id': gw_port_ids} - gw_ports = self._core_plugin.get_ports(context, filters) - if gw_ports: - self._populate_subnet_for_ports(context, gw_ports) - return gw_ports - - def get_sync_interfaces(self, context, router_ids, device_owners=None): - """Query router interfaces that relate to list of router_ids.""" - device_owners = device_owners or [DEVICE_OWNER_ROUTER_INTF] - if not router_ids: - return [] - filters = {'device_id': router_ids, - 'device_owner': device_owners} - interfaces = self._core_plugin.get_ports(context, filters) - if interfaces: - self._populate_subnet_for_ports(context, interfaces) - return interfaces - - def _populate_subnet_for_ports(self, context, ports): - """Populate ports with subnet. - - These ports already have fixed_ips populated. - """ - if not ports: - return - - def each_port_with_ip(): - for port in ports: - fixed_ips = port.get('fixed_ips', []) - if len(fixed_ips) > 1: - LOG.info(_("Ignoring multiple IPs on router port %s"), - port['id']) - continue - elif not fixed_ips: - # Skip ports without IPs, which can occur if a subnet - # attached to a router is deleted - LOG.info(_("Skipping port %s as no IP is configure on it"), - port['id']) - continue - yield (port, fixed_ips[0]) - - network_ids = set(p['network_id'] for p, _ in each_port_with_ip()) - filters = {'network_id': [id for id in network_ids]} - fields = ['id', 'cidr', 'gateway_ip', 'network_id'] - - subnets_by_network = dict((id, []) for id in network_ids) - for subnet in self._core_plugin.get_subnets(context, filters, fields): - subnets_by_network[subnet['network_id']].append(subnet) - - for port, fixed_ip in each_port_with_ip(): - port['extra_subnets'] = [] - for subnet in subnets_by_network[port['network_id']]: - subnet_info = {'id': subnet['id'], - 'cidr': subnet['cidr'], - 'gateway_ip': subnet['gateway_ip']} - - if subnet['id'] == fixed_ip['subnet_id']: - port['subnet'] = subnet_info - else: - port['extra_subnets'].append(subnet_info) - - def _process_sync_data(self, routers, interfaces, floating_ips): - routers_dict = {} - for router in routers: - routers_dict[router['id']] = router - for floating_ip in floating_ips: - router = routers_dict.get(floating_ip['router_id']) - if router: - router_floatingips = router.get(l3_constants.FLOATINGIP_KEY, - []) - router_floatingips.append(floating_ip) - router[l3_constants.FLOATINGIP_KEY] = router_floatingips - for interface in interfaces: - router = routers_dict.get(interface['device_id']) - if router: - router_interfaces = router.get(l3_constants.INTERFACE_KEY, []) - router_interfaces.append(interface) - router[l3_constants.INTERFACE_KEY] = router_interfaces - return routers_dict.values() - - def _get_router_info_list(self, context, router_ids=None, active=None, - device_owners=None): - """Query routers and their related floating_ips, interfaces.""" - with context.session.begin(subtransactions=True): - routers = self._get_sync_routers(context, - router_ids=router_ids, - active=active) - router_ids = [router['id'] for router in routers] - interfaces = self.get_sync_interfaces( - context, router_ids, device_owners) - floating_ips = self._get_sync_floating_ips(context, router_ids) - return (routers, interfaces, floating_ips) - - def get_sync_data(self, context, router_ids=None, active=None): - routers, interfaces, floating_ips = self._get_router_info_list( - context, router_ids=router_ids, active=active) - return self._process_sync_data(routers, interfaces, floating_ips) diff --git a/neutron/db/l3_gwmode_db.py b/neutron/db/l3_gwmode_db.py deleted file mode 100644 index 4c184019f..000000000 --- a/neutron/db/l3_gwmode_db.py +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright 2013 VMware, 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. -# - -import sqlalchemy as sa - -from neutron.db import db_base_plugin_v2 -from neutron.db import l3_db -from neutron.extensions import l3 -from neutron.openstack.common import log as logging - - -LOG = logging.getLogger(__name__) -EXTERNAL_GW_INFO = l3.EXTERNAL_GW_INFO - -# Modify the Router Data Model adding the enable_snat attribute -setattr(l3_db.Router, 'enable_snat', - sa.Column(sa.Boolean, default=True, nullable=False)) - - -class L3_NAT_db_mixin(l3_db.L3_NAT_db_mixin): - """Mixin class to add configurable gateway modes.""" - - # Register dict extend functions for ports and networks - db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - l3.ROUTERS, ['_extend_router_dict_gw_mode']) - - def _extend_router_dict_gw_mode(self, router_res, router_db): - if router_db.gw_port_id: - nw_id = router_db.gw_port['network_id'] - router_res[EXTERNAL_GW_INFO] = { - 'network_id': nw_id, - 'enable_snat': router_db.enable_snat} - - def _update_router_gw_info(self, context, router_id, info, router=None): - # Load the router only if necessary - if not router: - router = self._get_router(context, router_id) - # if enable_snat is not specified use the value - # stored in the database (default:True) - enable_snat = not info or info.get('enable_snat', router.enable_snat) - with context.session.begin(subtransactions=True): - router.enable_snat = enable_snat - - # Calls superclass, pass router db object for avoiding re-loading - super(L3_NAT_db_mixin, self)._update_router_gw_info( - context, router_id, info, router=router) - # Returning the router might come back useful if this - # method is overriden in child classes - return router - - def _build_routers_list(self, routers, gw_ports): - gw_port_id_gw_port_dict = {} - for gw_port in gw_ports: - gw_port_id_gw_port_dict[gw_port['id']] = gw_port - for rtr in routers: - gw_port_id = rtr['gw_port_id'] - if gw_port_id: - rtr['gw_port'] = gw_port_id_gw_port_dict[gw_port_id] - # Add enable_snat key - rtr['enable_snat'] = rtr[EXTERNAL_GW_INFO]['enable_snat'] - return routers diff --git a/neutron/db/l3_rpc_base.py b/neutron/db/l3_rpc_base.py deleted file mode 100644 index d86d95698..000000000 --- a/neutron/db/l3_rpc_base.py +++ /dev/null @@ -1,128 +0,0 @@ -# Copyright (c) 2012 OpenStack Foundation. -# -# 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 oslo.config import cfg - -from neutron.common import constants -from neutron.common import utils -from neutron import context as neutron_context -from neutron.extensions import l3 -from neutron.extensions import portbindings -from neutron import manager -from neutron.openstack.common import jsonutils -from neutron.openstack.common import log as logging -from neutron.plugins.common import constants as plugin_constants - - -LOG = logging.getLogger(__name__) - - -class L3RpcCallbackMixin(object): - """A mix-in that enable L3 agent rpc support in plugin implementations.""" - - def sync_routers(self, context, **kwargs): - """Sync routers according to filters to a specific agent. - - @param context: contain user information - @param kwargs: host, router_ids - @return: a list of routers - with their interfaces and floating_ips - """ - router_ids = kwargs.get('router_ids') - host = kwargs.get('host') - context = neutron_context.get_admin_context() - l3plugin = manager.NeutronManager.get_service_plugins()[ - plugin_constants.L3_ROUTER_NAT] - if not l3plugin: - routers = {} - LOG.error(_('No plugin for L3 routing registered! Will reply ' - 'to l3 agent with empty router dictionary.')) - elif utils.is_extension_supported( - l3plugin, constants.L3_AGENT_SCHEDULER_EXT_ALIAS): - if cfg.CONF.router_auto_schedule: - l3plugin.auto_schedule_routers(context, host, router_ids) - routers = l3plugin.list_active_sync_routers_on_active_l3_agent( - context, host, router_ids) - else: - routers = l3plugin.get_sync_data(context, router_ids) - plugin = manager.NeutronManager.get_plugin() - if utils.is_extension_supported( - plugin, constants.PORT_BINDING_EXT_ALIAS): - self._ensure_host_set_on_ports(context, plugin, host, routers) - LOG.debug(_("Routers returned to l3 agent:\n %s"), - jsonutils.dumps(routers, indent=5)) - return routers - - def _ensure_host_set_on_ports(self, context, plugin, host, routers): - for router in routers: - LOG.debug(_("Checking router: %(id)s for host: %(host)s"), - {'id': router['id'], 'host': host}) - self._ensure_host_set_on_port(context, plugin, host, - router.get('gw_port')) - for interface in router.get(constants.INTERFACE_KEY, []): - self._ensure_host_set_on_port(context, plugin, host, - interface) - - def _ensure_host_set_on_port(self, context, plugin, host, port): - if (port and - (port.get(portbindings.HOST_ID) != host or - port.get(portbindings.VIF_TYPE) == - portbindings.VIF_TYPE_BINDING_FAILED)): - plugin.update_port(context, port['id'], - {'port': {portbindings.HOST_ID: host}}) - - def get_external_network_id(self, context, **kwargs): - """Get one external network id for l3 agent. - - l3 agent expects only on external network when it performs - this query. - """ - context = neutron_context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() - net_id = plugin.get_external_network_id(context) - LOG.debug(_("External network ID returned to l3 agent: %s"), - net_id) - return net_id - - def update_floatingip_statuses(self, context, router_id, fip_statuses): - """Update operational status for a floating IP.""" - l3_plugin = manager.NeutronManager.get_service_plugins()[ - plugin_constants.L3_ROUTER_NAT] - with context.session.begin(subtransactions=True): - for (floatingip_id, status) in fip_statuses.iteritems(): - LOG.debug(_("New status for floating IP %(floatingip_id)s: " - "%(status)s"), {'floatingip_id': floatingip_id, - 'status': status}) - try: - l3_plugin.update_floatingip_status(context, - floatingip_id, - status) - except l3.FloatingIPNotFound: - LOG.debug(_("Floating IP: %s no longer present."), - floatingip_id) - # Find all floating IPs known to have been the given router - # for which an update was not received. Set them DOWN mercilessly - # This situation might occur for some asynchronous backends if - # notifications were missed - known_router_fips = l3_plugin.get_floatingips( - context, {'last_known_router_id': [router_id]}) - # Consider only floating ips which were disassociated in the API - # FIXME(salv-orlando): Filtering in code should be avoided. - # the plugin should offer a way to specify a null filter - fips_to_disable = (fip['id'] for fip in known_router_fips - if not fip['router_id']) - for fip_id in fips_to_disable: - l3_plugin.update_floatingip_status( - context, fip_id, constants.FLOATINGIP_STATUS_DOWN) diff --git a/neutron/db/loadbalancer/__init__.py b/neutron/db/loadbalancer/__init__.py deleted file mode 100644 index cae279d0a..000000000 --- a/neutron/db/loadbalancer/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 OpenStack Foundation -# -# 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. diff --git a/neutron/db/loadbalancer/loadbalancer_db.py b/neutron/db/loadbalancer/loadbalancer_db.py deleted file mode 100644 index 9c81a0664..000000000 --- a/neutron/db/loadbalancer/loadbalancer_db.py +++ /dev/null @@ -1,802 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation. 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. -# - -import sqlalchemy as sa -from sqlalchemy import orm -from sqlalchemy.orm import exc -from sqlalchemy.orm import validates - -from neutron.api.v2 import attributes -from neutron.common import exceptions as n_exc -from neutron.db import db_base_plugin_v2 as base_db -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.db import servicetype_db as st_db -from neutron.extensions import loadbalancer -from neutron import manager -from neutron.openstack.common.db import exception -from neutron.openstack.common import excutils -from neutron.openstack.common import log as logging -from neutron.openstack.common import uuidutils -from neutron.plugins.common import constants -from neutron.services.loadbalancer import constants as lb_const - - -LOG = logging.getLogger(__name__) - - -class SessionPersistence(model_base.BASEV2): - - vip_id = sa.Column(sa.String(36), - sa.ForeignKey("vips.id"), - primary_key=True) - type = sa.Column(sa.Enum("SOURCE_IP", - "HTTP_COOKIE", - "APP_COOKIE", - name="sesssionpersistences_type"), - nullable=False) - cookie_name = sa.Column(sa.String(1024)) - - -class PoolStatistics(model_base.BASEV2): - """Represents pool statistics.""" - - pool_id = sa.Column(sa.String(36), sa.ForeignKey("pools.id"), - primary_key=True) - bytes_in = sa.Column(sa.BigInteger, nullable=False) - bytes_out = sa.Column(sa.BigInteger, nullable=False) - active_connections = sa.Column(sa.BigInteger, nullable=False) - total_connections = sa.Column(sa.BigInteger, nullable=False) - - @validates('bytes_in', 'bytes_out', - 'active_connections', 'total_connections') - def validate_non_negative_int(self, key, value): - if value < 0: - data = {'key': key, 'value': value} - raise ValueError(_('The %(key)s field can not have ' - 'negative value. ' - 'Current value is %(value)d.') % data) - return value - - -class Vip(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant, - models_v2.HasStatusDescription): - """Represents a v2 neutron loadbalancer vip.""" - - name = sa.Column(sa.String(255)) - description = sa.Column(sa.String(255)) - port_id = sa.Column(sa.String(36), sa.ForeignKey('ports.id')) - protocol_port = sa.Column(sa.Integer, nullable=False) - protocol = sa.Column(sa.Enum("HTTP", "HTTPS", "TCP", name="lb_protocols"), - nullable=False) - pool_id = sa.Column(sa.String(36), nullable=False, unique=True) - session_persistence = orm.relationship(SessionPersistence, - uselist=False, - backref="vips", - cascade="all, delete-orphan") - admin_state_up = sa.Column(sa.Boolean(), nullable=False) - connection_limit = sa.Column(sa.Integer) - port = orm.relationship(models_v2.Port) - - -class Member(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant, - models_v2.HasStatusDescription): - """Represents a v2 neutron loadbalancer member.""" - - __table_args__ = ( - sa.schema.UniqueConstraint('pool_id', 'address', 'protocol_port', - name='uniq_member0pool_id0address0port'), - ) - pool_id = sa.Column(sa.String(36), sa.ForeignKey("pools.id"), - nullable=False) - address = sa.Column(sa.String(64), nullable=False) - protocol_port = sa.Column(sa.Integer, nullable=False) - weight = sa.Column(sa.Integer, nullable=False) - admin_state_up = sa.Column(sa.Boolean(), nullable=False) - - -class Pool(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant, - models_v2.HasStatusDescription): - """Represents a v2 neutron loadbalancer pool.""" - - vip_id = sa.Column(sa.String(36), sa.ForeignKey("vips.id")) - name = sa.Column(sa.String(255)) - description = sa.Column(sa.String(255)) - subnet_id = sa.Column(sa.String(36), nullable=False) - protocol = sa.Column(sa.Enum("HTTP", "HTTPS", "TCP", name="lb_protocols"), - nullable=False) - lb_method = sa.Column(sa.Enum("ROUND_ROBIN", - "LEAST_CONNECTIONS", - "SOURCE_IP", - name="pools_lb_method"), - nullable=False) - admin_state_up = sa.Column(sa.Boolean(), nullable=False) - stats = orm.relationship(PoolStatistics, - uselist=False, - backref="pools", - cascade="all, delete-orphan") - members = orm.relationship(Member, backref="pools", - cascade="all, delete-orphan") - monitors = orm.relationship("PoolMonitorAssociation", backref="pools", - cascade="all, delete-orphan") - vip = orm.relationship(Vip, backref='pool') - - provider = orm.relationship( - st_db.ProviderResourceAssociation, - uselist=False, - lazy="joined", - primaryjoin="Pool.id==ProviderResourceAssociation.resource_id", - foreign_keys=[st_db.ProviderResourceAssociation.resource_id] - ) - - -class HealthMonitor(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): - """Represents a v2 neutron loadbalancer healthmonitor.""" - - type = sa.Column(sa.Enum("PING", "TCP", "HTTP", "HTTPS", - name="healthmontiors_type"), - nullable=False) - delay = sa.Column(sa.Integer, nullable=False) - timeout = sa.Column(sa.Integer, nullable=False) - max_retries = sa.Column(sa.Integer, nullable=False) - http_method = sa.Column(sa.String(16)) - url_path = sa.Column(sa.String(255)) - expected_codes = sa.Column(sa.String(64)) - admin_state_up = sa.Column(sa.Boolean(), nullable=False) - - pools = orm.relationship( - "PoolMonitorAssociation", backref="healthmonitor", - cascade="all", lazy="joined" - ) - - -class PoolMonitorAssociation(model_base.BASEV2, - models_v2.HasStatusDescription): - """Many-to-many association between pool and healthMonitor classes.""" - - pool_id = sa.Column(sa.String(36), - sa.ForeignKey("pools.id"), - primary_key=True) - monitor_id = sa.Column(sa.String(36), - sa.ForeignKey("healthmonitors.id"), - primary_key=True) - - -class LoadBalancerPluginDb(loadbalancer.LoadBalancerPluginBase, - base_db.CommonDbMixin): - """Wraps loadbalancer with SQLAlchemy models. - - A class that wraps the implementation of the Neutron loadbalancer - plugin database access interface using SQLAlchemy models. - """ - - @property - def _core_plugin(self): - return manager.NeutronManager.get_plugin() - - def update_status(self, context, model, id, status, - status_description=None): - with context.session.begin(subtransactions=True): - if issubclass(model, Vip): - try: - v_db = (self._model_query(context, model). - filter(model.id == id). - options(orm.noload('port')). - one()) - except exc.NoResultFound: - raise loadbalancer.VipNotFound(vip_id=id) - else: - v_db = self._get_resource(context, model, id) - if v_db.status != status: - v_db.status = status - # update status_description in two cases: - # - new value is passed - # - old value is not None (needs to be updated anyway) - if status_description or v_db['status_description']: - v_db.status_description = status_description - - def _get_resource(self, context, model, id): - try: - r = self._get_by_id(context, model, id) - except exc.NoResultFound: - with excutils.save_and_reraise_exception(reraise=False) as ctx: - if issubclass(model, Vip): - raise loadbalancer.VipNotFound(vip_id=id) - elif issubclass(model, Pool): - raise loadbalancer.PoolNotFound(pool_id=id) - elif issubclass(model, Member): - raise loadbalancer.MemberNotFound(member_id=id) - elif issubclass(model, HealthMonitor): - raise loadbalancer.HealthMonitorNotFound(monitor_id=id) - ctx.reraise = True - return r - - def assert_modification_allowed(self, obj): - status = getattr(obj, 'status', None) - - if status == constants.PENDING_DELETE: - raise loadbalancer.StateInvalid(id=id, state=status) - - ######################################################## - # VIP DB access - def _make_vip_dict(self, vip, fields=None): - fixed_ip = (vip.port.fixed_ips or [{}])[0] - - res = {'id': vip['id'], - 'tenant_id': vip['tenant_id'], - 'name': vip['name'], - 'description': vip['description'], - 'subnet_id': fixed_ip.get('subnet_id'), - 'address': fixed_ip.get('ip_address'), - 'port_id': vip['port_id'], - 'protocol_port': vip['protocol_port'], - 'protocol': vip['protocol'], - 'pool_id': vip['pool_id'], - 'session_persistence': None, - 'connection_limit': vip['connection_limit'], - 'admin_state_up': vip['admin_state_up'], - 'status': vip['status'], - 'status_description': vip['status_description']} - - if vip['session_persistence']: - s_p = { - 'type': vip['session_persistence']['type'] - } - - if vip['session_persistence']['type'] == 'APP_COOKIE': - s_p['cookie_name'] = vip['session_persistence']['cookie_name'] - - res['session_persistence'] = s_p - - return self._fields(res, fields) - - def _check_session_persistence_info(self, info): - """Performs sanity check on session persistence info. - - :param info: Session persistence info - """ - if info['type'] == 'APP_COOKIE': - if not info.get('cookie_name'): - raise ValueError(_("'cookie_name' should be specified for this" - " type of session persistence.")) - else: - if 'cookie_name' in info: - raise ValueError(_("'cookie_name' is not allowed for this type" - " of session persistence")) - - def _create_session_persistence_db(self, session_info, vip_id): - self._check_session_persistence_info(session_info) - - sesspersist_db = SessionPersistence( - type=session_info['type'], - cookie_name=session_info.get('cookie_name'), - vip_id=vip_id) - return sesspersist_db - - def _update_vip_session_persistence(self, context, vip_id, info): - self._check_session_persistence_info(info) - - vip = self._get_resource(context, Vip, vip_id) - - with context.session.begin(subtransactions=True): - # Update sessionPersistence table - sess_qry = context.session.query(SessionPersistence) - sesspersist_db = sess_qry.filter_by(vip_id=vip_id).first() - - # Insert a None cookie_info if it is not present to overwrite an - # an existing value in the database. - if 'cookie_name' not in info: - info['cookie_name'] = None - - if sesspersist_db: - sesspersist_db.update(info) - else: - sesspersist_db = SessionPersistence( - type=info['type'], - cookie_name=info['cookie_name'], - vip_id=vip_id) - context.session.add(sesspersist_db) - # Update vip table - vip.session_persistence = sesspersist_db - context.session.add(vip) - - def _delete_session_persistence(self, context, vip_id): - with context.session.begin(subtransactions=True): - sess_qry = context.session.query(SessionPersistence) - sess_qry.filter_by(vip_id=vip_id).delete() - - def _create_port_for_vip(self, context, vip_db, subnet_id, ip_address): - # resolve subnet and create port - subnet = self._core_plugin.get_subnet(context, subnet_id) - fixed_ip = {'subnet_id': subnet['id']} - if ip_address and ip_address != attributes.ATTR_NOT_SPECIFIED: - fixed_ip['ip_address'] = ip_address - - port_data = { - 'tenant_id': vip_db.tenant_id, - 'name': 'vip-' + vip_db.id, - 'network_id': subnet['network_id'], - 'mac_address': attributes.ATTR_NOT_SPECIFIED, - 'admin_state_up': False, - 'device_id': '', - 'device_owner': '', - 'fixed_ips': [fixed_ip] - } - - port = self._core_plugin.create_port(context, {'port': port_data}) - vip_db.port_id = port['id'] - - def create_vip(self, context, vip): - v = vip['vip'] - tenant_id = self._get_tenant_id_for_create(context, v) - - with context.session.begin(subtransactions=True): - if v['pool_id']: - pool = self._get_resource(context, Pool, v['pool_id']) - # validate that the pool has same tenant - if pool['tenant_id'] != tenant_id: - raise n_exc.NotAuthorized() - # validate that the pool has same protocol - if pool['protocol'] != v['protocol']: - raise loadbalancer.ProtocolMismatch( - vip_proto=v['protocol'], - pool_proto=pool['protocol']) - if pool['status'] == constants.PENDING_DELETE: - raise loadbalancer.StateInvalid(state=pool['status'], - id=pool['id']) - else: - pool = None - - vip_db = Vip(id=uuidutils.generate_uuid(), - tenant_id=tenant_id, - name=v['name'], - description=v['description'], - port_id=None, - protocol_port=v['protocol_port'], - protocol=v['protocol'], - pool_id=v['pool_id'], - connection_limit=v['connection_limit'], - admin_state_up=v['admin_state_up'], - status=constants.PENDING_CREATE) - - session_info = v['session_persistence'] - - if session_info: - s_p = self._create_session_persistence_db( - session_info, - vip_db['id']) - vip_db.session_persistence = s_p - - try: - context.session.add(vip_db) - context.session.flush() - except exception.DBDuplicateEntry: - raise loadbalancer.VipExists(pool_id=v['pool_id']) - - # create a port to reserve address for IPAM - self._create_port_for_vip( - context, - vip_db, - v['subnet_id'], - v.get('address') - ) - - if pool: - pool['vip_id'] = vip_db['id'] - - return self._make_vip_dict(vip_db) - - def update_vip(self, context, id, vip): - v = vip['vip'] - - sess_persist = v.pop('session_persistence', None) - with context.session.begin(subtransactions=True): - vip_db = self._get_resource(context, Vip, id) - - self.assert_modification_allowed(vip_db) - - if sess_persist: - self._update_vip_session_persistence(context, id, sess_persist) - else: - self._delete_session_persistence(context, id) - - if v: - try: - # in case new pool already has a vip - # update will raise integrity error at first query - old_pool_id = vip_db['pool_id'] - vip_db.update(v) - # If the pool_id is changed, we need to update - # the associated pools - if 'pool_id' in v: - new_pool = self._get_resource(context, Pool, - v['pool_id']) - self.assert_modification_allowed(new_pool) - - # check that the pool matches the tenant_id - if new_pool['tenant_id'] != vip_db['tenant_id']: - raise n_exc.NotAuthorized() - # validate that the pool has same protocol - if new_pool['protocol'] != vip_db['protocol']: - raise loadbalancer.ProtocolMismatch( - vip_proto=vip_db['protocol'], - pool_proto=new_pool['protocol']) - if new_pool['status'] == constants.PENDING_DELETE: - raise loadbalancer.StateInvalid( - state=new_pool['status'], - id=new_pool['id']) - - if old_pool_id: - old_pool = self._get_resource( - context, - Pool, - old_pool_id - ) - old_pool['vip_id'] = None - - new_pool['vip_id'] = vip_db['id'] - except exception.DBDuplicateEntry: - raise loadbalancer.VipExists(pool_id=v['pool_id']) - - return self._make_vip_dict(vip_db) - - def delete_vip(self, context, id): - with context.session.begin(subtransactions=True): - vip = self._get_resource(context, Vip, id) - qry = context.session.query(Pool) - for pool in qry.filter_by(vip_id=id): - pool.update({"vip_id": None}) - - context.session.delete(vip) - if vip.port: # this is a Neutron port - self._core_plugin.delete_port(context, vip.port.id) - - def get_vip(self, context, id, fields=None): - vip = self._get_resource(context, Vip, id) - return self._make_vip_dict(vip, fields) - - def get_vips(self, context, filters=None, fields=None): - return self._get_collection(context, Vip, - self._make_vip_dict, - filters=filters, fields=fields) - - ######################################################## - # Pool DB access - def _make_pool_dict(self, pool, fields=None): - res = {'id': pool['id'], - 'tenant_id': pool['tenant_id'], - 'name': pool['name'], - 'description': pool['description'], - 'subnet_id': pool['subnet_id'], - 'protocol': pool['protocol'], - 'vip_id': pool['vip_id'], - 'lb_method': pool['lb_method'], - 'admin_state_up': pool['admin_state_up'], - 'status': pool['status'], - 'status_description': pool['status_description'], - 'provider': '' - } - - if pool.provider: - res['provider'] = pool.provider.provider_name - - # Get the associated members - res['members'] = [member['id'] for member in pool['members']] - - # Get the associated health_monitors - res['health_monitors'] = [ - monitor['monitor_id'] for monitor in pool['monitors']] - res['health_monitors_status'] = [ - {'monitor_id': monitor['monitor_id'], - 'status': monitor['status'], - 'status_description': monitor['status_description']} - for monitor in pool['monitors']] - return self._fields(res, fields) - - def update_pool_stats(self, context, pool_id, data=None): - """Update a pool with new stats structure.""" - data = data or {} - with context.session.begin(subtransactions=True): - pool_db = self._get_resource(context, Pool, pool_id) - self.assert_modification_allowed(pool_db) - pool_db.stats = self._create_pool_stats(context, pool_id, data) - - for member, stats in data.get('members', {}).items(): - stats_status = stats.get(lb_const.STATS_STATUS) - if stats_status: - self.update_status(context, Member, member, stats_status) - - def _create_pool_stats(self, context, pool_id, data=None): - # This is internal method to add pool statistics. It won't - # be exposed to API - if not data: - data = {} - stats_db = PoolStatistics( - pool_id=pool_id, - bytes_in=data.get(lb_const.STATS_IN_BYTES, 0), - bytes_out=data.get(lb_const.STATS_OUT_BYTES, 0), - active_connections=data.get(lb_const.STATS_ACTIVE_CONNECTIONS, 0), - total_connections=data.get(lb_const.STATS_TOTAL_CONNECTIONS, 0) - ) - return stats_db - - def _delete_pool_stats(self, context, pool_id): - # This is internal method to delete pool statistics. It won't - # be exposed to API - with context.session.begin(subtransactions=True): - stats_qry = context.session.query(PoolStatistics) - try: - stats = stats_qry.filter_by(pool_id=pool_id).one() - except exc.NoResultFound: - raise loadbalancer.PoolStatsNotFound(pool_id=pool_id) - context.session.delete(stats) - - def create_pool(self, context, pool): - v = pool['pool'] - - tenant_id = self._get_tenant_id_for_create(context, v) - with context.session.begin(subtransactions=True): - pool_db = Pool(id=uuidutils.generate_uuid(), - tenant_id=tenant_id, - name=v['name'], - description=v['description'], - subnet_id=v['subnet_id'], - protocol=v['protocol'], - lb_method=v['lb_method'], - admin_state_up=v['admin_state_up'], - status=constants.PENDING_CREATE) - pool_db.stats = self._create_pool_stats(context, pool_db['id']) - context.session.add(pool_db) - - return self._make_pool_dict(pool_db) - - def update_pool(self, context, id, pool): - p = pool['pool'] - with context.session.begin(subtransactions=True): - pool_db = self._get_resource(context, Pool, id) - self.assert_modification_allowed(pool_db) - if p: - pool_db.update(p) - - return self._make_pool_dict(pool_db) - - def _ensure_pool_delete_conditions(self, context, pool_id): - if context.session.query(Vip).filter_by(pool_id=pool_id).first(): - raise loadbalancer.PoolInUse(pool_id=pool_id) - - def delete_pool(self, context, pool_id): - # Check if the pool is in use - self._ensure_pool_delete_conditions(context, pool_id) - - with context.session.begin(subtransactions=True): - self._delete_pool_stats(context, pool_id) - pool_db = self._get_resource(context, Pool, pool_id) - context.session.delete(pool_db) - - def get_pool(self, context, id, fields=None): - pool = self._get_resource(context, Pool, id) - return self._make_pool_dict(pool, fields) - - def get_pools(self, context, filters=None, fields=None): - collection = self._model_query(context, Pool) - collection = self._apply_filters_to_query(collection, Pool, filters) - return [self._make_pool_dict(c, fields) - for c in collection] - - def stats(self, context, pool_id): - with context.session.begin(subtransactions=True): - pool = self._get_resource(context, Pool, pool_id) - stats = pool['stats'] - - res = {lb_const.STATS_IN_BYTES: stats['bytes_in'], - lb_const.STATS_OUT_BYTES: stats['bytes_out'], - lb_const.STATS_ACTIVE_CONNECTIONS: stats['active_connections'], - lb_const.STATS_TOTAL_CONNECTIONS: stats['total_connections']} - return {'stats': res} - - def create_pool_health_monitor(self, context, health_monitor, pool_id): - monitor_id = health_monitor['health_monitor']['id'] - with context.session.begin(subtransactions=True): - assoc_qry = context.session.query(PoolMonitorAssociation) - assoc = assoc_qry.filter_by(pool_id=pool_id, - monitor_id=monitor_id).first() - if assoc: - raise loadbalancer.PoolMonitorAssociationExists( - monitor_id=monitor_id, pool_id=pool_id) - - pool = self._get_resource(context, Pool, pool_id) - - assoc = PoolMonitorAssociation(pool_id=pool_id, - monitor_id=monitor_id, - status=constants.PENDING_CREATE) - pool.monitors.append(assoc) - monitors = [monitor['monitor_id'] for monitor in pool['monitors']] - - res = {"health_monitor": monitors} - return res - - def delete_pool_health_monitor(self, context, id, pool_id): - with context.session.begin(subtransactions=True): - assoc = self._get_pool_health_monitor(context, id, pool_id) - pool = self._get_resource(context, Pool, pool_id) - pool.monitors.remove(assoc) - - def _get_pool_health_monitor(self, context, id, pool_id): - try: - assoc_qry = context.session.query(PoolMonitorAssociation) - return assoc_qry.filter_by(monitor_id=id, pool_id=pool_id).one() - except exc.NoResultFound: - raise loadbalancer.PoolMonitorAssociationNotFound( - monitor_id=id, pool_id=pool_id) - - def get_pool_health_monitor(self, context, id, pool_id, fields=None): - pool_hm = self._get_pool_health_monitor(context, id, pool_id) - # need to add tenant_id for admin_or_owner policy check to pass - hm = self.get_health_monitor(context, id) - res = {'pool_id': pool_id, - 'monitor_id': id, - 'status': pool_hm['status'], - 'status_description': pool_hm['status_description'], - 'tenant_id': hm['tenant_id']} - return self._fields(res, fields) - - def update_pool_health_monitor(self, context, id, pool_id, - status, status_description=None): - with context.session.begin(subtransactions=True): - assoc = self._get_pool_health_monitor(context, id, pool_id) - self.assert_modification_allowed(assoc) - assoc.status = status - assoc.status_description = status_description - - ######################################################## - # Member DB access - def _make_member_dict(self, member, fields=None): - res = {'id': member['id'], - 'tenant_id': member['tenant_id'], - 'pool_id': member['pool_id'], - 'address': member['address'], - 'protocol_port': member['protocol_port'], - 'weight': member['weight'], - 'admin_state_up': member['admin_state_up'], - 'status': member['status'], - 'status_description': member['status_description']} - - return self._fields(res, fields) - - def create_member(self, context, member): - v = member['member'] - tenant_id = self._get_tenant_id_for_create(context, v) - - try: - with context.session.begin(subtransactions=True): - # ensuring that pool exists - self._get_resource(context, Pool, v['pool_id']) - member_db = Member(id=uuidutils.generate_uuid(), - tenant_id=tenant_id, - pool_id=v['pool_id'], - address=v['address'], - protocol_port=v['protocol_port'], - weight=v['weight'], - admin_state_up=v['admin_state_up'], - status=constants.PENDING_CREATE) - context.session.add(member_db) - return self._make_member_dict(member_db) - except exception.DBDuplicateEntry: - raise loadbalancer.MemberExists( - address=v['address'], - port=v['protocol_port'], - pool=v['pool_id']) - - def update_member(self, context, id, member): - v = member['member'] - try: - with context.session.begin(subtransactions=True): - member_db = self._get_resource(context, Member, id) - self.assert_modification_allowed(member_db) - if v: - member_db.update(v) - return self._make_member_dict(member_db) - except exception.DBDuplicateEntry: - raise loadbalancer.MemberExists( - address=member_db['address'], - port=member_db['protocol_port'], - pool=member_db['pool_id']) - - def delete_member(self, context, id): - with context.session.begin(subtransactions=True): - member_db = self._get_resource(context, Member, id) - context.session.delete(member_db) - - def get_member(self, context, id, fields=None): - member = self._get_resource(context, Member, id) - return self._make_member_dict(member, fields) - - def get_members(self, context, filters=None, fields=None): - return self._get_collection(context, Member, - self._make_member_dict, - filters=filters, fields=fields) - - ######################################################## - # HealthMonitor DB access - def _make_health_monitor_dict(self, health_monitor, fields=None): - res = {'id': health_monitor['id'], - 'tenant_id': health_monitor['tenant_id'], - 'type': health_monitor['type'], - 'delay': health_monitor['delay'], - 'timeout': health_monitor['timeout'], - 'max_retries': health_monitor['max_retries'], - 'admin_state_up': health_monitor['admin_state_up']} - # no point to add the values below to - # the result if the 'type' is not HTTP/S - if res['type'] in ['HTTP', 'HTTPS']: - for attr in ['url_path', 'http_method', 'expected_codes']: - res[attr] = health_monitor[attr] - res['pools'] = [{'pool_id': p['pool_id'], - 'status': p['status'], - 'status_description': p['status_description']} - for p in health_monitor.pools] - return self._fields(res, fields) - - def create_health_monitor(self, context, health_monitor): - v = health_monitor['health_monitor'] - tenant_id = self._get_tenant_id_for_create(context, v) - with context.session.begin(subtransactions=True): - # setting ACTIVE status since healthmon is shared DB object - monitor_db = HealthMonitor(id=uuidutils.generate_uuid(), - tenant_id=tenant_id, - type=v['type'], - delay=v['delay'], - timeout=v['timeout'], - max_retries=v['max_retries'], - http_method=v['http_method'], - url_path=v['url_path'], - expected_codes=v['expected_codes'], - admin_state_up=v['admin_state_up']) - context.session.add(monitor_db) - return self._make_health_monitor_dict(monitor_db) - - def update_health_monitor(self, context, id, health_monitor): - v = health_monitor['health_monitor'] - with context.session.begin(subtransactions=True): - monitor_db = self._get_resource(context, HealthMonitor, id) - self.assert_modification_allowed(monitor_db) - if v: - monitor_db.update(v) - return self._make_health_monitor_dict(monitor_db) - - def delete_health_monitor(self, context, id): - """Delete health monitor object from DB - - Raises an error if the monitor has associations with pools - """ - query = self._model_query(context, PoolMonitorAssociation) - has_associations = query.filter_by(monitor_id=id).first() - if has_associations: - raise loadbalancer.HealthMonitorInUse(monitor_id=id) - - with context.session.begin(subtransactions=True): - monitor_db = self._get_resource(context, HealthMonitor, id) - context.session.delete(monitor_db) - - def get_health_monitor(self, context, id, fields=None): - healthmonitor = self._get_resource(context, HealthMonitor, id) - return self._make_health_monitor_dict(healthmonitor, fields) - - def get_health_monitors(self, context, filters=None, fields=None): - return self._get_collection(context, HealthMonitor, - self._make_health_monitor_dict, - filters=filters, fields=fields) diff --git a/neutron/db/metering/__init__.py b/neutron/db/metering/__init__.py deleted file mode 100644 index 82a447213..000000000 --- a/neutron/db/metering/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright (C) 2013 eNovance SAS -# -# Author: Sylvain Afchain -# -# 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. diff --git a/neutron/db/metering/metering_db.py b/neutron/db/metering/metering_db.py deleted file mode 100644 index fe48ae4fd..000000000 --- a/neutron/db/metering/metering_db.py +++ /dev/null @@ -1,239 +0,0 @@ -# Copyright (C) 2013 eNovance SAS -# -# Author: Sylvain Afchain -# -# 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. - -import netaddr -import sqlalchemy as sa -from sqlalchemy import orm - -from neutron.api.rpc.agentnotifiers import metering_rpc_agent_api -from neutron.common import constants -from neutron.db import api as dbapi -from neutron.db import db_base_plugin_v2 as base_db -from neutron.db import l3_db -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.extensions import metering -from neutron.openstack.common import log as logging -from neutron.openstack.common import uuidutils - - -LOG = logging.getLogger(__name__) - - -class MeteringLabelRule(model_base.BASEV2, models_v2.HasId): - direction = sa.Column(sa.Enum('ingress', 'egress', - name='meteringlabels_direction')) - remote_ip_prefix = sa.Column(sa.String(64)) - metering_label_id = sa.Column(sa.String(36), - sa.ForeignKey("meteringlabels.id", - ondelete="CASCADE"), - nullable=False) - excluded = sa.Column(sa.Boolean, default=False) - - -class MeteringLabel(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): - name = sa.Column(sa.String(255)) - description = sa.Column(sa.String(1024)) - rules = orm.relationship(MeteringLabelRule, backref="label", - cascade="delete", lazy="joined") - routers = orm.relationship( - l3_db.Router, - primaryjoin="MeteringLabel.tenant_id==Router.tenant_id", - foreign_keys='MeteringLabel.tenant_id', - uselist=True) - - -class MeteringDbMixin(metering.MeteringPluginBase, - base_db.CommonDbMixin): - - def __init__(self): - dbapi.register_models() - - 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'], - 'tenant_id': metering_label['tenant_id']} - return self._fields(res, fields) - - def create_metering_label(self, context, metering_label): - m = metering_label['metering_label'] - tenant_id = self._get_tenant_id_for_create(context, m) - - with context.session.begin(subtransactions=True): - metering_db = MeteringLabel(id=uuidutils.generate_uuid(), - description=m['description'], - tenant_id=tenant_id, - name=m['name']) - context.session.add(metering_db) - - return self._make_metering_label_dict(metering_db) - - def delete_metering_label(self, context, label_id): - with context.session.begin(subtransactions=True): - try: - label = self._get_by_id(context, MeteringLabel, label_id) - except orm.exc.NoResultFound: - raise metering.MeteringLabelNotFound(label_id=label_id) - - context.session.delete(label) - - def get_metering_label(self, context, label_id, fields=None): - try: - metering_label = self._get_by_id(context, MeteringLabel, label_id) - except orm.exc.NoResultFound: - raise metering.MeteringLabelNotFound(label_id=label_id) - - return self._make_metering_label_dict(metering_label, fields) - - def get_metering_labels(self, context, filters=None, fields=None, - sorts=None, limit=None, marker=None, - page_reverse=False): - marker_obj = self._get_marker_obj(context, 'metering_labels', limit, - marker) - return self._get_collection(context, MeteringLabel, - self._make_metering_label_dict, - filters=filters, fields=fields, - sorts=sorts, - limit=limit, - marker_obj=marker_obj, - page_reverse=page_reverse) - - def _make_metering_label_rule_dict(self, metering_label_rule, fields=None): - res = {'id': metering_label_rule['id'], - 'metering_label_id': metering_label_rule['metering_label_id'], - 'direction': metering_label_rule['direction'], - 'remote_ip_prefix': metering_label_rule['remote_ip_prefix'], - 'excluded': metering_label_rule['excluded']} - return self._fields(res, fields) - - def get_metering_label_rules(self, context, filters=None, fields=None, - sorts=None, limit=None, marker=None, - page_reverse=False): - marker_obj = self._get_marker_obj(context, 'metering_label_rules', - limit, marker) - - return self._get_collection(context, MeteringLabelRule, - self._make_metering_label_rule_dict, - filters=filters, fields=fields, - sorts=sorts, - limit=limit, - marker_obj=marker_obj, - page_reverse=page_reverse) - - def get_metering_label_rule(self, context, rule_id, fields=None): - try: - metering_label_rule = self._get_by_id(context, - MeteringLabelRule, rule_id) - except orm.exc.NoResultFound: - raise metering.MeteringLabelRuleNotFound(rule_id=rule_id) - - return self._make_metering_label_rule_dict(metering_label_rule, fields) - - def _validate_cidr(self, context, label_id, remote_ip_prefix, - direction, excluded): - r_ips = self.get_metering_label_rules(context, - filters={'metering_label_id': - label_id, - 'direction': - [direction], - 'excluded': - [excluded]}, - fields=['remote_ip_prefix']) - - cidrs = [r['remote_ip_prefix'] for r in r_ips] - new_cidr_ipset = netaddr.IPSet([remote_ip_prefix]) - if (netaddr.IPSet(cidrs) & new_cidr_ipset): - raise metering.MeteringLabelRuleOverlaps(remote_ip_prefix= - remote_ip_prefix) - - def create_metering_label_rule(self, context, metering_label_rule): - m = metering_label_rule['metering_label_rule'] - with context.session.begin(subtransactions=True): - label_id = m['metering_label_id'] - ip_prefix = m['remote_ip_prefix'] - direction = m['direction'] - excluded = m['excluded'] - - self._validate_cidr(context, label_id, ip_prefix, direction, - excluded) - metering_db = MeteringLabelRule(id=uuidutils.generate_uuid(), - metering_label_id=label_id, - direction=direction, - excluded=m['excluded'], - remote_ip_prefix=ip_prefix) - context.session.add(metering_db) - - return self._make_metering_label_rule_dict(metering_db) - - def delete_metering_label_rule(self, context, rule_id): - with context.session.begin(subtransactions=True): - try: - rule = self._get_by_id(context, MeteringLabelRule, rule_id) - except orm.exc.NoResultFound: - raise metering.MeteringLabelRuleNotFound(rule_id=rule_id) - - context.session.delete(rule) - - def _get_metering_rules_dict(self, metering_label): - rules = [] - for rule in metering_label.rules: - rule_dict = self._make_metering_label_rule_dict(rule) - rules.append(rule_dict) - - return rules - - def _make_router_dict(self, router): - res = {'id': router['id'], - 'name': router['name'], - 'tenant_id': router['tenant_id'], - 'admin_state_up': router['admin_state_up'], - 'status': router['status'], - 'gw_port_id': router['gw_port_id'], - constants.METERING_LABEL_KEY: []} - - return res - - def _process_sync_metering_data(self, labels): - routers_dict = {} - for label in labels: - routers = label.routers - for router in routers: - router_dict = routers_dict.get( - router['id'], - self._make_router_dict(router)) - - rules = self._get_metering_rules_dict(label) - - data = {'id': label['id'], 'rules': rules} - router_dict[constants.METERING_LABEL_KEY].append(data) - - routers_dict[router['id']] = router_dict - - return routers_dict.values() - - def get_sync_data_metering(self, context, label_id=None, router_ids=None): - labels = context.session.query(MeteringLabel) - - if label_id: - labels = labels.filter(MeteringLabel.id == label_id) - elif router_ids: - labels = (labels.join(MeteringLabel.routers). - filter(l3_db.Router.id.in_(router_ids))) - - return self._process_sync_metering_data(labels) diff --git a/neutron/db/metering/metering_rpc.py b/neutron/db/metering/metering_rpc.py deleted file mode 100644 index c0bbd51ad..000000000 --- a/neutron/db/metering/metering_rpc.py +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (C) 2014 eNovance SAS -# -# Author: Sylvain Afchain -# -# 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 constants as consts -from neutron.common import utils -from neutron import manager -from neutron.openstack.common import log as logging -from neutron.plugins.common import constants as service_constants - -LOG = logging.getLogger(__name__) - - -class MeteringRpcCallbacks(object): - - RPC_API_VERSION = '1.0' - - def __init__(self, meter_plugin): - self.meter_plugin = meter_plugin - - def get_sync_data_metering(self, context, **kwargs): - l3_plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) - if not l3_plugin: - return - - host = kwargs.get('host') - if not utils.is_extension_supported( - l3_plugin, consts.L3_AGENT_SCHEDULER_EXT_ALIAS) or not host: - return self.meter_plugin.get_sync_data_metering(context) - else: - agents = l3_plugin.get_l3_agents(context, filters={'host': [host]}) - if not agents: - LOG.error(_('Unable to find agent %s.'), host) - return - - routers = l3_plugin.list_routers_on_l3_agent(context, agents[0].id) - router_ids = [router['id'] for router in routers['routers']] - if not router_ids: - return - - return self.meter_plugin.get_sync_data_metering(context, - router_ids=router_ids) diff --git a/neutron/db/migration/alembic_migrations/common_ext_ops.py b/neutron/db/migration/alembic_migrations/common_ext_ops.py deleted file mode 100644 index 5663ff228..000000000 --- a/neutron/db/migration/alembic_migrations/common_ext_ops.py +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright 2013 Openstack Foundation -# -# 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. -# - -""" -Upgrade/downgrade operations for 'community' extensions -""" - -from alembic import op -import sqlalchemy as sa - - -def upgrade_l3(): - op.create_table( - 'routers', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('status', sa.String(length=16), nullable=True), - sa.Column('admin_state_up', sa.Boolean(), nullable=True), - sa.Column('gw_port_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['gw_port_id'], ['ports.id'], ), - sa.PrimaryKeyConstraint('id') - ) - - op.create_table( - 'externalnetworks', - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('network_id') - ) - - op.create_table( - 'floatingips', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('floating_ip_address', sa.String(length=64), nullable=False), - sa.Column('floating_network_id', sa.String(length=36), nullable=False), - sa.Column('floating_port_id', sa.String(length=36), nullable=False), - sa.Column('fixed_port_id', sa.String(length=36), nullable=True), - sa.Column('fixed_ip_address', sa.String(length=64), nullable=True), - sa.Column('router_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['fixed_port_id'], ['ports.id'], ), - sa.ForeignKeyConstraint(['floating_port_id'], ['ports.id'], ), - sa.ForeignKeyConstraint(['router_id'], ['routers.id'], ), - sa.PrimaryKeyConstraint('id') - ) - - -def upgrade_quota(options=None): - if not (options or {}).get('folsom_quota_db_enabled'): - return - - op.create_table( - 'quotas', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('tenant_id', sa.String(255), index=True), - sa.Column('resource', sa.String(255)), - sa.Column('limit', sa.Integer()), - sa.PrimaryKeyConstraint('id') - ) - - -def downgrade_l3(): - for table in ('floatingips', 'routers', 'externalnetworks'): - op.drop_table(table) - - -def downgrade_quota(options=None): - if (options or {}).get('folsom_quota_db_enabled'): - op.drop_table('quotas') diff --git a/neutron/db/migration/alembic_migrations/versions/1064e98b7917_nec_pf_port_del.py b/neutron/db/migration/alembic_migrations/versions/1064e98b7917_nec_pf_port_del.py deleted file mode 100644 index a4ddbab5a..000000000 --- a/neutron/db/migration/alembic_migrations/versions/1064e98b7917_nec_pf_port_del.py +++ /dev/null @@ -1,63 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""nec-pf-port-del - -Revision ID: 1064e98b7917 -Revises: 3d6fae8b70b0 -Create Date: 2013-09-24 05:33:54.602618 - -""" - -# revision identifiers, used by Alembic. -revision = '1064e98b7917' -down_revision = '3d6fae8b70b0' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nec.nec_plugin.NECPluginV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('packetfilters', 'in_port', - existing_type=sa.String(length=36), - nullable=True) - op.create_foreign_key( - 'packetfilters_ibfk_2', - source='packetfilters', referent='ports', - local_cols=['in_port'], remote_cols=['id'], - ondelete='CASCADE') - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_constraint('packetfilters_ibfk_2', 'packetfilters', 'foreignkey') - op.alter_column('packetfilters', 'in_port', - existing_type=sa.String(length=36), - nullable=False) diff --git a/neutron/db/migration/alembic_migrations/versions/10cd28e692e9_nuage_extraroute.py b/neutron/db/migration/alembic_migrations/versions/10cd28e692e9_nuage_extraroute.py deleted file mode 100644 index 2949813bb..000000000 --- a/neutron/db/migration/alembic_migrations/versions/10cd28e692e9_nuage_extraroute.py +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""nuage_extraroute - -Revision ID: 10cd28e692e9 -Revises: 1b837a7125a9 -Create Date: 2014-05-14 14:47:53.148132 - -""" - -# revision identifiers, used by Alembic. -revision = '10cd28e692e9' -down_revision = '1b837a7125a9' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nuage.plugin.NuagePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'routerroutes_mapping', - sa.Column('router_id', sa.String(length=36), nullable=False), - sa.Column('nuage_route_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['router_id'], ['routers.id'], - ondelete='CASCADE'), - ) - op.create_table( - 'routerroutes', - sa.Column('destination', sa.String(length=64), nullable=False), - sa.Column('nexthop', sa.String(length=64), nullable=False), - sa.Column('router_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['router_id'], ['routers.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('destination', 'nexthop', - 'router_id'), - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('routerroutes') - op.drop_table('routerroutes_mapping') diff --git a/neutron/db/migration/alembic_migrations/versions/1149d7de0cfa_port_security.py b/neutron/db/migration/alembic_migrations/versions/1149d7de0cfa_port_security.py deleted file mode 100644 index 8929fc920..000000000 --- a/neutron/db/migration/alembic_migrations/versions/1149d7de0cfa_port_security.py +++ /dev/null @@ -1,84 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""initial port security - -Revision ID: 1149d7de0cfa -Revises: 1b693c095aa3 -Create Date: 2013-01-22 14:05:20.696502 - -""" - -# revision identifiers, used by Alembic. -revision = '1149d7de0cfa' -down_revision = '1b693c095aa3' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.create_table('networksecuritybindings', - sa.Column('network_id', sa.String(length=36), - nullable=False), - sa.Column('port_security_enabled', sa.Boolean(), - nullable=False), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('network_id')) - op.create_table('portsecuritybindings', - sa.Column('port_id', sa.String(length=36), - nullable=False), - sa.Column('port_security_enabled', sa.Boolean(), - nullable=False), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('port_id')) - ### end Alembic commands ### - - # Copy network and port ids over to network|port(securitybindings) table - # and set port_security_enabled to false as ip address pairs were not - # configured in NVP/NSX originally. - op.execute("INSERT INTO networksecuritybindings SELECT id as " - "network_id, False as port_security_enabled from networks") - op.execute("INSERT INTO portsecuritybindings SELECT id as port_id, " - "False as port_security_enabled from ports") - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('portsecuritybindings') - op.drop_table('networksecuritybindings') - ### end Alembic commands ### diff --git a/neutron/db/migration/alembic_migrations/versions/117643811bca_nec_delete_ofc_mapping.py b/neutron/db/migration/alembic_migrations/versions/117643811bca_nec_delete_ofc_mapping.py deleted file mode 100644 index 8db943492..000000000 --- a/neutron/db/migration/alembic_migrations/versions/117643811bca_nec_delete_ofc_mapping.py +++ /dev/null @@ -1,208 +0,0 @@ -# Copyright 2014 NEC Corporation -# -# 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. -# - -"""nec: delete old ofc mapping tables - -Revision ID: 117643811bca -Revises: 81c553f3776c -Create Date: 2014-03-02 05:26:47.073318 - -""" - -# revision identifiers, used by Alembic. -revision = '117643811bca' -down_revision = '81c553f3776c' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nec.nec_plugin.NECPluginV2' -] - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.ext import compiler as sa_compiler -from sqlalchemy.sql import expression as sa_expr - -from neutron.db import migration - - -# sqlalchemy does not support the expression: -# INSERT INTO (, ...) (SELECT ...) -# The following class is to support this expression. -# Reference: http://docs.sqlalchemy.org/en/rel_0_9/core/compiler.html -# section: "Compiling sub-elements of a custom expression construct" - -class InsertFromSelect(sa_expr.Executable, sa_expr.ClauseElement): - _execution_options = (sa_expr.Executable._execution_options. - union({'autocommit': True})) - - def __init__(self, insert_spec, select): - self.insert_spec = insert_spec - self.select = select - - -@sa_compiler.compiles(InsertFromSelect) -def visit_insert_from_select(element, compiler, **kw): - if type(element.insert_spec) == list: - columns = [] - for column in element.insert_spec: - columns.append(column.name) - table = compiler.process(element.insert_spec[0].table, asfrom=True) - columns = ", ".join(columns) - sql = ("INSERT INTO %s (%s) (%s)" % - (table, columns, compiler.process(element.select))) - else: - sql = ("INSERT INTO %s (%s)" % - (compiler.process(element.insert_spec, asfrom=True), - compiler.process(element.select))) - return sql - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - # Table definitions below are only used for sqlalchemy to generate - # SQL statements, so in networks/ports tables only required field - # are declared. Note that 'quantum_id' in OFC ID mapping tables - # will be renamed in a later patch (bug 1287432). - - ofctenants = sa_expr.table( - 'ofctenants', - sa_expr.column('id'), - sa_expr.column('quantum_id')) - ofcnetworks = sa_expr.table( - 'ofcnetworks', - sa_expr.column('id'), - sa_expr.column('quantum_id')) - ofcports = sa_expr.table( - 'ofcports', - sa_expr.column('id'), - sa_expr.column('quantum_id')) - ofcfilters = sa_expr.table( - 'ofcfilters', - sa_expr.column('id'), - sa_expr.column('quantum_id')) - - ofctenantmappings = sa_expr.table( - 'ofctenantmappings', - sa_expr.column('ofc_id'), - sa_expr.column('quantum_id')) - ofcnetworkmappings = sa_expr.table( - 'ofcnetworkmappings', - sa_expr.column('ofc_id'), - sa_expr.column('quantum_id')) - ofcportmappings = sa_expr.table( - 'ofcportmappings', - sa_expr.column('ofc_id'), - sa_expr.column('quantum_id')) - ofcfiltermappings = sa_expr.table( - 'ofcfiltermappings', - sa_expr.column('ofc_id'), - sa_expr.column('quantum_id')) - - networks = sa_expr.table( - 'networks', - sa_expr.column('id'), - sa_expr.column('tenant_id')) - ports = sa_expr.table( - 'ports', - sa_expr.column('id'), - sa_expr.column('network_id')) - - # ofctenants -> ofctenantmappings - select_obj = sa.select([ofctenants.c.quantum_id, - op.inline_literal('/tenants/') + ofctenants.c.id]) - stmt = InsertFromSelect([ofctenantmappings.c.quantum_id, - ofctenantmappings.c.ofc_id], - select_obj) - op.execute(stmt) - - # ofcnetworks -> ofcnetworkmappings - select_obj = ofcnetworks.join( - networks, - ofcnetworks.c.quantum_id == networks.c.id) - select_obj = select_obj.join( - ofctenantmappings, - ofctenantmappings.c.quantum_id == networks.c.tenant_id) - select_obj = sa.select( - [ofcnetworks.c.quantum_id, - (ofctenantmappings.c.ofc_id + - op.inline_literal('/networks/') + ofcnetworks.c.id)], - from_obj=select_obj) - stmt = InsertFromSelect([ofcnetworkmappings.c.quantum_id, - ofcnetworkmappings.c.ofc_id], - select_obj) - op.execute(stmt) - - # ofcports -> ofcportmappings - select_obj = ofcports.join(ports, ofcports.c.quantum_id == ports.c.id) - select_obj = select_obj.join( - ofcnetworkmappings, - ofcnetworkmappings.c.quantum_id == ports.c.network_id) - select_obj = sa.select( - [ofcports.c.quantum_id, - (ofcnetworkmappings.c.ofc_id + - op.inline_literal('/ports/') + ofcports.c.id)], - from_obj=select_obj) - stmt = InsertFromSelect([ofcportmappings.c.quantum_id, - ofcportmappings.c.ofc_id], - select_obj) - op.execute(stmt) - - # ofcfilters -> ofcfiltermappings - select_obj = sa.select([ofcfilters.c.quantum_id, - op.inline_literal('/filters/') + ofcfilters.c.id]) - stmt = InsertFromSelect([ofcfiltermappings.c.quantum_id, - ofcfiltermappings.c.ofc_id], - select_obj) - op.execute(stmt) - - # drop old mapping tables - op.drop_table('ofctenants') - op.drop_table('ofcnetworks') - op.drop_table('ofcports') - op.drop_table('ofcfilters') - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'ofctenants', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('quantum_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'ofcnetworks', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('quantum_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'ofcports', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('quantum_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'ofcfilters', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('quantum_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('id') - ) diff --git a/neutron/db/migration/alembic_migrations/versions/11c6e18605c8_pool_monitor_status_.py b/neutron/db/migration/alembic_migrations/versions/11c6e18605c8_pool_monitor_status_.py deleted file mode 100644 index 598f2ab32..000000000 --- a/neutron/db/migration/alembic_migrations/versions/11c6e18605c8_pool_monitor_status_.py +++ /dev/null @@ -1,62 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Pool Monitor status field - -Revision ID: 11c6e18605c8 -Revises: 52ff27f7567a -Create Date: 2013-07-10 06:07:20.878520 - -""" - -# revision identifiers, used by Alembic. -revision = '11c6e18605c8' -down_revision = '52ff27f7567a' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin', -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.add_column('poolmonitorassociations', sa.Column('status', - sa.String(16), - server_default='', - nullable=False)) - op.add_column('poolmonitorassociations', sa.Column('status_description', - sa.String(255))) - - # Set status to ACTIVE for existing associations - op.execute("UPDATE poolmonitorassociations SET status='ACTIVE'") - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_column('poolmonitorassociations', 'status') - op.drop_column('poolmonitorassociations', 'status_description') diff --git a/neutron/db/migration/alembic_migrations/versions/128e042a2b68_ext_gw_mode.py b/neutron/db/migration/alembic_migrations/versions/128e042a2b68_ext_gw_mode.py deleted file mode 100644 index dc4c14c14..000000000 --- a/neutron/db/migration/alembic_migrations/versions/128e042a2b68_ext_gw_mode.py +++ /dev/null @@ -1,71 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""ext_gw_mode - -Revision ID: 128e042a2b68 -Revises: 32b517556ec9 -Create Date: 2013-03-27 00:35:17.323280 - -""" - -# revision identifiers, used by Alembic. -revision = '128e042a2b68' -down_revision = '32b517556ec9' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.hyperv.hyperv_neutron_plugin.HyperVNeutronPlugin', - 'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2', - 'neutron.plugins.metaplugin.meta_neutron_plugin.MetaPluginV2', - 'neutron.plugins.ml2.plugin.Ml2Plugin', - 'neutron.plugins.nec.nec_plugin.NECPluginV2', - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', - 'neutron.plugins.ryu.ryu_neutron_plugin.RyuNeutronPluginV2', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin', - 'neutron.plugins.embrane.plugins.embrane_ovs_plugin.EmbraneOvsPlugin', - 'neutron.plugins.ibm.sdnve_neutron_plugin.SdnvePluginV2', - 'neutron.plugins.oneconvergence.plugin.OneConvergencePluginV2', - 'neutron.plugins.cisco.network_plugin.PluginV2', -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.add_column('routers', sa.Column('enable_snat', sa.Boolean(), - nullable=False, default=True)) - # Set enable_snat to True for existing routers - op.execute("UPDATE routers SET enable_snat=True") - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_column('routers', 'enable_snat') diff --git a/neutron/db/migration/alembic_migrations/versions/1341ed32cc1e_nvp_netbinding_update.py b/neutron/db/migration/alembic_migrations/versions/1341ed32cc1e_nvp_netbinding_update.py deleted file mode 100644 index 677d6f291..000000000 --- a/neutron/db/migration/alembic_migrations/versions/1341ed32cc1e_nvp_netbinding_update.py +++ /dev/null @@ -1,70 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""nvp_net_binding - -Revision ID: 1341ed32cc1e -Revises: 4692d074d587 -Create Date: 2013-02-26 01:28:29.182195 - -""" - -# revision identifiers, used by Alembic. -revision = '1341ed32cc1e' -down_revision = '4692d074d587' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - -new_type = sa.Enum('flat', 'vlan', 'stt', 'gre', 'l3_ext', - name='nvp_network_bindings_binding_type') -old_type = sa.Enum('flat', 'vlan', 'stt', 'gre', - name='nvp_network_bindings_binding_type') - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - op.alter_column('nvp_network_bindings', 'tz_uuid', - name='phy_uuid', - existing_type=sa.String(36), - existing_nullable=True) - migration.alter_enum('nvp_network_bindings', 'binding_type', new_type, - nullable=False) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - op.alter_column('nvp_network_bindings', 'phy_uuid', - name='tz_uuid', - existing_type=sa.String(36), - existing_nullable=True) - migration.alter_enum('nvp_network_bindings', 'binding_type', old_type, - nullable=False) diff --git a/neutron/db/migration/alembic_migrations/versions/13de305df56e_add_nec_pf_name.py b/neutron/db/migration/alembic_migrations/versions/13de305df56e_add_nec_pf_name.py deleted file mode 100644 index 17a951cd5..000000000 --- a/neutron/db/migration/alembic_migrations/versions/13de305df56e_add_nec_pf_name.py +++ /dev/null @@ -1,55 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""nec_add_pf_name - -Revision ID: 13de305df56e -Revises: b7a8863760e -Create Date: 2013-07-06 00:42:26.991175 - -""" - -# revision identifiers, used by Alembic. -revision = '13de305df56e' -down_revision = 'b7a8863760e' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nec.nec_plugin.NECPluginV2' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.add_column('packetfilters', - sa.Column('name', sa.String(length=255), nullable=True)) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_column('packetfilters', 'name') diff --git a/neutron/db/migration/alembic_migrations/versions/1421183d533f_nsx_dhcp_metadata.py b/neutron/db/migration/alembic_migrations/versions/1421183d533f_nsx_dhcp_metadata.py deleted file mode 100644 index 69e5414a8..000000000 --- a/neutron/db/migration/alembic_migrations/versions/1421183d533f_nsx_dhcp_metadata.py +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright 2014 VMware, 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. -# - -"""NSX DHCP/metadata support - -Revision ID: 1421183d533f -Revises: 8f682276ee4 -Create Date: 2013-10-11 14:33:37.303215 - -""" - -revision = '1421183d533f' -down_revision = '8f682276ee4' - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'lsn', - sa.Column('net_id', - sa.String(length=36), nullable=False), - sa.Column('lsn_id', - sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('lsn_id')) - - op.create_table( - 'lsn_port', - sa.Column('lsn_port_id', - sa.String(length=36), nullable=False), - sa.Column('lsn_id', - sa.String(length=36), nullable=False), - sa.Column('sub_id', - sa.String(length=36), nullable=False, unique=True), - sa.Column('mac_addr', - sa.String(length=32), nullable=False, unique=True), - sa.ForeignKeyConstraint(['lsn_id'], ['lsn.lsn_id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('lsn_port_id')) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('lsn_port') - op.drop_table('lsn') diff --git a/neutron/db/migration/alembic_migrations/versions/14f24494ca31_arista_ml2.py b/neutron/db/migration/alembic_migrations/versions/14f24494ca31_arista_ml2.py deleted file mode 100644 index 4ce63f9c0..000000000 --- a/neutron/db/migration/alembic_migrations/versions/14f24494ca31_arista_ml2.py +++ /dev/null @@ -1,78 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""DB Migration for Arista ml2 mechanism driver - -Revision ID: 14f24494ca31 -Revises: 2a3bae1ceb8 -Create Date: 2013-08-15 18:54:16.083640 - -""" - -# revision identifiers, used by Alembic. -revision = '14f24494ca31' -down_revision = '2a3bae1ceb8' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'arista_provisioned_nets', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('network_id', sa.String(length=36), nullable=True), - sa.Column('segmentation_id', sa.Integer(), - autoincrement=False, nullable=True), - sa.PrimaryKeyConstraint('id')) - - op.create_table( - 'arista_provisioned_vms', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('vm_id', sa.String(length=255), nullable=True), - sa.Column('host_id', sa.String(length=255), nullable=True), - sa.Column('port_id', sa.String(length=36), nullable=True), - sa.Column('network_id', sa.String(length=36), nullable=True), - sa.PrimaryKeyConstraint('id')) - - op.create_table( - 'arista_provisioned_tenants', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('id')) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('arista_provisioned_tenants') - op.drop_table('arista_provisioned_vms') - op.drop_table('arista_provisioned_nets') diff --git a/neutron/db/migration/alembic_migrations/versions/157a5d299379_ml2_binding_profile.py b/neutron/db/migration/alembic_migrations/versions/157a5d299379_ml2_binding_profile.py deleted file mode 100644 index 200589d16..000000000 --- a/neutron/db/migration/alembic_migrations/versions/157a5d299379_ml2_binding_profile.py +++ /dev/null @@ -1,55 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""ml2 binding:profile - -Revision ID: 157a5d299379 -Revises: 50d5ba354c23 -Create Date: 2014-02-13 23:48:25.147279 - -""" - -# revision identifiers, used by Alembic. -revision = '157a5d299379' -down_revision = '50d5ba354c23' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.add_column('ml2_port_bindings', - sa.Column('profile', sa.String(length=4095), - nullable=False, server_default='')) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_column('ml2_port_bindings', 'profile') diff --git a/neutron/db/migration/alembic_migrations/versions/176a85fc7d79_add_portbindings_db.py b/neutron/db/migration/alembic_migrations/versions/176a85fc7d79_add_portbindings_db.py deleted file mode 100644 index c1289250d..000000000 --- a/neutron/db/migration/alembic_migrations/versions/176a85fc7d79_add_portbindings_db.py +++ /dev/null @@ -1,66 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Add portbindings db - -Revision ID: 176a85fc7d79 -Revises: f489cf14a79c -Create Date: 2013-03-21 14:59:53.052600 - -""" - -# revision identifiers, used by Alembic. -revision = '176a85fc7d79' -down_revision = 'f489cf14a79c' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2', - 'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2', - 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin', - 'neutron.plugins.ibm.sdnve_neutron_plugin.SdnvePluginV2', - 'neutron.plugins.oneconvergence.plugin.OneConvergencePluginV2', -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'portbindingports', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('host', sa.String(length=255), nullable=False), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ondelete='CASCADE'), - sa.PrimaryKeyConstraint('port_id') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - op.drop_table('portbindingports') diff --git a/neutron/db/migration/alembic_migrations/versions/19180cf98af6_nsx_gw_devices.py b/neutron/db/migration/alembic_migrations/versions/19180cf98af6_nsx_gw_devices.py deleted file mode 100644 index fafb85a51..000000000 --- a/neutron/db/migration/alembic_migrations/versions/19180cf98af6_nsx_gw_devices.py +++ /dev/null @@ -1,103 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""nsx_gw_devices - -Revision ID: 19180cf98af6 -Revises: 117643811bca -Create Date: 2014-02-26 02:46:26.151741 - -""" - -# revision identifiers, used by Alembic. -revision = '19180cf98af6' -down_revision = '117643811bca' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'networkgatewaydevicereferences', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('network_gateway_id', sa.String(length=36), nullable=True), - sa.Column('interface_name', sa.String(length=64), nullable=True), - sa.ForeignKeyConstraint(['network_gateway_id'], ['networkgateways.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id', 'network_gateway_id', 'interface_name'), - mysql_engine='InnoDB') - # Copy data from networkgatewaydevices into networkgatewaydevicereference - op.execute("INSERT INTO networkgatewaydevicereferences SELECT " - "id, network_gateway_id, interface_name FROM " - "networkgatewaydevices") - # drop networkgatewaydevices - op.drop_table('networkgatewaydevices') - op.create_table( - 'networkgatewaydevices', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('nsx_id', sa.String(length=36), nullable=True), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('connector_type', sa.String(length=10), nullable=True), - sa.Column('connector_ip', sa.String(length=64), nullable=True), - sa.Column('status', sa.String(length=16), nullable=True), - sa.PrimaryKeyConstraint('id'), - mysql_engine='InnoDB') - # Create a networkgatewaydevice for each existing reference. - # For existing references nsx_id == neutron_id - # Do not fill conenctor info as they would be unknown - op.execute("INSERT INTO networkgatewaydevices (id, nsx_id, tenant_id) " - "SELECT gw_dev_ref.id, gw_dev_ref.id as nsx_id, tenant_id " - "FROM networkgatewaydevicereferences AS gw_dev_ref " - "INNER JOIN networkgateways AS net_gw ON " - "gw_dev_ref.network_gateway_id=net_gw.id") - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('networkgatewaydevices') - # Re-create previous version of networkgatewaydevices table - op.create_table( - 'networkgatewaydevices', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('network_gateway_id', sa.String(length=36), nullable=True), - sa.Column('interface_name', sa.String(length=64), nullable=True), - sa.ForeignKeyConstraint(['network_gateway_id'], ['networkgateways.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id'), - mysql_engine='InnoDB') - # Copy from networkgatewaydevicereferences to networkgatewaydevices - op.execute("INSERT INTO networkgatewaydevices SELECT " - "id, network_gateway_id, interface_name FROM " - "networkgatewaydevicereferences") - # Dropt networkgatewaydevicereferences - op.drop_table('networkgatewaydevicereferences') diff --git a/neutron/db/migration/alembic_migrations/versions/1b2580001654_nsx_sec_group_mappin.py b/neutron/db/migration/alembic_migrations/versions/1b2580001654_nsx_sec_group_mappin.py deleted file mode 100644 index 76e072ca3..000000000 --- a/neutron/db/migration/alembic_migrations/versions/1b2580001654_nsx_sec_group_mappin.py +++ /dev/null @@ -1,61 +0,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. -# - -"""nsx_sec_group_mapping - -Revision ID: 1b2580001654 -Revises: abc88c33f74f -Create Date: 2013-12-27 13:02:42.894648 - -""" - -# revision identifiers, used by Alembic. -revision = '1b2580001654' -down_revision = 'abc88c33f74f' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - # Create table for security group mappings - op.create_table( - 'neutron_nsx_security_group_mappings', - sa.Column('neutron_id', sa.String(length=36), nullable=False), - sa.Column('nsx_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['neutron_id'], ['securitygroups.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('neutron_id', 'nsx_id')) - # Execute statement to add a record in security group mappings for - # each record in securitygroups - op.execute("INSERT INTO neutron_nsx_security_group_mappings SELECT id,id " - "from securitygroups") - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - op.drop_table('neutron_nsx_security_group_mappings') diff --git a/neutron/db/migration/alembic_migrations/versions/1b693c095aa3_quota_ext_db_grizzly.py b/neutron/db/migration/alembic_migrations/versions/1b693c095aa3_quota_ext_db_grizzly.py deleted file mode 100644 index 2a50e4d5e..000000000 --- a/neutron/db/migration/alembic_migrations/versions/1b693c095aa3_quota_ext_db_grizzly.py +++ /dev/null @@ -1,64 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Quota ext support added in Grizzly - -Revision ID: 1b693c095aa3 -Revises: 1d76643bcec4 -Create Date: 2013-01-19 02:58:17.667524 - -""" - -# revision identifiers, used by Alembic. -revision = '1b693c095aa3' -down_revision = '2a6d0b51f4bb' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nec.nec_plugin.NECPluginV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.create_table( - 'quotas', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('resource', sa.String(length=255), nullable=True), - sa.Column('limit', sa.Integer(), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - ### end Alembic commands ### - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('quotas') - ### end Alembic commands ### diff --git a/neutron/db/migration/alembic_migrations/versions/1b837a7125a9_cisco_apic_driver.py b/neutron/db/migration/alembic_migrations/versions/1b837a7125a9_cisco_apic_driver.py deleted file mode 100644 index 92b132643..000000000 --- a/neutron/db/migration/alembic_migrations/versions/1b837a7125a9_cisco_apic_driver.py +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""Cisco APIC Mechanism Driver - -Revision ID: 1b837a7125a9 -Revises: 6be312499f9 -Create Date: 2014-02-13 09:35:19.147619 - -""" - -# revision identifiers, used by Alembic. -revision = '1b837a7125a9' -down_revision = '6be312499f9' - -migration_for_plugins = [ - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'cisco_ml2_apic_epgs', - sa.Column('network_id', sa.String(length=255), nullable=False), - sa.Column('epg_id', sa.String(length=64), nullable=False), - sa.Column('segmentation_id', sa.String(length=64), nullable=False), - sa.Column('provider', sa.Boolean(), default=False, nullable=False), - sa.PrimaryKeyConstraint('network_id')) - - op.create_table( - 'cisco_ml2_apic_port_profiles', - sa.Column('node_id', sa.String(length=255), nullable=False), - sa.Column('profile_id', sa.String(length=64), nullable=False), - sa.Column('hpselc_id', sa.String(length=64), nullable=False), - sa.Column('module', sa.String(length=10), nullable=False), - sa.Column('from_port', sa.Integer(), nullable=False), - sa.Column('to_port', sa.Integer(), nullable=False), - sa.PrimaryKeyConstraint('node_id')) - - op.create_table( - 'cisco_ml2_apic_contracts', - sa.Column('tenant_id', sa.String(length=255), nullable=False), - sa.Column('contract_id', sa.String(length=64), nullable=False), - sa.Column('filter_id', sa.String(length=64), nullable=False), - sa.PrimaryKeyConstraint('tenant_id')) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('cisco_ml2_apic_contracts') - op.drop_table('cisco_ml2_apic_port_profiles') - op.drop_table('cisco_ml2_apic_epgs') diff --git a/neutron/db/migration/alembic_migrations/versions/1c33fa3cd1a1_extra_route_config.py b/neutron/db/migration/alembic_migrations/versions/1c33fa3cd1a1_extra_route_config.py deleted file mode 100644 index bc5b78215..000000000 --- a/neutron/db/migration/alembic_migrations/versions/1c33fa3cd1a1_extra_route_config.py +++ /dev/null @@ -1,82 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Support routing table configuration on Router - -Revision ID: 1c33fa3cd1a1 -Revises: 45680af419f9 -Create Date: 2013-01-17 14:35:09.386975 - -""" - -# revision identifiers, used by Alembic. -revision = '1c33fa3cd1a1' -down_revision = '45680af419f9' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', - 'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2', - 'neutron.plugins.metaplugin.meta_neutron_plugin.MetaPluginV2', - 'neutron.plugins.ml2.plugin.Ml2Plugin', - 'neutron.plugins.nec.nec_plugin.NECPluginV2', - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.ryu.ryu_neutron_plugin.RyuNeutronPluginV2', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin', - 'neutron.plugins.oneconvergence.plugin.OneConvergencePluginV2', - 'neutron.plugins.cisco.network_plugin.PluginV2', - 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.rename_table( - 'routes', - 'subnetroutes', - ) - op.create_table( - 'routerroutes', - sa.Column('destination', sa.String(length=64), nullable=False), - sa.Column( - 'nexthop', sa.String(length=64), nullable=False), - sa.Column('router_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint( - ['router_id'], ['routers.id'], ondelete='CASCADE'), - sa.PrimaryKeyConstraint('destination', 'nexthop', 'router_id') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.rename_table( - 'subnetroutes', - 'routes', - ) - op.drop_table('routerroutes') diff --git a/neutron/db/migration/alembic_migrations/versions/1d76643bcec4_nvp_netbinding.py b/neutron/db/migration/alembic_migrations/versions/1d76643bcec4_nvp_netbinding.py deleted file mode 100644 index 114d575fe..000000000 --- a/neutron/db/migration/alembic_migrations/versions/1d76643bcec4_nvp_netbinding.py +++ /dev/null @@ -1,67 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""nvp_netbinding - -Revision ID: 1d76643bcec4 -Revises: 3cb5d900c5de -Create Date: 2013-01-15 07:36:10.024346 - -""" - -# revision identifiers, used by Alembic. -revision = '1d76643bcec4' -down_revision = '3cb5d900c5de' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'nvp_network_bindings', - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('binding_type', - sa.Enum('flat', 'vlan', 'stt', 'gre', - name='nvp_network_bindings_binding_type'), - nullable=False), - sa.Column('tz_uuid', sa.String(length=36), nullable=True), - sa.Column('vlan_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('network_id')) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('nvp_network_bindings') diff --git a/neutron/db/migration/alembic_migrations/versions/1e5dd1d09b22_set_not_null_fields_lb_stats.py b/neutron/db/migration/alembic_migrations/versions/1e5dd1d09b22_set_not_null_fields_lb_stats.py deleted file mode 100644 index 6d4d3adee..000000000 --- a/neutron/db/migration/alembic_migrations/versions/1e5dd1d09b22_set_not_null_fields_lb_stats.py +++ /dev/null @@ -1,66 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""set_not_null_fields_lb_stats - -Revision ID: 1e5dd1d09b22 -Revises: 54f7549a0e5f -Create Date: 2014-03-17 11:00:35.370618 - -""" - -# revision identifiers, used by Alembic. -revision = '1e5dd1d09b22' -down_revision = '54f7549a0e5f' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('poolstatisticss', 'bytes_in', nullable=False, - existing_type=sa.BigInteger()) - op.alter_column('poolstatisticss', 'bytes_out', nullable=False, - existing_type=sa.BigInteger()) - op.alter_column('poolstatisticss', 'active_connections', nullable=False, - existing_type=sa.BigInteger()) - op.alter_column('poolstatisticss', 'total_connections', nullable=False, - existing_type=sa.BigInteger()) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('poolstatisticss', 'bytes_in', nullable=True, - existing_type=sa.BigInteger()) - op.alter_column('poolstatisticss', 'bytes_out', nullable=True, - existing_type=sa.BigInteger()) - op.alter_column('poolstatisticss', 'active_connections', nullable=True, - existing_type=sa.BigInteger()) - op.alter_column('poolstatisticss', 'total_connections', nullable=True, - existing_type=sa.BigInteger()) diff --git a/neutron/db/migration/alembic_migrations/versions/1efb85914233_allowedaddresspairs.py b/neutron/db/migration/alembic_migrations/versions/1efb85914233_allowedaddresspairs.py deleted file mode 100644 index e1882d059..000000000 --- a/neutron/db/migration/alembic_migrations/versions/1efb85914233_allowedaddresspairs.py +++ /dev/null @@ -1,67 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""allowedaddresspairs - -Revision ID: 1efb85914233 -Revises: 51b4de912379 -Create Date: 2013-07-23 12:56:00.402855 - -""" - -# revision identifiers, used by Alembic. -revision = '1efb85914233' -down_revision = '51b4de912379' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.cisco.network_plugin.PluginV2', - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.ml2.plugin.Ml2Plugin', - 'neutron.plugins.nec.nec_plugin.NECPluginV2', - 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin', -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'allowedaddresspairs', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('mac_address', sa.String(length=32), nullable=False), - sa.Column('ip_address', sa.String(length=64), nullable=False), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ondelete='CASCADE'), - sa.PrimaryKeyConstraint('port_id', 'mac_address', 'ip_address'), - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('allowedaddresspairs') diff --git a/neutron/db/migration/alembic_migrations/versions/1fcfc149aca4_agents_unique_by_type_and_host.py b/neutron/db/migration/alembic_migrations/versions/1fcfc149aca4_agents_unique_by_type_and_host.py deleted file mode 100644 index e74a8be42..000000000 --- a/neutron/db/migration/alembic_migrations/versions/1fcfc149aca4_agents_unique_by_type_and_host.py +++ /dev/null @@ -1,73 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Add a unique constraint on (agent_type, host) columns to prevent a race -condition when an agent entry is 'upserted'. - -Revision ID: 1fcfc149aca4 -Revises: e197124d4b9 -Create Date: 2013-11-27 18:35:28.148680 - -""" - -revision = '1fcfc149aca4' -down_revision = 'e197124d4b9' - -migration_for_plugins = [ - 'neutron.plugins.brocade.NeutronPlugin.BrocadePluginV2', - 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', - 'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2', - 'neutron.plugins.nec.nec_plugin.NECPluginV2', - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin', - 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin', - 'neutron.plugins.ibm.sdnve_neutron_plugin.SdnvePluginV2', - 'neutron.plugins.oneconvergence.plugin.OneConvergencePluginV2', - 'neutron.plugins.mlnx.mlnx_plugin.MellanoxEswitchPlugin', -] - -from alembic import op - -from neutron.db import migration - - -TABLE_NAME = 'agents' -UC_NAME = 'uniq_agents0agent_type0host' - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_unique_constraint( - name=UC_NAME, - source=TABLE_NAME, - local_cols=['agent_type', 'host'] - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_constraint( - name=UC_NAME, - table_name=TABLE_NAME, - type_='unique' - ) diff --git a/neutron/db/migration/alembic_migrations/versions/2032abe8edac_lbaas_add_status_des.py b/neutron/db/migration/alembic_migrations/versions/2032abe8edac_lbaas_add_status_des.py deleted file mode 100644 index 813f93e96..000000000 --- a/neutron/db/migration/alembic_migrations/versions/2032abe8edac_lbaas_add_status_des.py +++ /dev/null @@ -1,57 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""LBaaS add status description - -Revision ID: 2032abe8edac -Revises: 477a4488d3f4 -Create Date: 2013-06-24 06:51:47.308545 - -""" - -# revision identifiers, used by Alembic. -revision = '2032abe8edac' -down_revision = '477a4488d3f4' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin', -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - -ENTITIES = ['vips', 'pools', 'members', 'healthmonitors'] - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - for entity in ENTITIES: - op.add_column(entity, sa.Column('status_description', sa.String(255))) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - for entity in ENTITIES: - op.drop_column(entity, 'status_description') diff --git a/neutron/db/migration/alembic_migrations/versions/20ae61555e95_ml2_gre_type_driver.py b/neutron/db/migration/alembic_migrations/versions/20ae61555e95_ml2_gre_type_driver.py deleted file mode 100644 index e63668c25..000000000 --- a/neutron/db/migration/alembic_migrations/versions/20ae61555e95_ml2_gre_type_driver.py +++ /dev/null @@ -1,66 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""DB Migration for ML2 GRE Type Driver - -Revision ID: 20ae61555e95 -Revises: 13de305df56e -Create Date: 2013-07-10 17:19:03.021937 - -""" - -# revision identifiers, used by Alembic. -revision = '20ae61555e95' -down_revision = '13de305df56e' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'ml2_gre_allocations', - sa.Column('gre_id', sa.Integer, nullable=False, - autoincrement=False), - sa.Column('allocated', sa.Boolean, nullable=False), - sa.PrimaryKeyConstraint('gre_id') - ) - - op.create_table( - 'ml2_gre_endpoints', - sa.Column('ip_address', sa.String(length=64)), - sa.PrimaryKeyConstraint('ip_address') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('ml2_gre_allocations') - op.drop_table('ml2_gre_endpoints') diff --git a/neutron/db/migration/alembic_migrations/versions/2447ad0e9585_add_ipv6_mode_props.py b/neutron/db/migration/alembic_migrations/versions/2447ad0e9585_add_ipv6_mode_props.py deleted file mode 100644 index f3b444a22..000000000 --- a/neutron/db/migration/alembic_migrations/versions/2447ad0e9585_add_ipv6_mode_props.py +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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 Sean M. Collins (Comcast) - -"""Add IPv6 Subnet properties - -Revision ID: 2447ad0e9585 -Revises: 33dd0a9fa487 -Create Date: 2013-10-23 16:36:44.188904 - -""" - -# revision identifiers, used by Alembic. -revision = '2447ad0e9585' -down_revision = '33dd0a9fa487' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - '*' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - # Workaround for Alemic bug #89 - # https://bitbucket.org/zzzeek/alembic/issue/89 - context = op.get_context() - if context.bind.dialect.name == 'postgresql': - op.execute("CREATE TYPE ipv6_ra_modes AS ENUM ('%s', '%s', '%s')" - % ('slaac', 'dhcpv6-stateful', 'dhcpv6-stateless')) - op.execute("CREATE TYPE ipv6_address_modes AS ENUM ('%s', '%s', '%s')" - % ('slaac', 'dhcpv6-stateful', 'dhcpv6-stateless')) - op.add_column('subnets', - sa.Column('ipv6_ra_mode', - sa.Enum('slaac', - 'dhcpv6-stateful', - 'dhcpv6-stateless', - name='ipv6_ra_modes'), - nullable=True) - ) - op.add_column('subnets', - sa.Column('ipv6_address_mode', - sa.Enum('slaac', - 'dhcpv6-stateful', - 'dhcpv6-stateless', - name='ipv6_address_modes'), - nullable=True) - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_column('subnets', 'ipv6_ra_mode') - op.drop_column('subnets', 'ipv6_address_mode') - context = op.get_context() - if context.bind.dialect.name == 'postgresql': - op.execute('DROP TYPE ipv6_ra_modes') - op.execute('DROP TYPE ipv6_address_modes') diff --git a/neutron/db/migration/alembic_migrations/versions/24c7ea5160d7_cisco_csr_vpnaas.py b/neutron/db/migration/alembic_migrations/versions/24c7ea5160d7_cisco_csr_vpnaas.py deleted file mode 100644 index f7cdfd913..000000000 --- a/neutron/db/migration/alembic_migrations/versions/24c7ea5160d7_cisco_csr_vpnaas.py +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2014 Cisco Systems, 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. - -"""Cisco CSR VPNaaS - - Revision ID: 24c7ea5160d7 - Revises: 492a106273f8 - Create Date: 2014-02-03 13:06:50.407601 -""" - -# revision identifiers, used by Alembic. -revision = '24c7ea5160d7' -down_revision = '492a106273f8' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.vpn.plugin.VPNDriverPlugin', -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'cisco_csr_identifier_map', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('ipsec_site_conn_id', sa.String(length=64), - primary_key=True), - sa.Column('csr_tunnel_id', sa.Integer(), nullable=False), - sa.Column('csr_ike_policy_id', sa.Integer(), nullable=False), - sa.Column('csr_ipsec_policy_id', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['ipsec_site_conn_id'], - ['ipsec_site_connections.id'], - ondelete='CASCADE') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('cisco_csr_identifier_map') diff --git a/neutron/db/migration/alembic_migrations/versions/2528ceb28230_nec_pf_netid_fix.py b/neutron/db/migration/alembic_migrations/versions/2528ceb28230_nec_pf_netid_fix.py deleted file mode 100644 index c2f130109..000000000 --- a/neutron/db/migration/alembic_migrations/versions/2528ceb28230_nec_pf_netid_fix.py +++ /dev/null @@ -1,61 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""NEC PacketFilter network_id nullable fix - -Revision ID: 2528ceb28230 -Revises: 1064e98b7917 -Create Date: 2013-09-24 12:07:43.124256 - -""" - -# revision identifiers, used by Alembic. -revision = '2528ceb28230' -down_revision = '1064e98b7917' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nec.nec_plugin.NECPluginV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('packetfilters', 'network_id', - existing_type=sa.String(length=36), - nullable=False) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - # NOTE(amotoki): There is a bug that nullable of network_id is - # set to True by mistake in folsom_initial (bug 1229508). - # To make sure nullable=False in any revision, nullable is set - # to False in both upgrade and downgrade. - op.alter_column('packetfilters', 'network_id', - existing_type=sa.String(length=36), - nullable=False) diff --git a/neutron/db/migration/alembic_migrations/versions/263772d65691_cisco_db_cleanup_2.py b/neutron/db/migration/alembic_migrations/versions/263772d65691_cisco_db_cleanup_2.py deleted file mode 100644 index 4f3adc447..000000000 --- a/neutron/db/migration/alembic_migrations/versions/263772d65691_cisco_db_cleanup_2.py +++ /dev/null @@ -1,66 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Cisco plugin db cleanup part II - -Revision ID: 263772d65691 -Revises: 35c7c198ddea -Create Date: 2013-07-29 02:31:26.646343 - -""" - -# revision identifiers, used by Alembic. -revision = '263772d65691' -down_revision = '35c7c198ddea' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.cisco.network_plugin.PluginV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.rename_table('credentials', 'cisco_credentials') - op.rename_table('nexusport_bindings', 'cisco_nexusport_bindings') - op.rename_table('qoss', 'cisco_qos_policies') - - op.drop_table('cisco_vlan_ids') - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'cisco_vlan_ids', - sa.Column('vlan_id', sa.Integer, nullable=False), - sa.Column('vlan_used', sa.Boolean), - sa.PrimaryKeyConstraint('vlan_id'), - ) - - op.rename_table('cisco_credentials', 'credentials') - op.rename_table('cisco_nexusport_bindings', 'nexusport_bindings') - op.rename_table('cisco_qos_policies', 'qoss') diff --git a/neutron/db/migration/alembic_migrations/versions/27cc183af192_ml2_vnic_type.py b/neutron/db/migration/alembic_migrations/versions/27cc183af192_ml2_vnic_type.py deleted file mode 100644 index db38e65a2..000000000 --- a/neutron/db/migration/alembic_migrations/versions/27cc183af192_ml2_vnic_type.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""ml2_vnic_type - -Revision ID: 27cc183af192 -Revises: 4ca36cfc898c -Create Date: 2014-02-09 12:19:21.362967 - -""" - -# revision identifiers, used by Alembic. -revision = '27cc183af192' -down_revision = '4ca36cfc898c' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.add_column('ml2_port_bindings', - sa.Column('vnic_type', sa.String(length=64), - nullable=False, - server_default='normal')) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_column('ml2_port_bindings', 'vnic_type') diff --git a/neutron/db/migration/alembic_migrations/versions/27ef74513d33_quota_in_plumgrid_pl.py b/neutron/db/migration/alembic_migrations/versions/27ef74513d33_quota_in_plumgrid_pl.py deleted file mode 100644 index df447813b..000000000 --- a/neutron/db/migration/alembic_migrations/versions/27ef74513d33_quota_in_plumgrid_pl.py +++ /dev/null @@ -1,65 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""quota_in_plumgrid_plugin - -Revision ID: 27ef74513d33 -Revises: 3a520dd165d0 -Create Date: 2013-10-08 10:59:19.860397 - -""" - -# revision identifiers, used by Alembic. -revision = '27ef74513d33' -down_revision = '3a520dd165d0' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.plumgrid.plumgrid_plugin.plumgrid_plugin.' - 'NeutronPluginPLUMgridV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.create_table( - 'quotas', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('resource', sa.String(length=255), nullable=True), - sa.Column('limit', sa.Integer(), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - ### end Alembic commands ### - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('quotas') - ### end Alembic commands ### diff --git a/neutron/db/migration/alembic_migrations/versions/2a3bae1ceb8_nec_port_binding.py b/neutron/db/migration/alembic_migrations/versions/2a3bae1ceb8_nec_port_binding.py deleted file mode 100644 index 943317d21..000000000 --- a/neutron/db/migration/alembic_migrations/versions/2a3bae1ceb8_nec_port_binding.py +++ /dev/null @@ -1,65 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""NEC Port Binding - -Revision ID: 2a3bae1ceb8 -Revises: 46a0efbd8f0 -Create Date: 2013-08-22 11:09:19.955386 - -""" - -# revision identifiers, used by Alembic. -revision = '2a3bae1ceb8' -down_revision = '46a0efbd8f0' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nec.nec_plugin.NECPluginV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'portbindingports', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('host', sa.String(length=255), nullable=False), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ondelete='CASCADE'), - sa.PrimaryKeyConstraint('port_id') - ) - op.create_foreign_key( - 'portinfos_ibfk_1', - source='portinfos', referent='ports', - local_cols=['id'], remote_cols=['id'], - ondelete='CASCADE') - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_constraint('portinfos_ibfk_1', 'portinfos', 'foreignkey') - op.drop_table('portbindingports') diff --git a/neutron/db/migration/alembic_migrations/versions/2a6d0b51f4bb_cisco_plugin_cleanup.py b/neutron/db/migration/alembic_migrations/versions/2a6d0b51f4bb_cisco_plugin_cleanup.py deleted file mode 100644 index 905536ceb..000000000 --- a/neutron/db/migration/alembic_migrations/versions/2a6d0b51f4bb_cisco_plugin_cleanup.py +++ /dev/null @@ -1,88 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""cisco plugin cleanup - -Revision ID: 2a6d0b51f4bb -Revises: 1d76643bcec4 -Create Date: 2013-01-17 22:24:37.730466 - -""" - -# revision identifiers, used by Alembic. -revision = '2a6d0b51f4bb' -down_revision = '1d76643bcec4' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.cisco.network_plugin.PluginV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table(u'portprofile_bindings') - op.drop_table(u'portprofiles') - op.drop_table(u'port_bindings') - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - u'port_bindings', - sa.Column(u'id', sa.Integer(), autoincrement=True, - nullable=False), - sa.Column(u'port_id', sa.String(255), nullable=False), - sa.Column(u'blade_intf_dn', sa.String(255), nullable=False), - sa.Column(u'portprofile_name', sa.String(255), - nullable=True), - sa.Column(u'vlan_name', sa.String(255), nullable=True), - sa.Column(u'vlan_id', sa.Integer(), nullable=True), - sa.Column(u'qos', sa.String(255), nullable=True), - sa.Column(u'tenant_id', sa.String(255), nullable=True), - sa.Column(u'vif_id', sa.String(255), nullable=True), - sa.PrimaryKeyConstraint(u'id') - ) - op.create_table( - u'portprofiles', - sa.Column(u'uuid', sa.String(255), nullable=False), - sa.Column(u'name', sa.String(255), nullable=True), - sa.Column(u'vlan_id', sa.Integer(), nullable=True), - sa.Column(u'qos', sa.String(255), nullable=True), - sa.PrimaryKeyConstraint(u'uuid') - ) - op.create_table( - u'portprofile_bindings', - sa.Column(u'id', sa.String(255), nullable=False), - sa.Column(u'tenant_id', sa.String(255), nullable=True), - sa.Column(u'port_id', sa.String(255), nullable=True), - sa.Column(u'portprofile_id', sa.String(255), nullable=True), - sa.Column(u'default', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['portprofile_id'], ['portprofiles.uuid'], ), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ), - sa.PrimaryKeyConstraint(u'id') - ) diff --git a/neutron/db/migration/alembic_migrations/versions/2c4af419145b_l3_support.py b/neutron/db/migration/alembic_migrations/versions/2c4af419145b_l3_support.py deleted file mode 100644 index 82aa30602..000000000 --- a/neutron/db/migration/alembic_migrations/versions/2c4af419145b_l3_support.py +++ /dev/null @@ -1,56 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""l3_support - -Revision ID: 2c4af419145b -Revises: folsom -Create Date: 2013-03-11 19:26:45.697774 - -""" - -# revision identifiers, used by Alembic. -revision = '2c4af419145b' -down_revision = 'folsom' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2', - 'neutron.plugins.hyperv.hyperv_neutron_plugin.HyperVNeutronPlugin', - 'neutron.plugins.midonet.plugin.MidonetPluginV2', - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin', - 'neutron.plugins.embrane.plugins.embrane_ovs_plugin.EmbraneOvsPlugin', -] - -from neutron.db import migration -from neutron.db.migration.alembic_migrations import common_ext_ops - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - common_ext_ops.upgrade_l3() - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - common_ext_ops.downgrade_l3() diff --git a/neutron/db/migration/alembic_migrations/versions/2db5203cb7a9_nuage_floatingip.py b/neutron/db/migration/alembic_migrations/versions/2db5203cb7a9_nuage_floatingip.py deleted file mode 100644 index 57876d096..000000000 --- a/neutron/db/migration/alembic_migrations/versions/2db5203cb7a9_nuage_floatingip.py +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""nuage_floatingip - -Revision ID: 2db5203cb7a9 -Revises: 10cd28e692e9 -Create Date: 2014-05-19 16:39:42.048125 - -""" - -# revision identifiers, used by Alembic. -revision = '2db5203cb7a9' -down_revision = '10cd28e692e9' - -migration_for_plugins = [ - 'neutron.plugins.nuage.plugin.NuagePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'nuage_floatingip_pool_mapping', - sa.Column('fip_pool_id', sa.String(length=36), nullable=False), - sa.Column('net_id', sa.String(length=36), nullable=True), - sa.Column('router_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['net_id'], ['networks.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['router_id'], ['routers.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('fip_pool_id'), - ) - op.create_table( - 'nuage_floatingip_mapping', - sa.Column('fip_id', sa.String(length=36), nullable=False), - sa.Column('router_id', sa.String(length=36), nullable=True), - sa.Column('nuage_fip_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['fip_id'], ['floatingips.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('fip_id'), - ) - op.rename_table('net_partitions', 'nuage_net_partitions') - op.rename_table('net_partition_router_mapping', - 'nuage_net_partition_router_mapping') - op.rename_table('router_zone_mapping', 'nuage_router_zone_mapping') - op.rename_table('subnet_l2dom_mapping', 'nuage_subnet_l2dom_mapping') - op.rename_table('port_mapping', 'nuage_port_mapping') - op.rename_table('routerroutes_mapping', 'nuage_routerroutes_mapping') - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('nuage_floatingip_mapping') - op.drop_table('nuage_floatingip_pool_mapping') - op.rename_table('nuage_net_partitions', 'net_partitions') - op.rename_table('nuage_net_partition_router_mapping', - 'net_partition_router_mapping') - op.rename_table('nuage_router_zone_mapping', 'router_zone_mapping') - op.rename_table('nuage_subnet_l2dom_mapping', 'subnet_l2dom_mapping') - op.rename_table('nuage_port_mapping', 'port_mapping') - op.rename_table('nuage_routerroutes_mapping', 'routerroutes_mapping') diff --git a/neutron/db/migration/alembic_migrations/versions/2eeaf963a447_floatingip_status.py b/neutron/db/migration/alembic_migrations/versions/2eeaf963a447_floatingip_status.py deleted file mode 100644 index 25c40276e..000000000 --- a/neutron/db/migration/alembic_migrations/versions/2eeaf963a447_floatingip_status.py +++ /dev/null @@ -1,81 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""floatingip_status - -Revision ID: 2eeaf963a447 -Revises: f44ab9871cd6 -Create Date: 2014-01-14 11:58:13.754747 - -""" - -# revision identifiers, used by Alembic. -revision = '2eeaf963a447' -down_revision = 'f44ab9871cd6' - -# This migration is applied to all L3 capable plugins - -migration_for_plugins = [ - 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2', - 'neutron.plugins.brocade.NeutronPlugin.BrocadePluginV2', - 'neutron.plugins.cisco.network_plugin.PluginV2', - 'neutron.plugins.cisco.n1kv.n1kv_neutron_plugin.N1kvNeutronPluginV2', - 'neutron.plugins.embrane.plugins.embrane_ovs_plugin.EmbraneOvsPlugin', - 'neutron.plugins.hyperv.hyperv_neutron_plugin.HyperVNeutronPlugin', - 'neutron.plugins.ibm.sdnve_neutron_plugin.SdnvePluginV2', - 'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2', - 'neutron.plugins.metaplugin.meta_neutron_plugin.MetaPluginV2', - 'neutron.plugins.mlnx.mlnx_plugin.MellanoxEswitchPlugin', - 'neutron.plugins.midonet.plugin.MidonetPluginV2', - 'neutron.plugins.ml2.plugin.Ml2Plugin', - 'neutron.plugins.nec.nec_plugin.NECPluginV2', - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.nuage.plugin.NuagePlugin', - 'neutron.plugins.oneconvergence.plugin.OneConvergencePluginV2', - 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', - 'neutron.plugins.plumgrid.plumgrid_plugin.plumgrid_plugin.' - 'NeutronPluginPLUMgridV2', - 'neutron.plugins.ryu.ryu_neutron_plugin.RyuNeutronPluginV2', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin', -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - op.add_column('floatingips', - sa.Column('last_known_router_id', - sa.String(length=36), - nullable=True)) - op.add_column('floatingips', - sa.Column('status', - sa.String(length=16), - nullable=True)) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - op.drop_column('floatingips', 'last_known_router_id') - op.drop_column('floatingips', 'status') diff --git a/neutron/db/migration/alembic_migrations/versions/32a65f71af51_ml2_portbinding.py b/neutron/db/migration/alembic_migrations/versions/32a65f71af51_ml2_portbinding.py deleted file mode 100644 index 6256186f4..000000000 --- a/neutron/db/migration/alembic_migrations/versions/32a65f71af51_ml2_portbinding.py +++ /dev/null @@ -1,70 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""ml2 portbinding - -Revision ID: 32a65f71af51 -Revises: 14f24494ca31 -Create Date: 2013-09-03 08:40:22.706651 - -""" - -# revision identifiers, used by Alembic. -revision = '32a65f71af51' -down_revision = '14f24494ca31' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'ml2_port_bindings', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('host', sa.String(length=255), nullable=False), - sa.Column('vif_type', sa.String(length=64), nullable=False), - sa.Column('cap_port_filter', sa.Boolean(), nullable=False), - sa.Column('driver', sa.String(length=64), nullable=True), - sa.Column('segment', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['segment'], ['ml2_network_segments.id'], - ondelete='SET NULL'), - sa.PrimaryKeyConstraint('port_id') - ) - - # Note that 176a85fc7d79_add_portbindings_db.py was never enabled - # for ml2, so there is no need to drop the portbindingports table - # that is no longer used. - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('ml2_port_bindings') diff --git a/neutron/db/migration/alembic_migrations/versions/32b517556ec9_remove_tunnelip_mode.py b/neutron/db/migration/alembic_migrations/versions/32b517556ec9_remove_tunnelip_mode.py deleted file mode 100644 index 4c5c1e98b..000000000 --- a/neutron/db/migration/alembic_migrations/versions/32b517556ec9_remove_tunnelip_mode.py +++ /dev/null @@ -1,58 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""remove TunnelIP model - -Revision ID: 32b517556ec9 -Revises: 176a85fc7d79 -Create Date: 2013-05-23 06:46:57.390838 - -""" - -# revision identifiers, used by Alembic. -revision = '32b517556ec9' -down_revision = '176a85fc7d79' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('ovs_tunnel_ips') - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'ovs_tunnel_ips', - sa.Column('ip_address', sa.String(length=255), nullable=False), - sa.PrimaryKeyConstraint('ip_address') - ) diff --git a/neutron/db/migration/alembic_migrations/versions/338d7508968c_vpnaas_peer_address_.py b/neutron/db/migration/alembic_migrations/versions/338d7508968c_vpnaas_peer_address_.py deleted file mode 100644 index 9675559c4..000000000 --- a/neutron/db/migration/alembic_migrations/versions/338d7508968c_vpnaas_peer_address_.py +++ /dev/null @@ -1,55 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""vpnaas peer_address size increase - -Revision ID: 338d7508968c -Revises: 4a666eb208c2 -Create Date: 2013-09-16 11:31:39.410189 - -""" - -# revision identifiers, used by Alembic. -revision = '338d7508968c' -down_revision = '4a666eb208c2' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.vpn.plugin.VPNDriverPlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('ipsec_site_connections', 'peer_address', - type_=sa.String(255), existing_type=sa.String(64)) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('ipsec_site_connections', 'peer_address', - type_=sa.String(64), existing_type=sa.String(255)) diff --git a/neutron/db/migration/alembic_migrations/versions/33c3db036fe4_set_length_of_description_field_metering.py b/neutron/db/migration/alembic_migrations/versions/33c3db036fe4_set_length_of_description_field_metering.py deleted file mode 100644 index 0882aa7f4..000000000 --- a/neutron/db/migration/alembic_migrations/versions/33c3db036fe4_set_length_of_description_field_metering.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""set_length_of_description_field_metering - -Revision ID: 33c3db036fe4 -Revises: b65aa907aec -Create Date: 2014-03-25 11:04:27.341830 - -""" - -# revision identifiers, used by Alembic. -revision = '33c3db036fe4' -down_revision = 'b65aa907aec' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.metering.metering_plugin.MeteringPlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.execute("CREATE TABLE IF NOT EXISTS meteringlabels( " - "tenant_id VARCHAR(255) NULL, " - "id VARCHAR(36) PRIMARY KEY NOT NULL, " - "name VARCHAR(255) NULL, " - "description VARCHAR(255) NULL)") - - op.alter_column('meteringlabels', 'description', type_=sa.String(1024), - existing_nullable=True) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - pass diff --git a/neutron/db/migration/alembic_migrations/versions/33dd0a9fa487_embrane_lbaas_driver.py b/neutron/db/migration/alembic_migrations/versions/33dd0a9fa487_embrane_lbaas_driver.py deleted file mode 100644 index aadf02d26..000000000 --- a/neutron/db/migration/alembic_migrations/versions/33dd0a9fa487_embrane_lbaas_driver.py +++ /dev/null @@ -1,61 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""embrane_lbaas_driver - -Revision ID: 33dd0a9fa487 -Revises: 19180cf98af6 -Create Date: 2014-02-25 00:15:35.567111 - -""" - -# revision identifiers, used by Alembic. -revision = '33dd0a9fa487' -down_revision = '19180cf98af6' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - u'embrane_pool_port', - sa.Column(u'pool_id', sa.String(length=36), nullable=False), - sa.Column(u'port_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['pool_id'], [u'pools.id'], - name=u'embrane_pool_port_ibfk_1'), - sa.ForeignKeyConstraint(['port_id'], [u'ports.id'], - name=u'embrane_pool_port_ibfk_2'), - sa.PrimaryKeyConstraint(u'pool_id')) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table(u'embrane_pool_port') diff --git a/neutron/db/migration/alembic_migrations/versions/35c7c198ddea_lbaas_healthmon_del_status.py b/neutron/db/migration/alembic_migrations/versions/35c7c198ddea_lbaas_healthmon_del_status.py deleted file mode 100644 index 574172694..000000000 --- a/neutron/db/migration/alembic_migrations/versions/35c7c198ddea_lbaas_healthmon_del_status.py +++ /dev/null @@ -1,58 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""remove status from HealthMonitor - -Revision ID: 35c7c198ddea -Revises: 11c6e18605c8 -Create Date: 2013-08-02 23:14:54.037976 - -""" - -# revision identifiers, used by Alembic. -revision = '35c7c198ddea' -down_revision = '11c6e18605c8' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin', -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - op.drop_column('healthmonitors', 'status') - op.drop_column('healthmonitors', 'status_description') - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.add_column('healthmonitors', sa.Column('status', - sa.String(16), - nullable=False)) - op.add_column('healthmonitors', sa.Column('status_description', - sa.String(255))) diff --git a/neutron/db/migration/alembic_migrations/versions/363468ac592c_nvp_network_gw.py b/neutron/db/migration/alembic_migrations/versions/363468ac592c_nvp_network_gw.py deleted file mode 100644 index e2727e60e..000000000 --- a/neutron/db/migration/alembic_migrations/versions/363468ac592c_nvp_network_gw.py +++ /dev/null @@ -1,100 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""nvp_network_gw - -Revision ID: 363468ac592c -Revises: 1c33fa3cd1a1 -Create Date: 2013-02-07 03:19:14.455372 - -""" - -# revision identifiers, used by Alembic. -revision = '363468ac592c' -down_revision = '1c33fa3cd1a1' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - op.create_table('networkgateways', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('tenant_id', sa.String(length=36), - nullable=True), - sa.Column('default', sa.Boolean(), nullable=True), - sa.PrimaryKeyConstraint('id')) - op.create_table('networkgatewaydevices', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('network_gateway_id', sa.String(length=36), - nullable=True), - sa.Column('interface_name', sa.String(length=64), - nullable=True), - sa.ForeignKeyConstraint(['network_gateway_id'], - ['networkgateways.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id')) - op.create_table('networkconnections', - sa.Column('tenant_id', sa.String(length=255), - nullable=True), - sa.Column('network_gateway_id', sa.String(length=36), - nullable=True), - sa.Column('network_id', sa.String(length=36), - nullable=True), - sa.Column('segmentation_type', - sa.Enum('flat', 'vlan', - name="net_conn_seg_type"), - nullable=True), - sa.Column('segmentation_id', sa.Integer(), - nullable=True), - sa.Column('port_id', sa.String(length=36), - nullable=False), - sa.ForeignKeyConstraint(['network_gateway_id'], - ['networkgateways.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('port_id'), - sa.UniqueConstraint('network_gateway_id', - 'segmentation_type', - 'segmentation_id')) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('networkconnections') - op.drop_table('networkgatewaydevices') - op.drop_table('networkgateways') diff --git a/neutron/db/migration/alembic_migrations/versions/38335592a0dc_nvp_portmap.py b/neutron/db/migration/alembic_migrations/versions/38335592a0dc_nvp_portmap.py deleted file mode 100644 index a5304ec22..000000000 --- a/neutron/db/migration/alembic_migrations/versions/38335592a0dc_nvp_portmap.py +++ /dev/null @@ -1,62 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""nvp_portmap - -Revision ID: 38335592a0dc -Revises: 49332180ca96 -Create Date: 2013-01-15 06:04:56.328991 - -""" - -# revision identifiers, used by Alembic. -revision = '38335592a0dc' -down_revision = '49332180ca96' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'quantum_nvp_port_mapping', - sa.Column('quantum_id', sa.String(length=36), nullable=False), - sa.Column('nvp_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['quantum_id'], ['ports.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('quantum_id')) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('quantum_nvp_port_mapping') diff --git a/neutron/db/migration/alembic_migrations/versions/38fc1f6789f8_cisco_n1kv_overlay.py b/neutron/db/migration/alembic_migrations/versions/38fc1f6789f8_cisco_n1kv_overlay.py deleted file mode 100644 index 8d1178ce0..000000000 --- a/neutron/db/migration/alembic_migrations/versions/38fc1f6789f8_cisco_n1kv_overlay.py +++ /dev/null @@ -1,57 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Cisco N1KV overlay support - -Revision ID: 38fc1f6789f8 -Revises: 1efb85914233 -Create Date: 2013-08-20 18:31:16.158387 - -""" - -revision = '38fc1f6789f8' -down_revision = '1efb85914233' - -migration_for_plugins = [ - 'neutron.plugins.cisco.network_plugin.PluginV2' -] - -import sqlalchemy as sa - -from neutron.db import migration - - -new_type = sa.Enum('vlan', 'overlay', 'trunk', 'multi-segment', - name='vlan_type') -old_type = sa.Enum('vlan', 'vxlan', 'trunk', 'multi-segment', - name='vlan_type') - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - migration.alter_enum('cisco_network_profiles', 'segment_type', new_type, - nullable=False) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - migration.alter_enum('cisco_network_profiles', 'segment_type', old_type, - nullable=False) diff --git a/neutron/db/migration/alembic_migrations/versions/39cf3f799352_fwaas_havana_2_model.py b/neutron/db/migration/alembic_migrations/versions/39cf3f799352_fwaas_havana_2_model.py deleted file mode 100644 index a114df1f8..000000000 --- a/neutron/db/migration/alembic_migrations/versions/39cf3f799352_fwaas_havana_2_model.py +++ /dev/null @@ -1,109 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""FWaaS Havana-2 model - -Revision ID: 39cf3f799352 -Revises: e6b16a30d97 -Create Date: 2013-07-10 16:16:51.302943 - -""" - -# revision identifiers, used by Alembic. -revision = '39cf3f799352' -down_revision = 'e6b16a30d97' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.firewall.fwaas_plugin.FirewallPlugin', -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('firewall_rules') - op.drop_table('firewalls') - op.drop_table('firewall_policies') - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'firewall_policies', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('description', sa.String(length=1024), nullable=True), - sa.Column('shared', sa.Boolean(), autoincrement=False, nullable=True), - sa.Column('audited', sa.Boolean(), autoincrement=False, - nullable=True), - sa.PrimaryKeyConstraint('id')) - op.create_table( - 'firewalls', sa.Column('tenant_id', sa.String(length=255), - nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('description', sa.String(length=1024), nullable=True), - sa.Column('shared', sa.Boolean(), autoincrement=False, nullable=True), - sa.Column('admin_state_up', sa.Boolean(), autoincrement=False, - nullable=True), - sa.Column('status', sa.String(length=16), nullable=True), - sa.Column('firewall_policy_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['firewall_policy_id'], - ['firewall_policies.id'], - name='firewalls_ibfk_1'), - sa.PrimaryKeyConstraint('id')) - op.create_table( - 'firewall_rules', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('description', sa.String(length=1024), nullable=True), - sa.Column('firewall_policy_id', sa.String(length=36), nullable=True), - sa.Column('shared', sa.Boolean(), autoincrement=False, - nullable=True), - sa.Column('protocol', sa.String(length=24), nullable=True), - sa.Column('ip_version', sa.Integer(), autoincrement=False, - nullable=False), - sa.Column('source_ip_address', sa.String(length=46), nullable=True), - sa.Column('destination_ip_address', sa.String(length=46), - nullable=True), - sa.Column('source_port_range_min', sa.Integer(), nullable=True), - sa.Column('source_port_range_max', sa.Integer(), nullable=True), - sa.Column('destination_port_range_min', sa.Integer(), nullable=True), - sa.Column('destination_port_range_max', sa.Integer(), nullable=True), - sa.Column('action', - sa.Enum('allow', 'deny', name='firewallrules_action'), - nullable=True), - sa.Column('enabled', sa.Boolean(), autoincrement=False, - nullable=True), - sa.Column('position', sa.Integer(), autoincrement=False, - nullable=True), - sa.ForeignKeyConstraint(['firewall_policy_id'], - ['firewall_policies.id'], - name='firewall_rules_ibfk_1'), - sa.PrimaryKeyConstraint('id')) diff --git a/neutron/db/migration/alembic_migrations/versions/3a520dd165d0_cisco_nexus_multi_switch.py b/neutron/db/migration/alembic_migrations/versions/3a520dd165d0_cisco_nexus_multi_switch.py deleted file mode 100644 index 7d13e742d..000000000 --- a/neutron/db/migration/alembic_migrations/versions/3a520dd165d0_cisco_nexus_multi_switch.py +++ /dev/null @@ -1,59 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Cisco Nexus multi-switch - -Revision ID: 3a520dd165d0 -Revises: 2528ceb28230 -Create Date: 2013-09-28 15:23:38.872682 - -""" - -# revision identifiers, used by Alembic. -revision = '3a520dd165d0' -down_revision = '2528ceb28230' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.cisco.network_plugin.PluginV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.add_column( - 'cisco_nexusport_bindings', - sa.Column('instance_id', sa.String(length=255), nullable=False)) - op.add_column( - 'cisco_nexusport_bindings', - sa.Column('switch_ip', sa.String(length=255), nullable=False)) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_column('cisco_nexusport_bindings', 'switch_ip') - op.drop_column('cisco_nexusport_bindings', 'instance_id') diff --git a/neutron/db/migration/alembic_migrations/versions/3b54bf9e29f7_nec_plugin_sharednet.py b/neutron/db/migration/alembic_migrations/versions/3b54bf9e29f7_nec_plugin_sharednet.py deleted file mode 100644 index fb2b776f5..000000000 --- a/neutron/db/migration/alembic_migrations/versions/3b54bf9e29f7_nec_plugin_sharednet.py +++ /dev/null @@ -1,84 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""NEC plugin sharednet - -Revision ID: 3b54bf9e29f7 -Revises: 511471cc46b -Create Date: 2013-02-17 09:21:48.287134 - -""" - -# revision identifiers, used by Alembic. -revision = '3b54bf9e29f7' -down_revision = '511471cc46b' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nec.nec_plugin.NECPluginV2' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'ofctenantmappings', - sa.Column('ofc_id', sa.String(length=255), nullable=False), - sa.Column('quantum_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('quantum_id'), - sa.UniqueConstraint('ofc_id') - ) - op.create_table( - 'ofcnetworkmappings', - sa.Column('ofc_id', sa.String(length=255), nullable=False), - sa.Column('quantum_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('quantum_id'), - sa.UniqueConstraint('ofc_id') - ) - op.create_table( - 'ofcportmappings', - sa.Column('ofc_id', sa.String(length=255), nullable=False), - sa.Column('quantum_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('quantum_id'), - sa.UniqueConstraint('ofc_id') - ) - op.create_table( - 'ofcfiltermappings', - sa.Column('ofc_id', sa.String(length=255), nullable=False), - sa.Column('quantum_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('quantum_id'), - sa.UniqueConstraint('ofc_id') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('ofcfiltermappings') - op.drop_table('ofcportmappings') - op.drop_table('ofcnetworkmappings') - op.drop_table('ofctenantmappings') diff --git a/neutron/db/migration/alembic_migrations/versions/3c6e57a23db4_add_multiprovider.py b/neutron/db/migration/alembic_migrations/versions/3c6e57a23db4_add_multiprovider.py deleted file mode 100644 index 70f66ac61..000000000 --- a/neutron/db/migration/alembic_migrations/versions/3c6e57a23db4_add_multiprovider.py +++ /dev/null @@ -1,103 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""add multiprovider - -Revision ID: 3c6e57a23db4 -Revises: 86cf4d88bd3 -Create Date: 2013-07-10 12:43:35.769283 - -""" - -# revision identifiers, used by Alembic. -revision = '3c6e57a23db4' -down_revision = '86cf4d88bd3' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'nvp_multi_provider_networks', - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('network_id'), - mysql_engine='InnoDB' - ) - op.create_table('rename_nvp_network_bindings', - sa.Column('network_id', sa.String(length=36), - primary_key=True), - sa.Column('binding_type', - sa.Enum( - 'flat', 'vlan', 'stt', 'gre', 'l3_ext', - name=( - 'nvp_network_bindings_binding_type')), - nullable=False, primary_key=True), - sa.Column('phy_uuid', sa.String(36), primary_key=True, - nullable=True), - sa.Column('vlan_id', sa.Integer, primary_key=True, - nullable=True, autoincrement=False)) - # copy data from nvp_network_bindings into rename_nvp_network_bindings - op.execute("INSERT INTO rename_nvp_network_bindings SELECT network_id, " - "binding_type, phy_uuid, vlan_id from nvp_network_bindings") - - op.drop_table('nvp_network_bindings') - op.rename_table('rename_nvp_network_bindings', 'nvp_network_bindings') - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - # Delete the multi_provider_network entries from nvp_network_bindings - op.execute("DELETE from nvp_network_bindings WHERE network_id IN " - "(SELECT network_id from nvp_multi_provider_networks)") - - # create table with previous contains - op.create_table( - 'rename_nvp_network_bindings', - sa.Column('network_id', sa.String(length=36), primary_key=True), - sa.Column('binding_type', - sa.Enum('flat', 'vlan', 'stt', 'gre', 'l3_ext', - name=('nvp_network_bindings_binding_type')), - nullable=False), - sa.Column('phy_uuid', sa.String(36), nullable=True), - sa.Column('vlan_id', sa.Integer, nullable=True, autoincrement=False)) - - # copy data from nvp_network_bindings into rename_nvp_network_bindings - op.execute("INSERT INTO rename_nvp_network_bindings SELECT network_id, " - "binding_type, phy_uuid, vlan_id from nvp_network_bindings") - - op.drop_table('nvp_network_bindings') - op.rename_table('rename_nvp_network_bindings', 'nvp_network_bindings') - op.drop_table('nvp_multi_provider_networks') diff --git a/neutron/db/migration/alembic_migrations/versions/3cabb850f4a5_table_to_track_port_.py b/neutron/db/migration/alembic_migrations/versions/3cabb850f4a5_table_to_track_port_.py deleted file mode 100644 index dbfdc5953..000000000 --- a/neutron/db/migration/alembic_migrations/versions/3cabb850f4a5_table_to_track_port_.py +++ /dev/null @@ -1,63 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Table to track port to host associations - -Revision ID: 3cabb850f4a5 -Revises: 5918cbddab04 -Create Date: 2013-06-24 14:30:33.533562 - -""" - -# revision identifiers, used by Alembic. -revision = '3cabb850f4a5' -down_revision = '5918cbddab04' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.create_table('portlocations', - sa.Column('port_id', sa.String(length=255), - primary_key=True, nullable=False), - sa.Column('host_id', - sa.String(length=255), nullable=False) - ) - ### end Alembic commands ### - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('portlocations') - ### end Alembic commands ### diff --git a/neutron/db/migration/alembic_migrations/versions/3cb5d900c5de_security_groups.py b/neutron/db/migration/alembic_migrations/versions/3cb5d900c5de_security_groups.py deleted file mode 100644 index 057a360aa..000000000 --- a/neutron/db/migration/alembic_migrations/versions/3cb5d900c5de_security_groups.py +++ /dev/null @@ -1,103 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""security_groups - -Revision ID: 3cb5d900c5de -Revises: 48b6f43f7471 -Create Date: 2013-01-08 00:13:43.051078 - -""" - -# revision identifiers, used by Alembic. -revision = '3cb5d900c5de' -down_revision = '48b6f43f7471' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2', - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', - 'neutron.plugins.nec.nec_plugin.NECPluginV2', - 'neutron.plugins.ryu.ryu_neutron_plugin.RyuNeutronPluginV2', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin', - 'neutron.plugins.oneconvergence.plugin.OneConvergencePluginV2', -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.create_table( - 'securitygroups', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'securitygrouprules', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('security_group_id', sa.String(length=36), nullable=False), - sa.Column('remote_group_id', sa.String(length=36), nullable=True), - sa.Column('direction', - sa.Enum('ingress', 'egress', - name='securitygrouprules_direction'), - nullable=True), - sa.Column('ethertype', sa.String(length=40), nullable=True), - sa.Column('protocol', sa.String(length=40), nullable=True), - sa.Column('port_range_min', sa.Integer(), nullable=True), - sa.Column('port_range_max', sa.Integer(), nullable=True), - sa.Column('remote_ip_prefix', sa.String(length=255), nullable=True), - sa.ForeignKeyConstraint(['security_group_id'], ['securitygroups.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['remote_group_id'], ['securitygroups.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'securitygroupportbindings', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('security_group_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ondelete='CASCADE'), - sa.ForeignKeyConstraint(['security_group_id'], ['securitygroups.id']), - sa.PrimaryKeyConstraint('port_id', 'security_group_id') - ) - ### end Alembic commands ### - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('securitygroupportbindings') - op.drop_table('securitygrouprules') - op.drop_table('securitygroups') - ### end Alembic commands ### diff --git a/neutron/db/migration/alembic_migrations/versions/3cbf70257c28_nvp_mac_learning.py b/neutron/db/migration/alembic_migrations/versions/3cbf70257c28_nvp_mac_learning.py deleted file mode 100644 index b62ebcab2..000000000 --- a/neutron/db/migration/alembic_migrations/versions/3cbf70257c28_nvp_mac_learning.py +++ /dev/null @@ -1,63 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""nvp_mac_learning - -Revision ID: 3cbf70257c28 -Revises: 5ac71e65402c -Create Date: 2013-05-15 10:15:50.875314 - -""" - -# revision identifiers, used by Alembic. -revision = '3cbf70257c28' -down_revision = '5ac71e65402c' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'maclearningstates', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('mac_learning_enabled', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint( - ['port_id'], ['ports.id'], ondelete='CASCADE'), - sa.PrimaryKeyConstraint('port_id')) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('maclearningstates') diff --git a/neutron/db/migration/alembic_migrations/versions/3d2585038b95_vmware_nsx.py b/neutron/db/migration/alembic_migrations/versions/3d2585038b95_vmware_nsx.py deleted file mode 100644 index c51f02a3d..000000000 --- a/neutron/db/migration/alembic_migrations/versions/3d2585038b95_vmware_nsx.py +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""VMware NSX rebranding - -Revision ID: 3d2585038b95 -Revises: 157a5d299379 -Create Date: 2014-02-11 18:18:34.319031 - -""" - -# revision identifiers, used by Alembic. -revision = '3d2585038b95' -down_revision = '157a5d299379' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.rename_table('nvp_network_bindings', 'tz_network_bindings') - op.rename_table('nvp_multi_provider_networks', 'multi_provider_networks') - - engine = op.get_bind().engine - if engine.name == 'postgresql': - op.execute("ALTER TYPE nvp_network_bindings_binding_type " - "RENAME TO tz_network_bindings_binding_type;") - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - engine = op.get_bind().engine - if engine.name == 'postgresql': - op.execute("ALTER TYPE tz_network_bindings_binding_type " - "RENAME TO nvp_network_bindings_binding_type;") - - op.rename_table('multi_provider_networks', 'nvp_multi_provider_networks') - op.rename_table('tz_network_bindings', 'nvp_network_bindings') diff --git a/neutron/db/migration/alembic_migrations/versions/3d3cb89d84ee_nsx_switch_mappings.py b/neutron/db/migration/alembic_migrations/versions/3d3cb89d84ee_nsx_switch_mappings.py deleted file mode 100644 index 2b4da4891..000000000 --- a/neutron/db/migration/alembic_migrations/versions/3d3cb89d84ee_nsx_switch_mappings.py +++ /dev/null @@ -1,61 +0,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. -# - -"""nsx_switch_mappings - -Revision ID: 3d3cb89d84ee -Revises: 1421183d533f -Create Date: 2014-01-07 15:37:41.323020 - -""" - -# revision identifiers, used by Alembic. -revision = '3d3cb89d84ee' -down_revision = '1421183d533f' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - # Create table for network mappings - op.create_table( - 'neutron_nsx_network_mappings', - sa.Column('neutron_id', sa.String(length=36), nullable=False), - sa.Column('nsx_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['neutron_id'], ['networks.id'], - ondelete='CASCADE'), - # There might be multiple switches for a neutron network - sa.PrimaryKeyConstraint('neutron_id', 'nsx_id'), - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('neutron_nsx_network_mappings') diff --git a/neutron/db/migration/alembic_migrations/versions/3d6fae8b70b0_nvp_lbaas_plugin.py b/neutron/db/migration/alembic_migrations/versions/3d6fae8b70b0_nvp_lbaas_plugin.py deleted file mode 100644 index cc4807fa1..000000000 --- a/neutron/db/migration/alembic_migrations/versions/3d6fae8b70b0_nvp_lbaas_plugin.py +++ /dev/null @@ -1,82 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""nvp lbaas plugin - -Revision ID: 3d6fae8b70b0 -Revises: 3ed8f075e38a -Create Date: 2013-09-13 19:34:41.522665 - -""" - -# revision identifiers, used by Alembic. -revision = '3d6fae8b70b0' -down_revision = '3ed8f075e38a' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'vcns_edge_pool_bindings', - sa.Column('pool_id', sa.String(length=36), nullable=False), - sa.Column('edge_id', sa.String(length=36), nullable=False), - sa.Column('pool_vseid', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['pool_id'], ['pools.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('pool_id', 'edge_id') - ) - op.create_table( - 'vcns_edge_monitor_bindings', - sa.Column('monitor_id', sa.String(length=36), nullable=False), - sa.Column('edge_id', sa.String(length=36), nullable=False), - sa.Column('monitor_vseid', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['monitor_id'], ['healthmonitors.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('monitor_id', 'edge_id') - ) - op.create_table( - 'vcns_edge_vip_bindings', - sa.Column('vip_id', sa.String(length=36), nullable=False), - sa.Column('edge_id', sa.String(length=36), nullable=True), - sa.Column('vip_vseid', sa.String(length=36), nullable=True), - sa.Column('app_profileid', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['vip_id'], ['vips.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('vip_id') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('vcns_edge_vip_bindings') - op.drop_table('vcns_edge_monitor_bindings') - op.drop_table('vcns_edge_pool_bindings') diff --git a/neutron/db/migration/alembic_migrations/versions/3ed8f075e38a_nvp_fwaas_plugin.py b/neutron/db/migration/alembic_migrations/versions/3ed8f075e38a_nvp_fwaas_plugin.py deleted file mode 100755 index 19c08a7f2..000000000 --- a/neutron/db/migration/alembic_migrations/versions/3ed8f075e38a_nvp_fwaas_plugin.py +++ /dev/null @@ -1,60 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""nvp fwaas plugin - -Revision ID: 3ed8f075e38a -Revises: 338d7508968c -Create Date: 2013-09-13 19:14:25.509033 - -""" - -# revision identifiers, used by Alembic. -revision = '3ed8f075e38a' -down_revision = '338d7508968c' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'vcns_firewall_rule_bindings', - sa.Column('rule_id', sa.String(length=36), nullable=False), - sa.Column('edge_id', sa.String(length=36), nullable=False), - sa.Column('rule_vseid', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['rule_id'], ['firewall_rules.id'], ), - sa.PrimaryKeyConstraint('rule_id', 'edge_id') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('vcns_firewall_rule_bindings') diff --git a/neutron/db/migration/alembic_migrations/versions/40b0aff0302e_mlnx_initial.py b/neutron/db/migration/alembic_migrations/versions/40b0aff0302e_mlnx_initial.py deleted file mode 100644 index 7da75d927..000000000 --- a/neutron/db/migration/alembic_migrations/versions/40b0aff0302e_mlnx_initial.py +++ /dev/null @@ -1,194 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""mlnx_initial - -Revision ID: 40b0aff0302e -Revises: 49f5e553f61f -Create Date: 2014-01-12 14:51:49.273105 - -""" - -# revision identifiers, used by Alembic. -revision = '40b0aff0302e' -down_revision = '49f5e553f61f' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.mlnx.mlnx_plugin.MellanoxEswitchPlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'securitygroups', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.PrimaryKeyConstraint('id'), - ) - - op.create_table( - 'segmentation_id_allocation', - sa.Column('physical_network', sa.String(length=64), nullable=False), - sa.Column('segmentation_id', sa.Integer(), autoincrement=False, - nullable=False), - sa.Column('allocated', sa.Boolean(), nullable=False), - sa.PrimaryKeyConstraint('physical_network', 'segmentation_id'), - ) - - op.create_table( - 'quotas', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('tenant_id', sa.String(255), index=True), - sa.Column('resource', sa.String(255)), - sa.Column('limit', sa.Integer()), - sa.PrimaryKeyConstraint('id') - ) - - op.create_table( - 'mlnx_network_bindings', - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('network_type', sa.String(length=32), nullable=False), - sa.Column('physical_network', sa.String(length=64), nullable=True), - sa.Column('segmentation_id', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('network_id'), - ) - - op.create_table( - 'networkdhcpagentbindings', - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('dhcp_agent_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['dhcp_agent_id'], ['agents.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('network_id', 'dhcp_agent_id'), - ) - - op.create_table( - 'securitygrouprules', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('security_group_id', sa.String(length=36), nullable=False), - sa.Column('remote_group_id', sa.String(length=36), nullable=True), - sa.Column('direction', - sa.Enum('ingress', 'egress', - name='securitygrouprules_direction'), - nullable=True), - sa.Column('ethertype', sa.String(length=40), nullable=True), - sa.Column('protocol', sa.String(length=40), nullable=True), - sa.Column('port_range_min', sa.Integer(), nullable=True), - sa.Column('port_range_max', sa.Integer(), nullable=True), - sa.Column('remote_ip_prefix', sa.String(length=255), nullable=True), - sa.ForeignKeyConstraint(['remote_group_id'], ['securitygroups.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['security_group_id'], ['securitygroups.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id'), - ) - - op.create_table( - 'port_profile', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('vnic_type', sa.String(length=32), nullable=False), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('port_id'), - ) - - op.add_column('routers', sa.Column('enable_snat', sa.Boolean(), - nullable=False, default=True)) - op.create_table( - 'securitygroupportbindings', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('security_group_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['security_group_id'], ['securitygroups.id'],), - sa.PrimaryKeyConstraint('port_id', 'security_group_id'), - ) - - op.create_table( - 'portbindingports', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('host', sa.String(length=255), nullable=False), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('port_id'), - ) - - op.rename_table( - 'routes', - 'subnetroutes', - ) - - op.create_table( - 'routerl3agentbindings', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('router_id', sa.String(length=36), nullable=True), - sa.Column('l3_agent_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['l3_agent_id'], ['agents.id'], - ondelete='CASCADE'), - - sa.ForeignKeyConstraint(['router_id'], ['routers.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id'), - ) - - op.create_table( - 'routerroutes', - sa.Column('destination', sa.String(length=64), nullable=False), - sa.Column('nexthop', sa.String(length=64), nullable=False), - sa.Column('router_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['router_id'], ['routers.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('destination', 'nexthop', 'router_id'), - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.rename_table( - 'subnetroutes', - 'routes', - ) - - op.drop_table('routerroutes') - op.drop_table('routerl3agentbindings') - op.drop_table('portbindingports') - op.drop_table('securitygroupportbindings') - op.drop_column('routers', 'enable_snat') - op.drop_table('port_profile') - op.drop_table('securitygrouprules') - op.drop_table('networkdhcpagentbindings') - op.drop_table('mlnx_network_bindings') - op.drop_table('quotas') - op.drop_table('segmentation_id_allocation') - op.drop_table('securitygroups') diff --git a/neutron/db/migration/alembic_migrations/versions/40dffbf4b549_nvp_dist_router.py b/neutron/db/migration/alembic_migrations/versions/40dffbf4b549_nvp_dist_router.py deleted file mode 100644 index 2bb3e83ef..000000000 --- a/neutron/db/migration/alembic_migrations/versions/40dffbf4b549_nvp_dist_router.py +++ /dev/null @@ -1,63 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""nvp_dist_router - -Revision ID: 40dffbf4b549 -Revises: 63afba73813 -Create Date: 2013-08-21 18:00:26.214923 - -""" - -# revision identifiers, used by Alembic. -revision = '40dffbf4b549' -down_revision = '63afba73813' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'nsxrouterextattributess', - sa.Column('router_id', sa.String(length=36), nullable=False), - sa.Column('distributed', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint( - ['router_id'], ['routers.id'], ondelete='CASCADE'), - sa.PrimaryKeyConstraint('router_id') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('nsxrouterextattributess') diff --git a/neutron/db/migration/alembic_migrations/versions/45680af419f9_nvp_qos.py b/neutron/db/migration/alembic_migrations/versions/45680af419f9_nvp_qos.py deleted file mode 100644 index bf59288ab..000000000 --- a/neutron/db/migration/alembic_migrations/versions/45680af419f9_nvp_qos.py +++ /dev/null @@ -1,94 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""nvp_qos - -Revision ID: 45680af419f9 -Revises: 54c2c487e913 -Create Date: 2013-02-17 13:27:57.999631 - -""" - -# revision identifiers, used by Alembic. -revision = '45680af419f9' -down_revision = '54c2c487e913' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.create_table( - 'qosqueues', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('default', sa.Boolean(), nullable=True), - sa.Column('min', sa.Integer(), nullable=False), - sa.Column('max', sa.Integer(), nullable=True), - sa.Column('qos_marking', sa.Enum('untrusted', 'trusted', - name='qosqueues_qos_marking'), - nullable=True), - sa.Column('dscp', sa.Integer(), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'networkqueuemappings', - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('queue_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['queue_id'], ['qosqueues.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('network_id') - ) - op.create_table( - 'portqueuemappings', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('queue_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ondelete='CASCADE'), - sa.ForeignKeyConstraint(['queue_id'], ['qosqueues.id'], ), - sa.PrimaryKeyConstraint('port_id', 'queue_id') - ) - ### end Alembic commands ### - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('portqueuemappings') - op.drop_table('networkqueuemappings') - op.drop_table('qosqueues') - ### end Alembic commands ### diff --git a/neutron/db/migration/alembic_migrations/versions/4692d074d587_agent_scheduler.py b/neutron/db/migration/alembic_migrations/versions/4692d074d587_agent_scheduler.py deleted file mode 100644 index 9338b0890..000000000 --- a/neutron/db/migration/alembic_migrations/versions/4692d074d587_agent_scheduler.py +++ /dev/null @@ -1,89 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""agent scheduler - -Revision ID: 4692d074d587 -Revises: 3b54bf9e29f7 -Create Date: 2013-02-21 23:01:50.370306 - -""" - -# revision identifiers, used by Alembic. -revision = '4692d074d587' -down_revision = '3b54bf9e29f7' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.brocade.NeutronPlugin.BrocadePluginV2', - 'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2', - 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.nec.nec_plugin.NECPluginV2', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin', - 'neutron.plugins.oneconvergence.plugin.OneConvergencePluginV2', - 'neutron.plugins.ml2.plugin.Ml2Plugin', - 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.create_table( - 'networkdhcpagentbindings', - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('dhcp_agent_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['dhcp_agent_id'], ['agents.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('network_id', 'dhcp_agent_id') - ) - op.create_table( - 'routerl3agentbindings', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('router_id', sa.String(length=36), nullable=True), - sa.Column('l3_agent_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['l3_agent_id'], ['agents.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['router_id'], ['routers.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id') - ) - ### end Alembic commands ### - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('routerl3agentbindings') - op.drop_table('networkdhcpagentbindings') - ### end Alembic commands ### diff --git a/neutron/db/migration/alembic_migrations/versions/46a0efbd8f0_cisco_n1kv_multisegm.py b/neutron/db/migration/alembic_migrations/versions/46a0efbd8f0_cisco_n1kv_multisegm.py deleted file mode 100644 index 1c55ce7f2..000000000 --- a/neutron/db/migration/alembic_migrations/versions/46a0efbd8f0_cisco_n1kv_multisegm.py +++ /dev/null @@ -1,80 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""cisco_n1kv_multisegment_trunk - -Revision ID: 46a0efbd8f0 -Revises: 53bbd27ec841 -Create Date: 2013-08-20 20:44:08.711110 - -""" - -revision = '46a0efbd8f0' -down_revision = '53bbd27ec841' - -migration_for_plugins = [ - 'neutron.plugins.cisco.network_plugin.PluginV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - -new_type = sa.Enum('vlan', 'vxlan', 'trunk', 'multi-segment', name='vlan_type') -old_type = sa.Enum('vlan', 'vxlan', name='vlan_type') - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'cisco_n1kv_trunk_segments', - sa.Column('trunk_segment_id', sa.String(length=36), nullable=False), - sa.Column('segment_id', sa.String(length=36), nullable=False), - sa.Column('dot1qtag', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['trunk_segment_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('trunk_segment_id', 'segment_id', 'dot1qtag') - ) - op.create_table( - 'cisco_n1kv_multi_segments', - sa.Column('multi_segment_id', sa.String(length=36), nullable=False), - sa.Column('segment1_id', sa.String(length=36), nullable=False), - sa.Column('segment2_id', sa.String(length=36), nullable=False), - sa.Column('encap_profile_name', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['multi_segment_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('multi_segment_id', 'segment1_id', - 'segment2_id') - ) - migration.alter_enum('cisco_network_profiles', 'segment_type', new_type, - nullable=False) - op.add_column('cisco_network_profiles', - sa.Column('sub_type', sa.String(length=255), nullable=True)) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('cisco_n1kv_trunk_segments') - op.drop_table('cisco_n1kv_multi_segments') - migration.alter_enum('cisco_network_profiles', 'segment_type', old_type, - nullable=False) - op.drop_column('cisco_network_profiles', 'sub_type') diff --git a/neutron/db/migration/alembic_migrations/versions/477a4488d3f4_ml2_vxlan_type_driver.py b/neutron/db/migration/alembic_migrations/versions/477a4488d3f4_ml2_vxlan_type_driver.py deleted file mode 100644 index eeb28539d..000000000 --- a/neutron/db/migration/alembic_migrations/versions/477a4488d3f4_ml2_vxlan_type_driver.py +++ /dev/null @@ -1,69 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""DB Migration for ML2 VXLAN Type Driver - -Revision ID: 477a4488d3f4 -Revises: 20ae61555e95 -Create Date: 2013-07-09 14:14:33.158502 - -""" - -# revision identifiers, used by Alembic. -revision = '477a4488d3f4' -down_revision = '20ae61555e95' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'ml2_vxlan_allocations', - sa.Column('vxlan_vni', sa.Integer, nullable=False, - autoincrement=False), - sa.Column('allocated', sa.Boolean, nullable=False), - sa.PrimaryKeyConstraint('vxlan_vni') - ) - - op.create_table( - 'ml2_vxlan_endpoints', - sa.Column('ip_address', sa.String(length=64)), - sa.Column('udp_port', sa.Integer(), nullable=False, - autoincrement=False), - sa.PrimaryKeyConstraint('ip_address', 'udp_port') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('ml2_vxlan_allocations') - op.drop_table('ml2_vxlan_endpoints') diff --git a/neutron/db/migration/alembic_migrations/versions/48b6f43f7471_service_type.py b/neutron/db/migration/alembic_migrations/versions/48b6f43f7471_service_type.py deleted file mode 100644 index 83f3e726b..000000000 --- a/neutron/db/migration/alembic_migrations/versions/48b6f43f7471_service_type.py +++ /dev/null @@ -1,76 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""DB support for service types - -Revision ID: 48b6f43f7471 -Revises: 5a875d0e5c -Create Date: 2013-01-07 13:47:29.093160 - -""" - -# revision identifiers, used by Alembic. -revision = '48b6f43f7471' -down_revision = '5a875d0e5c' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - '*' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - u'servicetypes', - sa.Column(u'tenant_id', sa.String(255), nullable=True), - sa.Column(u'id', sa.String(36), nullable=False), - sa.Column(u'name', sa.String(255), nullable=True), - sa.Column(u'description', sa.String(255), nullable=True), - sa.Column(u'default', sa.Boolean(), - autoincrement=False, nullable=False), - sa.Column(u'num_instances', sa.Integer(), - autoincrement=False, nullable=True), - sa.PrimaryKeyConstraint(u'id')) - op.create_table( - u'servicedefinitions', - sa.Column(u'id', sa.String(36), nullable=False), - sa.Column(u'service_class', sa.String(length=255), - nullable=False), - sa.Column(u'plugin', sa.String(255), nullable=True), - sa.Column(u'driver', sa.String(255), nullable=True), - sa.Column(u'service_type_id', sa.String(36), - nullable=False), - sa.ForeignKeyConstraint(['service_type_id'], [u'servicetypes.id'], - name=u'servicedefinitions_ibfk_1'), - sa.PrimaryKeyConstraint(u'id', u'service_class', u'service_type_id')) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table(u'servicedefinitions') - op.drop_table(u'servicetypes') diff --git a/neutron/db/migration/alembic_migrations/versions/492a106273f8_brocade_ml2_mech_dri.py b/neutron/db/migration/alembic_migrations/versions/492a106273f8_brocade_ml2_mech_dri.py deleted file mode 100644 index f8bf7995b..000000000 --- a/neutron/db/migration/alembic_migrations/versions/492a106273f8_brocade_ml2_mech_dri.py +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""Brocade ML2 Mech. Driver - -Revision ID: 492a106273f8 -Revises: fcac4c42e2cc -Create Date: 2014-03-03 15:35:46.974523 - -""" - -# revision identifiers, used by Alembic. -revision = '492a106273f8' -down_revision = 'fcac4c42e2cc' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'ml2_brocadenetworks', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('vlan', sa.String(length=10), nullable=True), - sa.Column('segment_id', sa.String(length=36), nullable=True), - sa.Column('network_type', sa.String(length=10), nullable=True), - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.PrimaryKeyConstraint('id')) - - op.create_table( - 'ml2_brocadeports', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('admin_state_up', sa.Boolean()), - sa.Column('physical_interface', sa.String(length=36), nullable=True), - sa.Column('vlan_id', sa.String(length=36), nullable=True), - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.PrimaryKeyConstraint('id')) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('ml2_brocadenetworks') - op.drop_table('ml2_brocadeports') diff --git a/neutron/db/migration/alembic_migrations/versions/49332180ca96_ryu_plugin_update.py b/neutron/db/migration/alembic_migrations/versions/49332180ca96_ryu_plugin_update.py deleted file mode 100644 index d44449962..000000000 --- a/neutron/db/migration/alembic_migrations/versions/49332180ca96_ryu_plugin_update.py +++ /dev/null @@ -1,59 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""ryu plugin update - -Revision ID: 49332180ca96 -Revises: 1149d7de0cfa -Create Date: 2013-01-30 07:52:58.472885 - -""" - -# revision identifiers, used by Alembic. -revision = '49332180ca96' -down_revision = '1149d7de0cfa' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ryu.ryu_neutron_plugin.RyuNeutronPluginV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('ofp_server') - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'ofp_server', - sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), - sa.Column('address', sa.String(length=255)), - sa.Column('host_type', sa.String(length=255)), - sa.PrimaryKeyConstraint(u'id') - ) diff --git a/neutron/db/migration/alembic_migrations/versions/49f5e553f61f_ml2_security_groups.py b/neutron/db/migration/alembic_migrations/versions/49f5e553f61f_ml2_security_groups.py deleted file mode 100644 index b7dd042d2..000000000 --- a/neutron/db/migration/alembic_migrations/versions/49f5e553f61f_ml2_security_groups.py +++ /dev/null @@ -1,95 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""security_groups - -Revision ID: 49f5e553f61f -Revises: 27ef74513d33 -Create Date: 2013-12-21 19:58:17.071412 - -""" - -# revision identifiers, used by Alembic. -revision = '49f5e553f61f' -down_revision = '27ef74513d33' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.create_table( - 'securitygroups', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'securitygrouprules', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('security_group_id', sa.String(length=36), nullable=False), - sa.Column('remote_group_id', sa.String(length=36), nullable=True), - sa.Column('direction', - sa.Enum('ingress', 'egress', - name='securitygrouprules_direction'), - nullable=True), - sa.Column('ethertype', sa.String(length=40), nullable=True), - sa.Column('protocol', sa.String(length=40), nullable=True), - sa.Column('port_range_min', sa.Integer(), nullable=True), - sa.Column('port_range_max', sa.Integer(), nullable=True), - sa.Column('remote_ip_prefix', sa.String(length=255), nullable=True), - sa.ForeignKeyConstraint(['security_group_id'], ['securitygroups.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['remote_group_id'], ['securitygroups.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'securitygroupportbindings', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('security_group_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ondelete='CASCADE'), - sa.ForeignKeyConstraint(['security_group_id'], ['securitygroups.id']), - sa.PrimaryKeyConstraint('port_id', 'security_group_id') - ) - ### end Alembic commands ### - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('securitygroupportbindings') - op.drop_table('securitygrouprules') - op.drop_table('securitygroups') - ### end Alembic commands ### diff --git a/neutron/db/migration/alembic_migrations/versions/4a666eb208c2_service_router.py b/neutron/db/migration/alembic_migrations/versions/4a666eb208c2_service_router.py deleted file mode 100644 index ad3356b45..000000000 --- a/neutron/db/migration/alembic_migrations/versions/4a666eb208c2_service_router.py +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""service router - -Revision ID: 4a666eb208c2 -Revises: 38fc1f6789f8 -Create Date: 2013-09-03 01:55:57.799217 - -""" - -# revision identifiers, used by Alembic. -revision = '4a666eb208c2' -down_revision = '38fc1f6789f8' - -# Change to ['*'] if this migration applies to all plugins -# This migration must apply to both NVP/NSX plugins as it alters a table -# used by both of them - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'vcns_router_bindings', - sa.Column('status', sa.String(length=16), nullable=False), - sa.Column('status_description', sa.String(length=255), nullable=True), - sa.Column('router_id', sa.String(length=36), nullable=False), - sa.Column('edge_id', sa.String(length=16), nullable=True), - sa.Column('lswitch_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('router_id'), - mysql_engine='InnoDB' - ) - op.add_column( - u'nsxrouterextattributess', - sa.Column('service_router', sa.Boolean(), nullable=False)) - op.execute("UPDATE nsxrouterextattributess set service_router=False") - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_column(u'nsxrouterextattributess', 'service_router') - op.drop_table('vcns_router_bindings') diff --git a/neutron/db/migration/alembic_migrations/versions/4ca36cfc898c_nsx_router_mappings.py b/neutron/db/migration/alembic_migrations/versions/4ca36cfc898c_nsx_router_mappings.py deleted file mode 100644 index c9784a890..000000000 --- a/neutron/db/migration/alembic_migrations/versions/4ca36cfc898c_nsx_router_mappings.py +++ /dev/null @@ -1,64 +0,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. -# - -"""nsx_router_mappings - -Revision ID: 4ca36cfc898c -Revises: 3d3cb89d84ee -Create Date: 2014-01-08 10:41:43.373031 - -""" - -# revision identifiers, used by Alembic. -revision = '4ca36cfc898c' -down_revision = '3d3cb89d84ee' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - # Create table for router/lrouter mappings - op.create_table( - 'neutron_nsx_router_mappings', - sa.Column('neutron_id', sa.String(length=36), nullable=False), - sa.Column('nsx_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['neutron_id'], ['routers.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('neutron_id'), - ) - # Execute statement to a record in nsx_router_mappings for - # each record in routers - op.execute("INSERT INTO neutron_nsx_router_mappings SELECT id,id " - "from routers") - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('neutron_nsx_router_mappings') diff --git a/neutron/db/migration/alembic_migrations/versions/4eca4a84f08a_remove_ml2_cisco_cred_db.py b/neutron/db/migration/alembic_migrations/versions/4eca4a84f08a_remove_ml2_cisco_cred_db.py deleted file mode 100644 index 10bc6fee8..000000000 --- a/neutron/db/migration/alembic_migrations/versions/4eca4a84f08a_remove_ml2_cisco_cred_db.py +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""Remove ML2 Cisco Credentials DB - -Revision ID: 4eca4a84f08a -Revises: 33c3db036fe4 -Create Date: 2014-04-10 19:32:46.697189 - -""" - -# revision identifiers, used by Alembic. -revision = '4eca4a84f08a' -down_revision = '33c3db036fe4' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('cisco_ml2_credentials') - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'cisco_ml2_credentials', - sa.Column('credential_id', sa.String(length=255), nullable=True), - sa.Column('tenant_id', sa.String(length=255), nullable=False), - sa.Column('credential_name', sa.String(length=255), nullable=False), - sa.Column('user_name', sa.String(length=255), nullable=True), - sa.Column('password', sa.String(length=255), nullable=True), - sa.PrimaryKeyConstraint('tenant_id', 'credential_name') - ) diff --git a/neutron/db/migration/alembic_migrations/versions/50d5ba354c23_ml2_binding_vif_details.py b/neutron/db/migration/alembic_migrations/versions/50d5ba354c23_ml2_binding_vif_details.py deleted file mode 100644 index 4182eea1a..000000000 --- a/neutron/db/migration/alembic_migrations/versions/50d5ba354c23_ml2_binding_vif_details.py +++ /dev/null @@ -1,99 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""ml2 binding:vif_details - -Revision ID: 50d5ba354c23 -Revises: 27cc183af192 -Create Date: 2014-02-11 23:21:59.577972 - -""" - -# revision identifiers, used by Alembic. -revision = '50d5ba354c23' -down_revision = '27cc183af192' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.add_column('ml2_port_bindings', - sa.Column('vif_details', sa.String(length=4095), - nullable=False, server_default='')) - if op.get_bind().engine.name == 'ibm_db_sa': - op.execute( - "UPDATE ml2_port_bindings SET" - " vif_details = '{\"port_filter\": true}'" - " WHERE cap_port_filter = 1") - op.execute( - "UPDATE ml2_port_bindings SET" - " vif_details = '{\"port_filter\": false}'" - " WHERE cap_port_filter = 0") - else: - op.execute( - "UPDATE ml2_port_bindings SET" - " vif_details = '{\"port_filter\": true}'" - " WHERE cap_port_filter = true") - op.execute( - "UPDATE ml2_port_bindings SET" - " vif_details = '{\"port_filter\": false}'" - " WHERE cap_port_filter = false") - op.drop_column('ml2_port_bindings', 'cap_port_filter') - if op.get_bind().engine.name == 'ibm_db_sa': - op.execute("CALL SYSPROC.ADMIN_CMD('REORG TABLE ml2_port_bindings')") - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - if op.get_bind().engine.name == 'ibm_db_sa': - # Note(xuhanp): DB2 doesn't allow nullable=False Column with - # "DEFAULT" clause not specified. So server_default is used. - # Using sa.text will result "DEFAULT 0" for cap_port_filter. - op.add_column('ml2_port_bindings', - sa.Column('cap_port_filter', sa.Boolean(), - nullable=False, - server_default=sa.text("0"))) - op.execute( - "UPDATE ml2_port_bindings SET" - " cap_port_filter = 1" - " WHERE vif_details LIKE '%\"port_filter\": true%'") - else: - op.add_column('ml2_port_bindings', - sa.Column('cap_port_filter', sa.Boolean(), - nullable=False, - server_default=sa.text("false"))) - op.execute( - "UPDATE ml2_port_bindings SET" - " cap_port_filter = true" - " WHERE vif_details LIKE '%\"port_filter\": true%'") - op.drop_column('ml2_port_bindings', 'vif_details') - if op.get_bind().engine.name == 'ibm_db_sa': - op.execute("CALL SYSPROC.ADMIN_CMD('REORG TABLE ml2_port_bindings')") diff --git a/neutron/db/migration/alembic_migrations/versions/50e86cb2637a_nsx_mappings.py b/neutron/db/migration/alembic_migrations/versions/50e86cb2637a_nsx_mappings.py deleted file mode 100644 index e571f378a..000000000 --- a/neutron/db/migration/alembic_migrations/versions/50e86cb2637a_nsx_mappings.py +++ /dev/null @@ -1,82 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""nsx_mappings - -Revision ID: 50e86cb2637a -Revises: havana -Create Date: 2013-10-26 14:37:30.012149 - -""" - -# revision identifiers, used by Alembic. -revision = '50e86cb2637a' -down_revision = '1fcfc149aca4' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table('neutron_nsx_port_mappings', - sa.Column('neutron_id', sa.String(length=36), - nullable=False), - sa.Column('nsx_port_id', sa.String(length=36), - nullable=False), - sa.Column('nsx_switch_id', sa.String(length=36), - nullable=True), - sa.ForeignKeyConstraint(['neutron_id'], ['ports.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('neutron_id')) - - op.execute("INSERT INTO neutron_nsx_port_mappings SELECT quantum_id as " - "neutron_id, nvp_id as nsx_port_id, null as nsx_switch_id from" - " quantum_nvp_port_mapping") - op.drop_table('quantum_nvp_port_mapping') - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - # Restore table to pre-icehouse version - op.create_table('quantum_nvp_port_mapping', - sa.Column('quantum_id', sa.String(length=36), - nullable=False), - sa.Column('nvp_id', sa.String(length=36), - nullable=False), - sa.ForeignKeyConstraint(['quantum_id'], ['ports.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('quantum_id')) - op.execute("INSERT INTO quantum_nvp_port_mapping SELECT neutron_id as " - "quantum_id, nsx_port_id as nvp_id from" - " neutron_nsx_port_mappings") - op.drop_table('neutron_nsx_port_mappings') diff --git a/neutron/db/migration/alembic_migrations/versions/511471cc46b_agent_ext_model_supp.py b/neutron/db/migration/alembic_migrations/versions/511471cc46b_agent_ext_model_supp.py deleted file mode 100644 index ee14c1b92..000000000 --- a/neutron/db/migration/alembic_migrations/versions/511471cc46b_agent_ext_model_supp.py +++ /dev/null @@ -1,84 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Add agent management extension model support - -Revision ID: 511471cc46b -Revises: 363468ac592c -Create Date: 2013-02-18 05:09:32.523460 - -""" - -# revision identifiers, used by Alembic. -revision = '511471cc46b' -down_revision = '363468ac592c' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.brocade.NeutronPlugin.BrocadePluginV2', - 'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2', - 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', - 'neutron.plugins.nec.nec_plugin.NECPluginV2', - 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', - 'neutron.plugins.vmware.plugin.NsxPlugin', - 'neutron.plugins.vmware.plugin.NsxServicePlugin', - 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin', - 'neutron.plugins.ibm.sdnve_neutron_plugin.SdnvePluginV2', - 'neutron.plugins.oneconvergence.plugin.OneConvergencePluginV2', - 'neutron.plugins.mlnx.mlnx_plugin.MellanoxEswitchPlugin', - 'neutron.plugins.ml2.plugin.Ml2Plugin', -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.create_table( - 'agents', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('agent_type', sa.String(length=255), nullable=False), - sa.Column('binary', sa.String(length=255), nullable=False), - sa.Column('topic', sa.String(length=255), nullable=False), - sa.Column('host', sa.String(length=255), nullable=False), - sa.Column('admin_state_up', sa.Boolean(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('started_at', sa.DateTime(), nullable=False), - sa.Column('heartbeat_timestamp', sa.DateTime(), nullable=False), - sa.Column('description', sa.String(length=255), nullable=True), - sa.Column('configurations', sa.String(length=4095), nullable=False), - sa.PrimaryKeyConstraint('id') - ) - ### end Alembic commands ### - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('agents') - ### end Alembic commands ### diff --git a/neutron/db/migration/alembic_migrations/versions/51b4de912379_cisco_nexus_ml2_mech.py b/neutron/db/migration/alembic_migrations/versions/51b4de912379_cisco_nexus_ml2_mech.py deleted file mode 100755 index f6038fd3e..000000000 --- a/neutron/db/migration/alembic_migrations/versions/51b4de912379_cisco_nexus_ml2_mech.py +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Cisco Nexus ML2 mechanism driver - -Revision ID: 51b4de912379 -Revises: 66a59a7f516 -Create Date: 2013-08-20 15:31:40.553634 - -""" - -# revision identifiers, used by Alembic. -revision = '51b4de912379' -down_revision = '66a59a7f516' - -migration_for_plugins = [ - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'cisco_ml2_nexusport_bindings', - sa.Column('binding_id', sa.Integer(), nullable=False), - sa.Column('port_id', sa.String(length=255), nullable=True), - sa.Column('vlan_id', sa.Integer(), autoincrement=False, - nullable=False), - sa.Column('switch_ip', sa.String(length=255), nullable=True), - sa.Column('instance_id', sa.String(length=255), nullable=True), - sa.PrimaryKeyConstraint('binding_id'), - ) - op.create_table( - 'cisco_ml2_credentials', - sa.Column('credential_id', sa.String(length=255), nullable=True), - sa.Column('tenant_id', sa.String(length=255), nullable=False), - sa.Column('credential_name', sa.String(length=255), nullable=False), - sa.Column('user_name', sa.String(length=255), nullable=True), - sa.Column('password', sa.String(length=255), nullable=True), - sa.PrimaryKeyConstraint('tenant_id', 'credential_name'), - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('cisco_ml2_credentials') - op.drop_table('cisco_ml2_nexusport_bindings') diff --git a/neutron/db/migration/alembic_migrations/versions/52c5e4a18807_lbaas_pool_scheduler.py b/neutron/db/migration/alembic_migrations/versions/52c5e4a18807_lbaas_pool_scheduler.py deleted file mode 100644 index 345955a0f..000000000 --- a/neutron/db/migration/alembic_migrations/versions/52c5e4a18807_lbaas_pool_scheduler.py +++ /dev/null @@ -1,63 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""LBaaS Pool scheduler - -Revision ID: 52c5e4a18807 -Revises: 2032abe8edac -Create Date: 2013-06-14 03:23:47.815865 - -""" - -# revision identifiers, used by Alembic. -revision = '52c5e4a18807' -down_revision = '2032abe8edac' - -migration_for_plugins = [ - 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin', -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - ### commands auto generated by Alembic - please adjust! ### - op.create_table( - 'poolloadbalanceragentbindings', - sa.Column('pool_id', sa.String(length=36), nullable=False), - sa.Column('agent_id', sa.String(length=36), - nullable=False), - sa.ForeignKeyConstraint(['agent_id'], ['agents.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['pool_id'], ['pools.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('pool_id') - ) - ### end Alembic commands ### - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('poolloadbalanceragentbindings') - ### end Alembic commands ### diff --git a/neutron/db/migration/alembic_migrations/versions/52ff27f7567a_support_for_vpnaas.py b/neutron/db/migration/alembic_migrations/versions/52ff27f7567a_support_for_vpnaas.py deleted file mode 100644 index c9f61ff91..000000000 --- a/neutron/db/migration/alembic_migrations/versions/52ff27f7567a_support_for_vpnaas.py +++ /dev/null @@ -1,183 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Support for VPNaaS - -Revision ID: 52ff27f7567a -Revises: 39cf3f799352 -Create Date: 2013-07-14 23:04:13.395955 - -""" - -# revision identifiers, used by Alembic. -revision = '52ff27f7567a' -down_revision = '39cf3f799352' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.vpn.plugin.VPNDriverPlugin', -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'ikepolicies', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.Column( - 'auth_algorithm', - sa.Enum('sha1', name='vpn_auth_algorithms'), nullable=False), - sa.Column( - 'encryption_algorithm', - sa.Enum('3des', 'aes-128', 'aes-256', 'aes-192', - name='vpn_encrypt_algorithms'), nullable=False), - sa.Column( - 'phase1_negotiation_mode', - sa.Enum('main', name='ike_phase1_mode'), nullable=False), - sa.Column( - 'lifetime_units', - sa.Enum('seconds', 'kilobytes', name='vpn_lifetime_units'), - nullable=False), - sa.Column('lifetime_value', sa.Integer(), nullable=False), - sa.Column( - 'ike_version', - sa.Enum('v1', 'v2', name='ike_versions'), nullable=False), - sa.Column( - 'pfs', - sa.Enum('group2', 'group5', 'group14', name='vpn_pfs'), - nullable=False), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'ipsecpolicies', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.Column( - 'transform_protocol', - sa.Enum('esp', 'ah', 'ah-esp', name='ipsec_transform_protocols'), - nullable=False), - sa.Column( - 'auth_algorithm', - sa.Enum('sha1', name='vpn_auth_algorithms'), nullable=False), - sa.Column( - 'encryption_algorithm', - sa.Enum( - '3des', 'aes-128', - 'aes-256', 'aes-192', name='vpn_encrypt_algorithms'), - nullable=False), - sa.Column( - 'encapsulation_mode', - sa.Enum('tunnel', 'transport', name='ipsec_encapsulations'), - nullable=False), - sa.Column( - 'lifetime_units', - sa.Enum( - 'seconds', 'kilobytes', - name='vpn_lifetime_units'), nullable=False), - sa.Column( - 'lifetime_value', sa.Integer(), nullable=False), - sa.Column( - 'pfs', - sa.Enum( - 'group2', 'group5', 'group14', name='vpn_pfs'), - nullable=False), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'vpnservices', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.Column('status', sa.String(length=16), nullable=False), - sa.Column('admin_state_up', sa.Boolean(), nullable=False), - sa.Column('subnet_id', sa.String(length=36), nullable=False), - sa.Column('router_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['router_id'], ['routers.id'], ), - sa.ForeignKeyConstraint(['subnet_id'], ['subnets.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'ipsec_site_connections', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.Column('peer_address', sa.String(length=64), nullable=False), - sa.Column('peer_id', sa.String(length=255), nullable=False), - sa.Column('route_mode', sa.String(length=8), nullable=False), - sa.Column('mtu', sa.Integer(), nullable=False), - sa.Column( - 'initiator', - sa.Enum( - 'bi-directional', 'response-only', name='vpn_initiators'), - nullable=False), - sa.Column('auth_mode', sa.String(length=16), nullable=False), - sa.Column('psk', sa.String(length=255), nullable=False), - sa.Column( - 'dpd_action', - sa.Enum( - 'hold', 'clear', 'restart', - 'disabled', 'restart-by-peer', name='vpn_dpd_actions'), - nullable=False), - sa.Column('dpd_interval', sa.Integer(), nullable=False), - sa.Column('dpd_timeout', sa.Integer(), nullable=False), - sa.Column('status', sa.String(length=16), nullable=False), - sa.Column('admin_state_up', sa.Boolean(), nullable=False), - sa.Column('vpnservice_id', sa.String(length=36), nullable=False), - sa.Column('ipsecpolicy_id', sa.String(length=36), nullable=False), - sa.Column('ikepolicy_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['ikepolicy_id'], ['ikepolicies.id']), - sa.ForeignKeyConstraint(['ipsecpolicy_id'], ['ipsecpolicies.id']), - sa.ForeignKeyConstraint(['vpnservice_id'], ['vpnservices.id']), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'ipsecpeercidrs', - sa.Column('cidr', sa.String(length=32), nullable=False), - sa.Column('ipsec_site_connection_id', - sa.String(length=36), - nullable=False), - sa.ForeignKeyConstraint(['ipsec_site_connection_id'], - ['ipsec_site_connections.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('cidr', 'ipsec_site_connection_id') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('ipsecpeercidrs') - op.drop_table('ipsec_site_connections') - op.drop_table('vpnservices') - op.drop_table('ipsecpolicies') - op.drop_table('ikepolicies') diff --git a/neutron/db/migration/alembic_migrations/versions/538732fa21e1_nec_rename_quantum_id_to_neutron_id.py b/neutron/db/migration/alembic_migrations/versions/538732fa21e1_nec_rename_quantum_id_to_neutron_id.py deleted file mode 100644 index 0dd6ca149..000000000 --- a/neutron/db/migration/alembic_migrations/versions/538732fa21e1_nec_rename_quantum_id_to_neutron_id.py +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""NEC Rename quantum_id to neutron_id - -Revision ID: 538732fa21e1 -Revises: 2447ad0e9585 -Create Date: 2014-03-04 05:43:33.660601 - -""" - -# revision identifiers, used by Alembic. -revision = '538732fa21e1' -down_revision = '2447ad0e9585' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nec.nec_plugin.NECPluginV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - for table in ['ofctenantmappings', 'ofcnetworkmappings', - 'ofcportmappings', 'ofcfiltermappings', - 'ofcroutermappings', - ]: - op.alter_column(table, 'quantum_id', - new_column_name='neutron_id', - existing_type=sa.String(length=36), - existing_nullable=False) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - for table in ['ofctenantmappings', 'ofcnetworkmappings', - 'ofcportmappings', 'ofcfiltermappings', - 'ofcroutermappings', - ]: - op.alter_column(table, 'neutron_id', - new_column_name='quantum_id', - existing_type=sa.String(length=36), - existing_nullable=False) diff --git a/neutron/db/migration/alembic_migrations/versions/53bbd27ec841_extra_dhcp_opts_supp.py b/neutron/db/migration/alembic_migrations/versions/53bbd27ec841_extra_dhcp_opts_supp.py deleted file mode 100644 index ef903425d..000000000 --- a/neutron/db/migration/alembic_migrations/versions/53bbd27ec841_extra_dhcp_opts_supp.py +++ /dev/null @@ -1,66 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Extra dhcp opts support - -Revision ID: 53bbd27ec841 -Revises: 40dffbf4b549 -Create Date: 2013-05-09 15:36:50.485036 - -""" - -# revision identifiers, used by Alembic. -revision = '53bbd27ec841' -down_revision = '40dffbf4b549' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', - 'neutron.plugins.ml2.plugin.Ml2Plugin', - 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'extradhcpopts', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('opt_name', sa.String(length=64), nullable=False), - sa.Column('opt_value', sa.String(length=255), nullable=False), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('port_id', 'opt_name', name='uidx_portid_optname')) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('extradhcpopts') - ### end Alembic commands ### diff --git a/neutron/db/migration/alembic_migrations/versions/54c2c487e913_lbaas.py b/neutron/db/migration/alembic_migrations/versions/54c2c487e913_lbaas.py deleted file mode 100644 index f40daf5e6..000000000 --- a/neutron/db/migration/alembic_migrations/versions/54c2c487e913_lbaas.py +++ /dev/null @@ -1,163 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""'DB support for load balancing service - -Revision ID: 54c2c487e913 -Revises: 38335592a0dc -Create Date: 2013-02-04 16:32:32.048731 - -""" - -# revision identifiers, used by Alembic. -revision = '54c2c487e913' -down_revision = '38335592a0dc' - -# We need migration_for_plugins to be an empty list to avoid creating tables, -# if there's no plugin that implements the LBaaS extension. - -migration_for_plugins = [] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - u'vips', - sa.Column(u'tenant_id', sa.String(255), nullable=True), - sa.Column(u'id', sa.String(36), nullable=False), - sa.Column(u'name', sa.String(255), nullable=True), - sa.Column(u'description', sa.String(255), nullable=True), - sa.Column(u'port_id', sa.String(36), nullable=True), - sa.Column(u'protocol_port', sa.Integer(), nullable=False), - sa.Column(u'protocol', - sa.Enum("HTTP", "HTTPS", "TCP", name="lb_protocols"), - nullable=False), - sa.Column(u'pool_id', sa.String(36), nullable=False), - sa.Column(u'status', sa.String(16), nullable=False), - sa.Column(u'admin_state_up', sa.Boolean(), nullable=False), - sa.Column(u'connection_limit', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ), - sa.UniqueConstraint('pool_id'), - sa.PrimaryKeyConstraint(u'id') - ) - op.create_table( - u'poolmonitorassociations', - sa.Column(u'pool_id', sa.String(36), nullable=False), - sa.Column(u'monitor_id', sa.String(36), nullable=False), - sa.ForeignKeyConstraint(['monitor_id'], [u'healthmonitors.id'], ), - sa.ForeignKeyConstraint(['pool_id'], [u'pools.id'], ), - sa.PrimaryKeyConstraint(u'pool_id', u'monitor_id') - ) - op.create_table( - u'sessionpersistences', - sa.Column(u'vip_id', sa.String(36), nullable=False), - sa.Column(u'type', - sa.Enum("SOURCE_IP", - "HTTP_COOKIE", - "APP_COOKIE", - name="sesssionpersistences_type"), - nullable=False), - sa.Column(u'cookie_name', sa.String(1024), nullable=True), - sa.ForeignKeyConstraint(['vip_id'], [u'vips.id'], ), - sa.PrimaryKeyConstraint(u'vip_id') - ) - op.create_table( - u'pools', - sa.Column(u'tenant_id', sa.String(255), nullable=True), - sa.Column(u'id', sa.String(36), nullable=False), - sa.Column(u'vip_id', sa.String(36), nullable=True), - sa.Column(u'name', sa.String(255), nullable=True), - sa.Column(u'description', sa.String(255), nullable=True), - sa.Column(u'subnet_id', sa.String(36), nullable=False), - sa.Column(u'protocol', - sa.Enum("HTTP", "HTTPS", "TCP", name="lb_protocols"), - nullable=False), - sa.Column(u'lb_method', - sa.Enum("ROUND_ROBIN", - "LEAST_CONNECTIONS", - "SOURCE_IP", - name="pools_lb_method"), - nullable=False), - sa.Column(u'status', sa.String(16), nullable=False), - sa.Column(u'admin_state_up', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['vip_id'], [u'vips.id'], ), - sa.PrimaryKeyConstraint(u'id') - ) - op.create_table( - u'healthmonitors', - sa.Column(u'tenant_id', sa.String(255), nullable=True), - sa.Column(u'id', sa.String(36), nullable=False), - sa.Column(u'type', - sa.Enum("PING", - "TCP", - "HTTP", - "HTTPS", - name="healthmontiors_type"), - nullable=False), - sa.Column(u'delay', sa.Integer(), nullable=False), - sa.Column(u'timeout', sa.Integer(), nullable=False), - sa.Column(u'max_retries', sa.Integer(), nullable=False), - sa.Column(u'http_method', sa.String(16), nullable=True), - sa.Column(u'url_path', sa.String(255), nullable=True), - sa.Column(u'expected_codes', sa.String(64), nullable=True), - sa.Column(u'status', sa.String(16), nullable=False), - sa.Column(u'admin_state_up', sa.Boolean(), nullable=False), - sa.PrimaryKeyConstraint(u'id') - ) - op.create_table( - u'members', - sa.Column(u'tenant_id', sa.String(255), nullable=True), - sa.Column(u'id', sa.String(36), nullable=False), - sa.Column(u'pool_id', sa.String(36), nullable=False), - sa.Column(u'address', sa.String(64), nullable=False), - sa.Column(u'protocol_port', sa.Integer(), nullable=False), - sa.Column(u'weight', sa.Integer(), nullable=False), - sa.Column(u'status', sa.String(16), nullable=False), - sa.Column(u'admin_state_up', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['pool_id'], [u'pools.id'], ), - sa.PrimaryKeyConstraint(u'id') - ) - op.create_table( - u'poolstatisticss', - sa.Column(u'pool_id', sa.String(36), nullable=False), - sa.Column(u'bytes_in', sa.Integer(), nullable=False), - sa.Column(u'bytes_out', sa.Integer(), nullable=False), - sa.Column(u'active_connections', sa.Integer(), nullable=False), - sa.Column(u'total_connections', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['pool_id'], [u'pools.id'], ), - sa.PrimaryKeyConstraint(u'pool_id') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table(u'poolstatisticss') - op.drop_table(u'members') - op.drop_table(u'healthmonitors') - op.drop_table(u'pools') - op.drop_table(u'sessionpersistences') - op.drop_table(u'poolmonitorassociations') - op.drop_table(u'vips') diff --git a/neutron/db/migration/alembic_migrations/versions/54f7549a0e5f_set_not_null_peer_address.py b/neutron/db/migration/alembic_migrations/versions/54f7549a0e5f_set_not_null_peer_address.py deleted file mode 100644 index 626c26fb7..000000000 --- a/neutron/db/migration/alembic_migrations/versions/54f7549a0e5f_set_not_null_peer_address.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""set_not_null_peer_address - -Revision ID: 54f7549a0e5f -Revises: 33dd0a9fa487 -Create Date: 2014-03-17 11:00:17.539028 - -""" - -# revision identifiers, used by Alembic. -revision = '54f7549a0e5f' -down_revision = 'icehouse' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.vpn.plugin.VPNDriverPlugin' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('ipsec_site_connections', 'peer_address', - existing_type=sa.String(255), nullable=False) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('ipsec_site_connections', 'peer_address', nullable=True, - existing_type=sa.String(255)) diff --git a/neutron/db/migration/alembic_migrations/versions/557edfc53098_new_service_types.py b/neutron/db/migration/alembic_migrations/versions/557edfc53098_new_service_types.py deleted file mode 100644 index 81fe08b32..000000000 --- a/neutron/db/migration/alembic_migrations/versions/557edfc53098_new_service_types.py +++ /dev/null @@ -1,81 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""New service types framework (service providers) - -Revision ID: 557edfc53098 -Revises: 52c5e4a18807 -Create Date: 2013-06-29 21:10:41.283358 - -""" - -# revision identifiers, used by Alembic. -revision = '557edfc53098' -down_revision = '52c5e4a18807' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin', -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - op.create_table( - 'providerresourceassociations', - sa.Column('provider_name', sa.String(length=255), nullable=False), - sa.Column('resource_id', sa.String(length=36), - nullable=False, unique=True), - ) - - for table in ('servicedefinitions', 'servicetypes'): - op.execute("DROP TABLE IF EXISTS %s" % table) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - op.create_table( - 'servicetypes', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('tenant_id', sa.String(length=255)), - sa.Column('name', sa.String(255)), - sa.Column('description', sa.String(255)), - sa.Column('default', sa.Boolean(), nullable=False, default=False), - sa.Column('num_instances', sa.Integer, default=0), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'servicedefinitions', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('service_class', sa.String(255)), - sa.Column('plugin', sa.String(255)), - sa.Column('driver', sa.String(255)), - sa.Column('service_type_id', sa.String(36), - sa.ForeignKey('servicetypes.id', - ondelete='CASCADE')), - sa.PrimaryKeyConstraint('id', 'service_class') - ) - op.drop_table('providerresourceassociations') diff --git a/neutron/db/migration/alembic_migrations/versions/569e98a8132b_metering.py b/neutron/db/migration/alembic_migrations/versions/569e98a8132b_metering.py deleted file mode 100644 index 7ec917368..000000000 --- a/neutron/db/migration/alembic_migrations/versions/569e98a8132b_metering.py +++ /dev/null @@ -1,77 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""metering - -Revision ID: 569e98a8132b -Revises: 13de305df56e -Create Date: 2013-07-17 15:38:36.254595 - -""" - -# revision identifiers, used by Alembic. -revision = '569e98a8132b' -down_revision = 'f9263d6df56' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = ['neutron.services.metering.metering_plugin.' - 'MeteringPlugin'] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('meteringlabelrules') - op.drop_table('meteringlabels') - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table('meteringlabels', - sa.Column('tenant_id', sa.String(length=255), - nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), - nullable=True), - sa.Column('description', sa.String(length=255), - nullable=True), - sa.PrimaryKeyConstraint('id')) - op.create_table('meteringlabelrules', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('direction', - sa.Enum('ingress', 'egress', - name='meteringlabels_direction'), - nullable=True), - sa.Column('remote_ip_prefix', sa.String(length=64), - nullable=True), - sa.Column('metering_label_id', sa.String(length=36), - nullable=False), - sa.Column('excluded', sa.Boolean(), - autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['metering_label_id'], - ['meteringlabels.id'], - name='meteringlabelrules_ibfk_1'), - sa.PrimaryKeyConstraint('id')) diff --git a/neutron/db/migration/alembic_migrations/versions/5918cbddab04_add_tables_for_route.py b/neutron/db/migration/alembic_migrations/versions/5918cbddab04_add_tables_for_route.py deleted file mode 100644 index 946f9c08e..000000000 --- a/neutron/db/migration/alembic_migrations/versions/5918cbddab04_add_tables_for_route.py +++ /dev/null @@ -1,71 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""add tables for router rules support - -Revision ID: 5918cbddab04 -Revises: 3cbf70257c28 -Create Date: 2013-06-16 02:20:07.024752 - -""" - -# revision identifiers, used by Alembic. -revision = '5918cbddab04' -down_revision = '3cbf70257c28' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table('routerrules', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('source', sa.String(length=64), nullable=False), - sa.Column('destination', sa.String(length=64), - nullable=False), - sa.Column('action', sa.String(length=10), nullable=False), - sa.Column('router_id', sa.String(length=36), - nullable=True), - sa.ForeignKeyConstraint(['router_id'], ['routers.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id')) - op.create_table('nexthops', - sa.Column('rule_id', sa.Integer(), nullable=False), - sa.Column('nexthop', sa.String(length=64), nullable=False), - sa.ForeignKeyConstraint(['rule_id'], ['routerrules.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('rule_id', 'nexthop')) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('nexthops') - op.drop_table('routerrules') diff --git a/neutron/db/migration/alembic_migrations/versions/5a875d0e5c_ryu.py b/neutron/db/migration/alembic_migrations/versions/5a875d0e5c_ryu.py deleted file mode 100644 index 8eee238a1..000000000 --- a/neutron/db/migration/alembic_migrations/versions/5a875d0e5c_ryu.py +++ /dev/null @@ -1,74 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2012 New Dream Network, LLC (DreamHost) -# -# 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: Mark McClain, DreamHost - -"""ryu - -This retroactively provides migration support for -https://review.openstack.org/#/c/11204/ - -Revision ID: 5a875d0e5c -Revises: 2c4af419145b -Create Date: 2012-12-18 12:32:04.482477 - -""" - - -# revision identifiers, used by Alembic. -revision = '5a875d0e5c' -down_revision = '2c4af419145b' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ryu.ryu_neutron_plugin.RyuNeutronPluginV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'tunnelkeys', - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('tunnel_key', sa.Integer(), autoincrement=False, - nullable=False), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('tunnel_key') - ) - - op.create_table( - 'tunnelkeylasts', - sa.Column('last_key', sa.Integer(), autoincrement=False, - nullable=False), - sa.PrimaryKeyConstraint('last_key') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('tunnelkeylasts') - op.drop_table('tunnelkeys') diff --git a/neutron/db/migration/alembic_migrations/versions/5ac1c354a051_n1kv_segment_alloc.py b/neutron/db/migration/alembic_migrations/versions/5ac1c354a051_n1kv_segment_alloc.py deleted file mode 100644 index 516faaf78..000000000 --- a/neutron/db/migration/alembic_migrations/versions/5ac1c354a051_n1kv_segment_alloc.py +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""n1kv segment allocs for cisco n1kv plugin - -Revision ID: 5ac1c354a051 -Revises: 538732fa21e1 -Create Date: 2014-03-05 17:36:52.952608 - -""" - -# revision identifiers, used by Alembic. -revision = '5ac1c354a051' -down_revision = '538732fa21e1' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.cisco.network_plugin.PluginV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.add_column( - 'cisco_n1kv_vlan_allocations', - sa.Column('network_profile_id', - sa.String(length=36), - nullable=False) - ) - op.create_foreign_key( - 'cisco_n1kv_vlan_allocations_ibfk_1', - source='cisco_n1kv_vlan_allocations', - referent='cisco_network_profiles', - local_cols=['network_profile_id'], remote_cols=['id'], - ondelete='CASCADE' - ) - op.add_column( - 'cisco_n1kv_vxlan_allocations', - sa.Column('network_profile_id', - sa.String(length=36), - nullable=False) - ) - op.create_foreign_key( - 'cisco_n1kv_vxlan_allocations_ibfk_1', - source='cisco_n1kv_vxlan_allocations', - referent='cisco_network_profiles', - local_cols=['network_profile_id'], remote_cols=['id'], - ondelete='CASCADE' - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_constraint('cisco_n1kv_vxlan_allocations_ibfk_1', - 'cisco_n1kv_vxlan_allocations', - 'foreignkey') - op.drop_column('cisco_n1kv_vxlan_allocations', 'network_profile_id') - op.drop_constraint('cisco_n1kv_vlan_allocations_ibfk_1', - 'cisco_n1kv_vlan_allocations', - 'foreignkey') - op.drop_column('cisco_n1kv_vlan_allocations', 'network_profile_id') diff --git a/neutron/db/migration/alembic_migrations/versions/5ac71e65402c_ml2_initial.py b/neutron/db/migration/alembic_migrations/versions/5ac71e65402c_ml2_initial.py deleted file mode 100644 index 9227197c7..000000000 --- a/neutron/db/migration/alembic_migrations/versions/5ac71e65402c_ml2_initial.py +++ /dev/null @@ -1,84 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""ml2_initial - -Revision ID: 5ac71e65402c -Revises: 128e042a2b68 -Create Date: 2013-05-27 16:08:40.853821 - -""" - -# revision identifiers, used by Alembic. -revision = '5ac71e65402c' -down_revision = '128e042a2b68' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.create_table( - 'ml2_network_segments', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('network_type', sa.String(length=32), nullable=False), - sa.Column('physical_network', sa.String(length=64), nullable=True), - sa.Column('segmentation_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'ml2_vlan_allocations', - sa.Column('physical_network', sa.String(length=64), nullable=False), - sa.Column('vlan_id', sa.Integer(), autoincrement=False, - nullable=False), - sa.Column('allocated', sa.Boolean(), autoincrement=False, - nullable=False), - sa.PrimaryKeyConstraint('physical_network', 'vlan_id') - ) - op.create_table( - 'ml2_flat_allocations', - sa.Column('physical_network', sa.String(length=64), nullable=False), - sa.PrimaryKeyConstraint('physical_network') - ) - ### end Alembic commands ### - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('ml2_network_segments') - op.drop_table('ml2_flat_allocations') - op.drop_table('ml2_vlan_allocations') - ### end Alembic commands ### diff --git a/neutron/db/migration/alembic_migrations/versions/63afba73813_ovs_tunnelendpoints_id_unique.py b/neutron/db/migration/alembic_migrations/versions/63afba73813_ovs_tunnelendpoints_id_unique.py deleted file mode 100644 index c5f255059..000000000 --- a/neutron/db/migration/alembic_migrations/versions/63afba73813_ovs_tunnelendpoints_id_unique.py +++ /dev/null @@ -1,64 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Add unique constraint for id column of TunnelEndpoint - -Revision ID: 63afba73813 -Revises: 3c6e57a23db4 -Create Date: 2013-04-30 13:53:31.717450 - -""" - -# revision identifiers, used by Alembic. -revision = '63afba73813' -down_revision = '3c6e57a23db4' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', -] - -from alembic import op - -from neutron.db import migration - - -CONSTRAINT_NAME = 'uniq_ovs_tunnel_endpoints0id' -TABLE_NAME = 'ovs_tunnel_endpoints' - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_unique_constraint( - name=CONSTRAINT_NAME, - source=TABLE_NAME, - local_cols=['id'] - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_constraint( - CONSTRAINT_NAME, - TABLE_NAME, - type_='unique' - ) diff --git a/neutron/db/migration/alembic_migrations/versions/66a59a7f516_nec_openflow_router.py b/neutron/db/migration/alembic_migrations/versions/66a59a7f516_nec_openflow_router.py deleted file mode 100644 index ffead1147..000000000 --- a/neutron/db/migration/alembic_migrations/versions/66a59a7f516_nec_openflow_router.py +++ /dev/null @@ -1,68 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""NEC OpenFlow Router - -Revision ID: 66a59a7f516 -Revises: 32a65f71af51 -Create Date: 2013-09-03 22:16:31.446031 - -""" - -# revision identifiers, used by Alembic. -revision = '66a59a7f516' -down_revision = '32a65f71af51' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.nec.nec_plugin.NECPluginV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'ofcroutermappings', - sa.Column('ofc_id', sa.String(length=255), nullable=False), - sa.Column('quantum_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('quantum_id'), - sa.UniqueConstraint('ofc_id'), - ) - op.create_table( - 'routerproviders', - sa.Column('provider', sa.String(length=255), nullable=True), - sa.Column('router_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['router_id'], ['routers.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('router_id'), - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('routerproviders') - op.drop_table('ofcroutermappings') diff --git a/neutron/db/migration/alembic_migrations/versions/6be312499f9_set_not_null_vlan_id_cisco.py b/neutron/db/migration/alembic_migrations/versions/6be312499f9_set_not_null_vlan_id_cisco.py deleted file mode 100644 index e304fdc24..000000000 --- a/neutron/db/migration/alembic_migrations/versions/6be312499f9_set_not_null_vlan_id_cisco.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""set_not_null_vlan_id_cisco - -Revision ID: 6be312499f9 -Revises: d06e871c0d5 -Create Date: 2014-03-27 14:38:12.571173 - -""" - -# revision identifiers, used by Alembic. -revision = '6be312499f9' -down_revision = 'd06e871c0d5' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.cisco.network_plugin.PluginV2' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('cisco_nexusport_bindings', 'vlan_id', nullable=False, - existing_type=sa.Integer) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('cisco_nexusport_bindings', 'vlan_id', nullable=True, - existing_type=sa.Integer) diff --git a/neutron/db/migration/alembic_migrations/versions/81c553f3776c_bsn_consistencyhashes.py b/neutron/db/migration/alembic_migrations/versions/81c553f3776c_bsn_consistencyhashes.py deleted file mode 100644 index 0300c2475..000000000 --- a/neutron/db/migration/alembic_migrations/versions/81c553f3776c_bsn_consistencyhashes.py +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""bsn_consistencyhashes - -Revision ID: 81c553f3776c -Revises: 24c7ea5160d7 -Create Date: 2014-02-26 18:56:00.402855 - -""" - -# revision identifiers, used by Alembic. -revision = '81c553f3776c' -down_revision = '24c7ea5160d7' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2', - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'consistencyhashes', - sa.Column('hash_id', sa.String(255), primary_key=True), - sa.Column('hash', sa.String(255), nullable=False) - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('consistencyhashes') diff --git a/neutron/db/migration/alembic_migrations/versions/86cf4d88bd3_remove_bigswitch_por.py b/neutron/db/migration/alembic_migrations/versions/86cf4d88bd3_remove_bigswitch_por.py deleted file mode 100644 index 7d91893e2..000000000 --- a/neutron/db/migration/alembic_migrations/versions/86cf4d88bd3_remove_bigswitch_por.py +++ /dev/null @@ -1,59 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""remove bigswitch port tracking table - -Revision ID: 86cf4d88bd3 -Revises: 569e98a8132b -Create Date: 2013-08-13 21:59:04.373496 - -""" - -# revision identifiers, used by Alembic. -revision = '86cf4d88bd3' -down_revision = '569e98a8132b' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('portlocations') - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table('portlocations', - sa.Column('port_id', sa.String(length=255), - primary_key=True, nullable=False), - sa.Column('host_id', - sa.String(length=255), nullable=False) - ) diff --git a/neutron/db/migration/alembic_migrations/versions/8f682276ee4_ryu_plugin_quota.py b/neutron/db/migration/alembic_migrations/versions/8f682276ee4_ryu_plugin_quota.py deleted file mode 100644 index 110f206e3..000000000 --- a/neutron/db/migration/alembic_migrations/versions/8f682276ee4_ryu_plugin_quota.py +++ /dev/null @@ -1,61 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""ryu plugin quota - -Revision ID: 8f682276ee4 -Revises: ed93525fd003 -Create Date: 2014-01-07 15:47:17.349425 - -""" - -# revision identifiers, used by Alembic. -revision = '8f682276ee4' -down_revision = 'ed93525fd003' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ryu.ryu_neutron_plugin.RyuNeutronPluginV2' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'quotas', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('resource', sa.String(length=255), nullable=True), - sa.Column('limit', sa.Integer(), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('quotas') diff --git a/neutron/db/migration/alembic_migrations/versions/abc88c33f74f_lb_stats_needs_bigint.py b/neutron/db/migration/alembic_migrations/versions/abc88c33f74f_lb_stats_needs_bigint.py deleted file mode 100644 index 79f39dde3..000000000 --- a/neutron/db/migration/alembic_migrations/versions/abc88c33f74f_lb_stats_needs_bigint.py +++ /dev/null @@ -1,67 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""lb stats - -Revision ID: abc88c33f74f -Revises: 3d2585038b95 -Create Date: 2014-02-24 20:14:59.577972 - -""" - -# revision identifiers, used by Alembic. -revision = 'abc88c33f74f' -down_revision = '3d2585038b95' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('poolstatisticss', 'bytes_in', - type_=sa.BigInteger(), existing_type=sa.Integer()) - op.alter_column('poolstatisticss', 'bytes_out', - type_=sa.BigInteger(), existing_type=sa.Integer()) - op.alter_column('poolstatisticss', 'active_connections', - type_=sa.BigInteger(), existing_type=sa.Integer()) - op.alter_column('poolstatisticss', 'total_connections', - type_=sa.BigInteger(), existing_type=sa.Integer()) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('poolstatisticss', 'bytes_in', - type_=sa.Integer(), existing_type=sa.BigInteger()) - op.alter_column('poolstatisticss', 'bytes_out', - type_=sa.Integer(), existing_type=sa.BigInteger()) - op.alter_column('poolstatisticss', 'active_connections', - type_=sa.Integer(), existing_type=sa.BigInteger()) - op.alter_column('poolstatisticss', 'total_connections', - type_=sa.Integer(), existing_type=sa.BigInteger()) diff --git a/neutron/db/migration/alembic_migrations/versions/b65aa907aec_set_length_of_protocol_field.py b/neutron/db/migration/alembic_migrations/versions/b65aa907aec_set_length_of_protocol_field.py deleted file mode 100644 index de82ce505..000000000 --- a/neutron/db/migration/alembic_migrations/versions/b65aa907aec_set_length_of_protocol_field.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""set_length_of_protocol_field - -Revision ID: b65aa907aec -Revises: 2447ad0e9585 -Create Date: 2014-03-21 16:30:10.626649 - -""" - -# revision identifiers, used by Alembic. -revision = 'b65aa907aec' -down_revision = '1e5dd1d09b22' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.firewall.fwaas_plugin.FirewallPlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('firewall_rules', 'protocol', type_=sa.String(40), - existing_nullable=True) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - pass diff --git a/neutron/db/migration/alembic_migrations/versions/b7a8863760e_rm_cisco_vlan_bindin.py b/neutron/db/migration/alembic_migrations/versions/b7a8863760e_rm_cisco_vlan_bindin.py deleted file mode 100644 index dcda4e686..000000000 --- a/neutron/db/migration/alembic_migrations/versions/b7a8863760e_rm_cisco_vlan_bindin.py +++ /dev/null @@ -1,60 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Remove cisco_vlan_bindings table - -Revision ID: b7a8863760e -Revises: 3cabb850f4a5 -Create Date: 2013-07-03 19:15:19.143175 - -""" - -# revision identifiers, used by Alembic. -revision = 'b7a8863760e' -down_revision = '3cabb850f4a5' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.cisco.network_plugin.PluginV2' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('cisco_vlan_bindings') - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'cisco_vlan_bindings', - sa.Column('vlan_id', sa.Integer(display_width=11), nullable=False), - sa.Column('vlan_name', sa.String(length=255), nullable=True), - sa.Column('network_id', sa.String(length=255), nullable=False), - sa.PrimaryKeyConstraint('vlan_id') - ) diff --git a/neutron/db/migration/alembic_migrations/versions/c88b6b5fea3_cisco_n1kv_tables.py b/neutron/db/migration/alembic_migrations/versions/c88b6b5fea3_cisco_n1kv_tables.py deleted file mode 100644 index 380a236ed..000000000 --- a/neutron/db/migration/alembic_migrations/versions/c88b6b5fea3_cisco_n1kv_tables.py +++ /dev/null @@ -1,150 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Cisco N1KV tables - -Revision ID: c88b6b5fea3 -Revises: 263772d65691 -Create Date: 2013-08-06 15:08:32.651975 - -""" - -# revision identifiers, used by Alembic. -revision = 'c88b6b5fea3' -down_revision = '263772d65691' - -migration_for_plugins = [ - 'neutron.plugins.cisco.network_plugin.PluginV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - -vlan_type = sa.Enum('vlan', 'vxlan', name='vlan_type') -network_type = sa.Enum('network', 'policy', name='network_type') - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_column('cisco_credentials', 'tenant_id') - op.add_column( - 'cisco_credentials', - sa.Column('type', sa.String(length=255), nullable=True) - ) - op.create_table( - 'cisco_policy_profiles', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'cisco_n1kv_vmnetworks', - sa.Column('name', sa.String(length=80), nullable=False), - sa.Column('profile_id', sa.String(length=36), nullable=True), - sa.Column('network_id', sa.String(length=36), nullable=True), - sa.Column('port_count', sa.Integer(), autoincrement=False, - nullable=True), - sa.ForeignKeyConstraint(['profile_id'], ['cisco_policy_profiles.id']), - sa.PrimaryKeyConstraint('name') - ) - op.create_table( - 'cisco_n1kv_vxlan_allocations', - sa.Column('vxlan_id', sa.Integer(), autoincrement=False, - nullable=False), - sa.Column('allocated', sa.Boolean(), autoincrement=False, - nullable=False), - sa.PrimaryKeyConstraint('vxlan_id') - ) - op.create_table( - 'cisco_network_profiles', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('segment_type', vlan_type, nullable=False), - sa.Column('segment_range', sa.String(length=255), nullable=True), - sa.Column('multicast_ip_index', sa.Integer(), autoincrement=False, - nullable=True), - sa.Column('multicast_ip_range', sa.String(length=255), nullable=True), - sa.Column('physical_network', sa.String(length=255), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'cisco_n1kv_profile_bindings', - sa.Column('profile_type', network_type, nullable=True), - sa.Column('tenant_id', sa.String(length=36), nullable=False), - sa.Column('profile_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('tenant_id', 'profile_id') - ) - op.create_table( - 'cisco_n1kv_port_bindings', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('profile_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ondelete='CASCADE'), - sa.ForeignKeyConstraint(['profile_id'], ['cisco_policy_profiles.id']), - sa.PrimaryKeyConstraint('port_id') - ) - op.create_table( - 'cisco_n1kv_vlan_allocations', - sa.Column('physical_network', sa.String(length=64), nullable=False), - sa.Column('vlan_id', - sa.Integer(), - autoincrement=False, - nullable=False), - sa.Column('allocated', - sa.Boolean(), - autoincrement=False, - nullable=False), - sa.PrimaryKeyConstraint('physical_network', 'vlan_id') - ) - op.create_table( - 'cisco_n1kv_network_bindings', - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('network_type', sa.String(length=32), nullable=False), - sa.Column('physical_network', sa.String(length=64), nullable=True), - sa.Column('segmentation_id', sa.Integer(), autoincrement=False, - nullable=True), - sa.Column('multicast_ip', sa.String(length=32), nullable=True), - sa.Column('profile_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['profile_id'], ['cisco_network_profiles.id']), - sa.PrimaryKeyConstraint('network_id') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('cisco_n1kv_network_bindings') - op.drop_table('cisco_n1kv_vlan_allocations') - op.drop_table('cisco_n1kv_port_bindings') - op.drop_table('cisco_n1kv_profile_bindings') - network_type.drop(op.get_bind(), checkfirst=False) - op.drop_table('cisco_network_profiles') - vlan_type.drop(op.get_bind(), checkfirst=False) - op.drop_table('cisco_n1kv_vxlan_allocations') - op.drop_table('cisco_n1kv_vmnetworks') - op.drop_table('cisco_policy_profiles') - op.drop_column('cisco_credentials', 'type') - op.add_column( - 'cisco_credentials', - sa.Column('tenant_id', sa.String(length=255), nullable=False) - ) diff --git a/neutron/db/migration/alembic_migrations/versions/d06e871c0d5_set_admin_state_up_not_null_ml2.py b/neutron/db/migration/alembic_migrations/versions/d06e871c0d5_set_admin_state_up_not_null_ml2.py deleted file mode 100644 index be99747c5..000000000 --- a/neutron/db/migration/alembic_migrations/versions/d06e871c0d5_set_admin_state_up_not_null_ml2.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""set_admin_state_up_not_null_ml2 - -Revision ID: d06e871c0d5 -Revises: 2447ad0e9585 -Create Date: 2014-03-21 17:22:20.545186 - -""" - -# revision identifiers, used by Alembic. -revision = 'd06e871c0d5' -down_revision = '4eca4a84f08a' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.ml2.plugin.Ml2Plugin' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('ml2_brocadeports', 'admin_state_up', nullable=False, - existing_type=sa.Boolean) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.alter_column('ml2_brocadeports', 'admin_state_up', nullable=True, - existing_type=sa.Boolean) diff --git a/neutron/db/migration/alembic_migrations/versions/e197124d4b9_add_unique_constrain.py b/neutron/db/migration/alembic_migrations/versions/e197124d4b9_add_unique_constrain.py deleted file mode 100644 index b2f4b5a87..000000000 --- a/neutron/db/migration/alembic_migrations/versions/e197124d4b9_add_unique_constrain.py +++ /dev/null @@ -1,65 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""add unique constraint to members - -Revision ID: e197124d4b9 -Revises: havana -Create Date: 2013-11-17 10:09:37.728903 - -""" - -# revision identifiers, used by Alembic. -revision = 'e197124d4b9' -down_revision = 'havana' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin', - 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', -] - -from alembic import op - -from neutron.db import migration - - -CONSTRAINT_NAME = 'uniq_member0pool_id0address0port' -TABLE_NAME = 'members' - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_unique_constraint( - name=CONSTRAINT_NAME, - source=TABLE_NAME, - local_cols=['pool_id', 'address', 'protocol_port'] - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_constraint( - CONSTRAINT_NAME, - TABLE_NAME, - type_='unique' - ) diff --git a/neutron/db/migration/alembic_migrations/versions/e6b16a30d97_cisco_provider_nets.py b/neutron/db/migration/alembic_migrations/versions/e6b16a30d97_cisco_provider_nets.py deleted file mode 100644 index 8671f77e9..000000000 --- a/neutron/db/migration/alembic_migrations/versions/e6b16a30d97_cisco_provider_nets.py +++ /dev/null @@ -1,62 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""Add cisco_provider_networks table - -Revision ID: e6b16a30d97 -Revises: 557edfc53098 -Create Date: 2013-07-18 21:46:12.792504 - -""" - -# revision identifiers, used by Alembic. -revision = 'e6b16a30d97' -down_revision = '557edfc53098' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.cisco.network_plugin.PluginV2' -] - -from alembic import op -import sqlalchemy as sa - - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'cisco_provider_networks', - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('network_type', sa.String(length=255), nullable=False), - sa.Column('segmentation_id', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('network_id') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('cisco_provider_networks') diff --git a/neutron/db/migration/alembic_migrations/versions/e766b19a3bb_nuage_initial.py b/neutron/db/migration/alembic_migrations/versions/e766b19a3bb_nuage_initial.py deleted file mode 100644 index 3562c7d94..000000000 --- a/neutron/db/migration/alembic_migrations/versions/e766b19a3bb_nuage_initial.py +++ /dev/null @@ -1,120 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""nuage_initial - -Revision ID: e766b19a3bb -Revises: 1b2580001654 -Create Date: 2014-02-14 18:03:14.841064 - -""" - -# revision identifiers, used by Alembic. -revision = 'e766b19a3bb' -down_revision = '1b2580001654' - -migration_for_plugins = [ - 'neutron.plugins.nuage.plugin.NuagePlugin' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration -from neutron.db.migration.alembic_migrations import common_ext_ops - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - common_ext_ops.upgrade_l3() - - op.create_table( - 'quotas', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('resource', sa.String(length=255), nullable=True), - sa.Column('limit', sa.Integer(), nullable=True), - sa.PrimaryKeyConstraint('id'), - ) - op.create_table( - 'net_partitions', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=64), nullable=True), - sa.Column('l3dom_tmplt_id', sa.String(length=36), nullable=True), - sa.Column('l2dom_tmplt_id', sa.String(length=36), nullable=True), - sa.PrimaryKeyConstraint('id'), - ) - op.create_table( - 'port_mapping', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('nuage_vport_id', sa.String(length=36), nullable=True), - sa.Column('nuage_vif_id', sa.String(length=36), nullable=True), - sa.Column('static_ip', sa.Boolean(), nullable=True), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('port_id'), - ) - op.create_table( - 'subnet_l2dom_mapping', - sa.Column('subnet_id', sa.String(length=36), nullable=False), - sa.Column('net_partition_id', sa.String(length=36), nullable=True), - sa.Column('nuage_subnet_id', sa.String(length=36), nullable=True), - sa.Column('nuage_l2dom_tmplt_id', sa.String(length=36), - nullable=True), - sa.Column('nuage_user_id', sa.String(length=36), nullable=True), - sa.Column('nuage_group_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['net_partition_id'], ['net_partitions.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['subnet_id'], ['subnets.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('subnet_id'), - ) - op.create_table( - 'net_partition_router_mapping', - sa.Column('net_partition_id', sa.String(length=36), nullable=False), - sa.Column('router_id', sa.String(length=36), nullable=False), - sa.Column('nuage_router_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['net_partition_id'], ['net_partitions.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['router_id'], ['routers.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('router_id'), - ) - op.create_table( - 'router_zone_mapping', - sa.Column('router_id', sa.String(length=36), nullable=False), - sa.Column('nuage_zone_id', sa.String(length=36), nullable=True), - sa.Column('nuage_user_id', sa.String(length=36), nullable=True), - sa.Column('nuage_group_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['router_id'], ['routers.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('router_id'), - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('router_zone_mapping') - op.drop_table('net_partition_router_mapping') - op.drop_table('subnet_l2dom_mapping') - op.drop_table('port_mapping') - op.drop_table('net_partitions') - op.drop_table('quotas') - - common_ext_ops.downgrade_l3() diff --git a/neutron/db/migration/alembic_migrations/versions/ed93525fd003_bigswitch_quota.py b/neutron/db/migration/alembic_migrations/versions/ed93525fd003_bigswitch_quota.py deleted file mode 100644 index 3baa247d4..000000000 --- a/neutron/db/migration/alembic_migrations/versions/ed93525fd003_bigswitch_quota.py +++ /dev/null @@ -1,64 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""bigswitch_quota - -Revision ID: ed93525fd003 -Revises: 50e86cb2637a -Create Date: 2014-01-05 10:59:19.860397 - -""" - -# revision identifiers, used by Alembic. -revision = 'ed93525fd003' -down_revision = '50e86cb2637a' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.create_table( - 'quotas', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('resource', sa.String(length=255), nullable=True), - sa.Column('limit', sa.Integer(), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - ### end Alembic commands ### - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('quotas') - ### end Alembic commands ### diff --git a/neutron/db/migration/alembic_migrations/versions/f44ab9871cd6_bsn_security_groups.py b/neutron/db/migration/alembic_migrations/versions/f44ab9871cd6_bsn_security_groups.py deleted file mode 100644 index b75bf4201..000000000 --- a/neutron/db/migration/alembic_migrations/versions/f44ab9871cd6_bsn_security_groups.py +++ /dev/null @@ -1,95 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""bsn_security_groups - -Revision ID: f44ab9871cd6 -Revises: e766b19a3bb -Create Date: 2014-02-26 17:43:43.051078 - -""" - -# revision identifiers, used by Alembic. -revision = 'f44ab9871cd6' -down_revision = 'e766b19a3bb' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2', -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.create_table( - 'securitygroups', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'securitygrouprules', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('security_group_id', sa.String(length=36), nullable=False), - sa.Column('remote_group_id', sa.String(length=36), nullable=True), - sa.Column('direction', - sa.Enum('ingress', 'egress', - name='securitygrouprules_direction'), - nullable=True), - sa.Column('ethertype', sa.String(length=40), nullable=True), - sa.Column('protocol', sa.String(length=40), nullable=True), - sa.Column('port_range_min', sa.Integer(), nullable=True), - sa.Column('port_range_max', sa.Integer(), nullable=True), - sa.Column('remote_ip_prefix', sa.String(length=255), nullable=True), - sa.ForeignKeyConstraint(['security_group_id'], ['securitygroups.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['remote_group_id'], ['securitygroups.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'securitygroupportbindings', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('security_group_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ondelete='CASCADE'), - sa.ForeignKeyConstraint(['security_group_id'], ['securitygroups.id']), - sa.PrimaryKeyConstraint('port_id', 'security_group_id') - ) - ### end Alembic commands ### - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('securitygroupportbindings') - op.drop_table('securitygrouprules') - op.drop_table('securitygroups') - ### end Alembic commands ### diff --git a/neutron/db/migration/alembic_migrations/versions/f489cf14a79c_lbaas_havana.py b/neutron/db/migration/alembic_migrations/versions/f489cf14a79c_lbaas_havana.py deleted file mode 100644 index b2d07e607..000000000 --- a/neutron/db/migration/alembic_migrations/versions/f489cf14a79c_lbaas_havana.py +++ /dev/null @@ -1,162 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""DB support for load balancing service (havana) - -Revision ID: f489cf14a79c -Revises: grizzly -Create Date: 2013-02-04 16:32:32.048731 - -""" - -# revision identifiers, used by Alembic. -revision = 'f489cf14a79c' -down_revision = 'grizzly' - -migration_for_plugins = [ - 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin', -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - u'vips', - sa.Column(u'tenant_id', sa.String(255), nullable=True), - sa.Column(u'id', sa.String(36), nullable=False), - sa.Column(u'name', sa.String(255), nullable=True), - sa.Column(u'description', sa.String(255), nullable=True), - sa.Column(u'port_id', sa.String(36), nullable=True), - sa.Column(u'protocol_port', sa.Integer(), nullable=False), - sa.Column(u'protocol', - sa.Enum("HTTP", "HTTPS", "TCP", name="lb_protocols"), - nullable=False), - sa.Column(u'pool_id', sa.String(36), nullable=False), - sa.Column(u'status', sa.String(16), nullable=False), - sa.Column(u'admin_state_up', sa.Boolean(), nullable=False), - sa.Column(u'connection_limit', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ), - sa.UniqueConstraint('pool_id'), - sa.PrimaryKeyConstraint(u'id') - ) - op.create_table( - u'sessionpersistences', - sa.Column(u'vip_id', sa.String(36), nullable=False), - sa.Column(u'type', - sa.Enum("SOURCE_IP", - "HTTP_COOKIE", - "APP_COOKIE", - name="sesssionpersistences_type"), - nullable=False), - sa.Column(u'cookie_name', sa.String(1024), nullable=True), - sa.ForeignKeyConstraint(['vip_id'], [u'vips.id'], ), - sa.PrimaryKeyConstraint(u'vip_id') - ) - op.create_table( - u'pools', - sa.Column(u'tenant_id', sa.String(255), nullable=True), - sa.Column(u'id', sa.String(36), nullable=False), - sa.Column(u'vip_id', sa.String(36), nullable=True), - sa.Column(u'name', sa.String(255), nullable=True), - sa.Column(u'description', sa.String(255), nullable=True), - sa.Column(u'subnet_id', sa.String(36), nullable=False), - sa.Column(u'protocol', - sa.Enum("HTTP", "HTTPS", "TCP", name="lb_protocols"), - nullable=False), - sa.Column(u'lb_method', - sa.Enum("ROUND_ROBIN", - "LEAST_CONNECTIONS", - "SOURCE_IP", - name="pools_lb_method"), - nullable=False), - sa.Column(u'status', sa.String(16), nullable=False), - sa.Column(u'admin_state_up', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['vip_id'], [u'vips.id'], ), - sa.PrimaryKeyConstraint(u'id') - ) - op.create_table( - u'healthmonitors', - sa.Column(u'tenant_id', sa.String(255), nullable=True), - sa.Column(u'id', sa.String(36), nullable=False), - sa.Column(u'type', - sa.Enum("PING", - "TCP", - "HTTP", - "HTTPS", - name="healthmontiors_type"), - nullable=False), - sa.Column(u'delay', sa.Integer(), nullable=False), - sa.Column(u'timeout', sa.Integer(), nullable=False), - sa.Column(u'max_retries', sa.Integer(), nullable=False), - sa.Column(u'http_method', sa.String(16), nullable=True), - sa.Column(u'url_path', sa.String(255), nullable=True), - sa.Column(u'expected_codes', sa.String(64), nullable=True), - sa.Column(u'status', sa.String(16), nullable=False), - sa.Column(u'admin_state_up', sa.Boolean(), nullable=False), - sa.PrimaryKeyConstraint(u'id') - ) - op.create_table( - u'poolmonitorassociations', - sa.Column(u'pool_id', sa.String(36), nullable=False), - sa.Column(u'monitor_id', sa.String(36), nullable=False), - sa.ForeignKeyConstraint(['monitor_id'], [u'healthmonitors.id'], ), - sa.ForeignKeyConstraint(['pool_id'], [u'pools.id'], ), - sa.PrimaryKeyConstraint(u'pool_id', u'monitor_id') - ) - op.create_table( - u'members', - sa.Column(u'tenant_id', sa.String(255), nullable=True), - sa.Column(u'id', sa.String(36), nullable=False), - sa.Column(u'pool_id', sa.String(36), nullable=False), - sa.Column(u'address', sa.String(64), nullable=False), - sa.Column(u'protocol_port', sa.Integer(), nullable=False), - sa.Column(u'weight', sa.Integer(), nullable=False), - sa.Column(u'status', sa.String(16), nullable=False), - sa.Column(u'admin_state_up', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['pool_id'], [u'pools.id'], ), - sa.PrimaryKeyConstraint(u'id') - ) - op.create_table( - u'poolstatisticss', - sa.Column(u'pool_id', sa.String(36), nullable=False), - sa.Column(u'bytes_in', sa.Integer(), nullable=False), - sa.Column(u'bytes_out', sa.Integer(), nullable=False), - sa.Column(u'active_connections', sa.Integer(), nullable=False), - sa.Column(u'total_connections', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['pool_id'], [u'pools.id'], ), - sa.PrimaryKeyConstraint(u'pool_id') - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table(u'poolstatisticss') - op.drop_table(u'members') - op.drop_table(u'poolmonitorassociations') - op.drop_table(u'healthmonitors') - op.drop_table(u'pools') - op.drop_table(u'sessionpersistences') - op.drop_table(u'vips') diff --git a/neutron/db/migration/alembic_migrations/versions/f9263d6df56_remove_dhcp_lease.py b/neutron/db/migration/alembic_migrations/versions/f9263d6df56_remove_dhcp_lease.py deleted file mode 100644 index 51b8d937e..000000000 --- a/neutron/db/migration/alembic_migrations/versions/f9263d6df56_remove_dhcp_lease.py +++ /dev/null @@ -1,46 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""remove_dhcp_lease - -Revision ID: f9263d6df56 -Revises: c88b6b5fea3 -Create Date: 2013-07-17 12:31:33.731197 - -""" - -# revision identifiers, used by Alembic. -revision = 'f9263d6df56' -down_revision = 'c88b6b5fea3' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - '*' -] - -from alembic import op -import sqlalchemy as sa - - -def upgrade(active_plugins=None, options=None): - op.drop_column('ipallocations', u'expiration') - - -def downgrade(active_plugins=None, options=None): - op.add_column('ipallocations', sa.Column(u'expiration', sa.DateTime(), - nullable=True)) diff --git a/neutron/db/migration/alembic_migrations/versions/fcac4c42e2cc_bsn_addresspairs.py b/neutron/db/migration/alembic_migrations/versions/fcac4c42e2cc_bsn_addresspairs.py deleted file mode 100644 index 9d80be9fb..000000000 --- a/neutron/db/migration/alembic_migrations/versions/fcac4c42e2cc_bsn_addresspairs.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# 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. -# - -"""bsn_addresspairs - -Revision ID: fcac4c42e2cc -Revises: 2eeaf963a447 -Create Date: 2014-02-23 12:56:00.402855 - -""" - -# revision identifiers, used by Alembic. -revision = 'fcac4c42e2cc' -down_revision = '2eeaf963a447' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = [ - 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2' -] - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration - - -def upgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.create_table( - 'allowedaddresspairs', - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('mac_address', sa.String(length=32), nullable=False), - sa.Column('ip_address', sa.String(length=64), nullable=False), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ondelete='CASCADE'), - sa.PrimaryKeyConstraint('port_id', 'mac_address', 'ip_address'), - ) - - -def downgrade(active_plugins=None, options=None): - if not migration.should_run(active_plugins, migration_for_plugins): - return - - op.drop_table('allowedaddresspairs') diff --git a/neutron/db/migration/alembic_migrations/versions/folsom_initial.py b/neutron/db/migration/alembic_migrations/versions/folsom_initial.py deleted file mode 100644 index a6dab6188..000000000 --- a/neutron/db/migration/alembic_migrations/versions/folsom_initial.py +++ /dev/null @@ -1,563 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2012 New Dream Network, LLC (DreamHost) -# -# 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 Mark McClain (DreamHost) - -"""folsom initial database - -Revision ID: folsom -Revises: None -Create Date: 2012-12-03 09:14:50.579765 - -""" - -PLUGINS = { - 'bigswitch': 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2', - 'brocade': 'neutron.plugins.brocade.NeutronPlugin.BrocadePluginV2', - 'cisco': 'neutron.plugins.cisco.network_plugin.PluginV2', - 'lbr': 'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2', - 'meta': 'neutron.plugins.metaplugin.meta_neutron_plugin.MetaPluginV2', - 'ml2': 'neutron.plugins.ml2.plugin.Ml2Plugin', - 'mlnx': 'neutron.plugins.mlnx.mlnx_plugin.MellanoxEswitchPlugin', - 'nec': 'neutron.plugins.nec.nec_plugin.NECPluginV2', - 'nvp': 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', - 'ocnvsd': 'neutron.plugins.oneconvergence.plugin.OneConvergencePluginV2', - 'ovs': 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', - 'plumgrid': 'neutron.plugins.plumgrid.plumgrid_plugin.plumgrid_plugin.' - 'NeutronPluginPLUMgridV2', - 'ryu': 'neutron.plugins.ryu.ryu_neutron_plugin.RyuNeutronPluginV2', - 'ibm': 'neutron.plugins.ibm.sdnve_neutron_plugin.SdnvePluginV2', -} - -L3_CAPABLE = [ - PLUGINS['lbr'], - PLUGINS['meta'], - PLUGINS['ml2'], - PLUGINS['mlnx'], - PLUGINS['nec'], - PLUGINS['ocnvsd'], - PLUGINS['ovs'], - PLUGINS['ryu'], - PLUGINS['brocade'], - PLUGINS['plumgrid'], - PLUGINS['ibm'], -] - -FOLSOM_QUOTA = [ - PLUGINS['lbr'], - PLUGINS['ml2'], - PLUGINS['nvp'], - PLUGINS['ocnvsd'], - PLUGINS['ovs'], -] - - -# revision identifiers, used by Alembic. -revision = 'folsom' -down_revision = None - -from alembic import op -import sqlalchemy as sa - -from neutron.db import migration -from neutron.db.migration.alembic_migrations import common_ext_ops -# NOTE: This is a special migration that creates a Folsom compatible database. - - -def upgrade(active_plugins=None, options=None): - # general model - upgrade_base() - - if migration.should_run(active_plugins, L3_CAPABLE): - common_ext_ops.upgrade_l3() - - if migration.should_run(active_plugins, FOLSOM_QUOTA): - common_ext_ops.upgrade_quota(options) - - if PLUGINS['lbr'] in active_plugins: - upgrade_linuxbridge() - elif PLUGINS['ovs'] in active_plugins: - upgrade_ovs() - elif PLUGINS['cisco'] in active_plugins: - upgrade_cisco() - # Cisco plugin imports OVS models too - upgrade_ovs() - elif PLUGINS['meta'] in active_plugins: - upgrade_meta() - elif PLUGINS['nec'] in active_plugins: - upgrade_nec() - elif PLUGINS['ryu'] in active_plugins: - upgrade_ryu() - elif PLUGINS['brocade'] in active_plugins: - upgrade_brocade() - # Brocade plugin imports linux bridge models too - upgrade_linuxbridge() - - -def upgrade_base(): - op.create_table( - 'networks', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('status', sa.String(length=16), nullable=True), - sa.Column('admin_state_up', sa.Boolean(), nullable=True), - sa.Column('shared', sa.Boolean(), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - - op.create_table( - 'subnets', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('network_id', sa.String(length=36), nullable=True), - sa.Column('ip_version', sa.Integer(), nullable=False), - sa.Column('cidr', sa.String(length=64), nullable=False), - sa.Column('gateway_ip', sa.String(length=64), nullable=True), - sa.Column('enable_dhcp', sa.Boolean(), nullable=True), - sa.Column('shared', sa.Boolean(), nullable=True), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], ), - sa.PrimaryKeyConstraint('id') - ) - - op.create_table( - 'ports', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('name', sa.String(length=255), nullable=True), - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('mac_address', sa.String(length=32), nullable=False), - sa.Column('admin_state_up', sa.Boolean(), nullable=False), - sa.Column('status', sa.String(length=16), nullable=False), - sa.Column('device_id', sa.String(length=255), nullable=False), - sa.Column('device_owner', sa.String(length=255), nullable=False), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], ), - sa.PrimaryKeyConstraint('id') - ) - - op.create_table( - 'dnsnameservers', - sa.Column('address', sa.String(length=128), nullable=False), - sa.Column('subnet_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['subnet_id'], ['subnets.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('address', 'subnet_id') - ) - - op.create_table( - 'ipallocations', - sa.Column('port_id', sa.String(length=36), nullable=True), - sa.Column('ip_address', sa.String(length=64), nullable=False), - sa.Column('subnet_id', sa.String(length=36), nullable=False), - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('expiration', sa.DateTime(), nullable=True), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['subnet_id'], ['subnets.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('ip_address', 'subnet_id', 'network_id') - ) - - op.create_table( - 'routes', - sa.Column('destination', sa.String(length=64), nullable=False), - sa.Column('nexthop', sa.String(length=64), nullable=False), - sa.Column('subnet_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['subnet_id'], ['subnets.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('destination', 'nexthop', 'subnet_id') - ) - - op.create_table( - 'ipallocationpools', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('subnet_id', sa.String(length=36), nullable=True), - sa.Column('first_ip', sa.String(length=64), nullable=False), - sa.Column('last_ip', sa.String(length=64), nullable=False), - sa.ForeignKeyConstraint(['subnet_id'], ['subnets.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id') - ) - - op.create_table( - 'ipavailabilityranges', - sa.Column('allocation_pool_id', sa.String(length=36), nullable=False), - sa.Column('first_ip', sa.String(length=64), nullable=False), - sa.Column('last_ip', sa.String(length=64), nullable=False), - sa.ForeignKeyConstraint(['allocation_pool_id'], - ['ipallocationpools.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('allocation_pool_id', 'first_ip', 'last_ip') - ) - - -def upgrade_linuxbridge(): - op.create_table( - 'network_states', - sa.Column('physical_network', sa.String(length=64), nullable=False), - sa.Column('vlan_id', sa.Integer(), autoincrement=False, - nullable=False), - sa.Column('allocated', sa.Boolean(), nullable=False), - sa.PrimaryKeyConstraint('physical_network', 'vlan_id') - ) - - op.create_table( - 'network_bindings', - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('physical_network', sa.String(length=64), nullable=True), - sa.Column('vlan_id', sa.Integer(), autoincrement=False, - nullable=False), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('network_id') - ) - - -def upgrade_ovs(): - op.create_table( - 'ovs_tunnel_endpoints', - sa.Column('ip_address', sa.String(length=64), nullable=False), - sa.Column('id', sa.Integer(), nullable=False), - sa.PrimaryKeyConstraint('ip_address') - ) - - op.create_table( - 'ovs_tunnel_ips', - sa.Column('ip_address', sa.String(length=255), nullable=False), - sa.PrimaryKeyConstraint('ip_address') - ) - - op.create_table( - 'ovs_vlan_allocations', - sa.Column('physical_network', sa.String(length=64), nullable=False), - sa.Column('vlan_id', sa.Integer(), autoincrement=False, - nullable=False), - sa.Column('allocated', sa.Boolean(), nullable=False), - sa.PrimaryKeyConstraint('physical_network', 'vlan_id') - ) - - op.create_table( - 'ovs_tunnel_allocations', - sa.Column('tunnel_id', sa.Integer(), autoincrement=False, - nullable=False), - sa.Column('allocated', sa.Boolean(), nullable=False), - sa.PrimaryKeyConstraint('tunnel_id') - ) - - op.create_table( - 'ovs_network_bindings', - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('network_type', sa.String(length=32), nullable=False), - sa.Column('physical_network', sa.String(length=64), nullable=True), - sa.Column('segmentation_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('network_id') - ) - - -def upgrade_meta(): - op.create_table( - 'networkflavors', - sa.Column('flavor', sa.String(length=255)), - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('network_id') - ) - - op.create_table( - 'routerflavors', - sa.Column('flavor', sa.String(length=255)), - sa.Column('router_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['router_id'], ['routers.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('router_id') - ) - - -def upgrade_nec(): - op.create_table( - 'ofctenants', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('quantum_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('id') - ) - - op.create_table( - 'ofcnetworks', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('quantum_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('id') - ) - - op.create_table( - 'ofcports', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('quantum_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('id') - ) - - op.create_table( - 'ofcfilters', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('quantum_id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('id') - ) - - op.create_table( - 'portinfos', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('datapath_id', sa.String(length=36), nullable=False), - sa.Column('port_no', sa.Integer(), nullable=False), - sa.Column('vlan_id', sa.Integer(), nullable=False), - sa.Column('mac', sa.String(length=32), nullable=False), - sa.PrimaryKeyConstraint('id') - ) - - op.create_table( - 'packetfilters', - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('priority', sa.Integer(), nullable=False), - sa.Column('action', sa.String(16), nullable=False), - sa.Column('in_port', sa.String(36), nullable=False), - sa.Column('src_mac', sa.String(32), nullable=False), - sa.Column('dst_mac', sa.String(32), nullable=False), - sa.Column('eth_type', sa.Integer(), nullable=False), - sa.Column('src_cidr', sa.String(64), nullable=False), - sa.Column('dst_cidr', sa.String(64), nullable=False), - sa.Column('protocol', sa.String(16), nullable=False), - sa.Column('src_port', sa.Integer(), nullable=False), - sa.Column('dst_port', sa.Integer(), nullable=False), - sa.Column('admin_state_up', sa.Boolean(), nullable=False), - sa.Column('status', sa.String(16), nullable=False), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id') - ) - - -def upgrade_ryu(): - op.create_table( - 'ofp_server', - sa.Column('id', sa.Integer(), autoincrement=False, nullable=False), - sa.Column('address', sa.String(255)), - sa.Column('host_type', sa.String(255)), - sa.PrimaryKeyConstraint('id') - ) - - -def upgrade_brocade(): - op.create_table( - 'brocadenetworks', - sa.Column('id', sa.Integer(), autoincrement=False, nullable=False), - sa.Column('vlan', sa.String(10)), - sa.PrimaryKeyConstraint('id') - ) - - op.create_table( - 'brocadeports', - sa.Column('port_id', sa.String(36), nullable=False), - sa.Column('network_id', sa.String(36)), - sa.Column('admin_state_up', sa.Boolean()), - sa.Column('physical_interface', sa.String(36)), - sa.Column('vlan_id', sa.String(10)), - sa.Column('tenant_id', sa.String(36)), - sa.PrimaryKeyConstraint('port_id') - ) - - -def upgrade_cisco(): - op.create_table( - 'cisco_vlan_ids', - sa.Column('vlan_id', sa.Integer(), autoincrement=True), - sa.Column('vlan_used', sa.Boolean()), - sa.PrimaryKeyConstraint('vlan_id') - ) - - op.create_table( - 'cisco_vlan_bindings', - sa.Column('vlan_id', sa.Integer(), autoincrement=True), - sa.Column('vlan_name', sa.String(255)), - sa.Column('network_id', sa.String(255), nullable=False), - sa.PrimaryKeyConstraint('vlan_id') - ) - - op.create_table( - 'portprofiles', - sa.Column('uuid', sa.String(255), nullable=False), - sa.Column('name', sa.String(255)), - sa.Column('vlan_id', sa.Integer()), - sa.Column('qos', sa.String(255)), - sa.PrimaryKeyConstraint('uuid') - ) - - op.create_table( - 'portprofile_bindings', - sa.Column('id', sa.Integer(), autoincrement=True), - sa.Column('tenant_id', sa.String(255)), - sa.Column('port_id', sa.String(255), nullable=False), - sa.Column('portprofile_id', sa.String(255), nullable=False), - sa.Column('default', sa.Boolean()), - sa.PrimaryKeyConstraint('id'), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ), - sa.ForeignKeyConstraint(['portprofile_id'], ['portprofiles.uuid'], ), - ) - - op.create_table( - 'qoss', # yes two S's - sa.Column('qos_id', sa.String(255)), - sa.Column('tenant_id', sa.String(255)), - sa.Column('qos_name', sa.String(255)), - sa.Column('qos_desc', sa.String(255)), - sa.PrimaryKeyConstraint('tenant_id', 'qos_name') - ) - - op.create_table( - 'credentials', - sa.Column('credential_id', sa.String(255)), - sa.Column('tenant_id', sa.String(255)), - sa.Column('credential_name', sa.String(255)), - sa.Column('user_name', sa.String(255)), - sa.Column('password', sa.String(255)), - sa.PrimaryKeyConstraint('tenant_id', 'credential_name') - ) - - op.create_table( - 'port_bindings', - sa.Column('id', sa.Integer(), autoincrement=True), - sa.Column('port_id', sa.String(255), nullable=False), - sa.Column('blade_intf_dn', sa.String(255), nullable=False), - sa.Column('portprofile_name', sa.String(255)), - sa.Column('vlan_name', sa.String(255)), - sa.Column('vlan_id', sa.Integer()), - sa.Column('qos', sa.String(255)), - sa.Column('tenant_id', sa.String(255)), - sa.Column('instance_id', sa.String(255)), - sa.Column('vif_id', sa.String(255)), - sa.PrimaryKeyConstraint('id') - ) - - op.create_table( - 'nexusport_bindings', - sa.Column('id', sa.Integer(), primary_key=True, autoincrement=True), - sa.Column('port_id', sa.String(255)), - sa.Column('vlan_id', sa.Integer()), - sa.PrimaryKeyConstraint('id') - ) - - -def downgrade(active_plugins=None, options=None): - if PLUGINS['lbr'] in active_plugins: - downgrade_linuxbridge() - elif PLUGINS['ovs'] in active_plugins: - downgrade_ovs() - elif PLUGINS['cisco'] in active_plugins: - # Cisco plugin imports OVS models too - downgrade_ovs() - downgrade_cisco() - elif PLUGINS['meta'] in active_plugins: - downgrade_meta() - elif PLUGINS['nec'] in active_plugins: - downgrade_nec() - elif PLUGINS['ryu'] in active_plugins: - downgrade_ryu() - elif PLUGINS['brocade'] in active_plugins: - # Brocade plugin imports linux bridge models too - downgrade_brocade() - downgrade_linuxbridge() - - if migration.should_run(active_plugins, FOLSOM_QUOTA): - common_ext_ops.downgrade_quota(options) - - if migration.should_run(active_plugins, L3_CAPABLE): - common_ext_ops.downgrade_l3() - - downgrade_base() - - -def downgrade_base(): - drop_tables( - 'ipavailabilityranges', - 'ipallocationpools', - 'routes', - 'ipallocations', - 'dnsnameservers', - 'ports', - 'subnets', - 'networks' - ) - - -def downgrade_linuxbridge(): - drop_tables('network_bindings', 'network_states') - - -def downgrade_ovs(): - drop_tables( - 'ovs_network_bindings', - 'ovs_tunnel_allocations', - 'ovs_vlan_allocations', - 'ovs_tunnel_ips', - 'ovs_tunnel_endpoints' - ) - - -def downgrade_meta(): - drop_tables('routerflavors', 'networkflavors') - - -def downgrade_nec(): - drop_tables( - 'packetfilters', - 'portinfos', - 'ofcfilters', - 'ofcports', - 'ofcnetworks', - 'ofctenants' - ) - - -def downgrade_ryu(): - op.drop_table('ofp_server') - - -def downgrade_brocade(): - op.drop_table('brocadenetworks') - op.drop_table('brocadeports') - - -def downgrade_cisco(): - drop_tables( - 'nexusport_bindings', - 'port_bindings', - 'credentials', - 'qoss', - 'portprofile_bindings', - 'portprofiles', - 'cisco_vlan_bindings', - 'cisco_vlan_ids' - ) - - -def drop_tables(*tables): - for table in tables: - op.drop_table(table) diff --git a/neutron/db/migration/alembic_migrations/versions/grizzly_release.py b/neutron/db/migration/alembic_migrations/versions/grizzly_release.py deleted file mode 100644 index a7a25652f..000000000 --- a/neutron/db/migration/alembic_migrations/versions/grizzly_release.py +++ /dev/null @@ -1,42 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""grizzly - -Revision ID: grizzly -Revises: 1341ed32cc1e -Create Date: 2013-03-12 23:59:59.000000 - -""" - -# revision identifiers, used by Alembic. -revision = 'grizzly' -down_revision = '1341ed32cc1e' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = ['*'] - - -def upgrade(active_plugins=None, options=None): - """A no-op migration for marking the Grizzly release.""" - pass - - -def downgrade(active_plugins=None, options=None): - """A no-op migration for marking the Grizzly release.""" - pass diff --git a/neutron/db/migration/alembic_migrations/versions/havana_release.py b/neutron/db/migration/alembic_migrations/versions/havana_release.py deleted file mode 100644 index 5be1e0676..000000000 --- a/neutron/db/migration/alembic_migrations/versions/havana_release.py +++ /dev/null @@ -1,42 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation -# -# 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. -# - -"""havana - -Revision ID: havana -Revises: 40b0aff0302e -Create Date: 2013-10-02 00:00:00.000000 - -""" - -# revision identifiers, used by Alembic. -revision = 'havana' -down_revision = '40b0aff0302e' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = ['*'] - - -def upgrade(active_plugins=None, options=None): - """A no-op migration for marking the Havana release.""" - pass - - -def downgrade(active_plugins=None, options=None): - """A no-op migration for marking the Havana release.""" - pass diff --git a/neutron/db/migration/alembic_migrations/versions/icehouse_release.py b/neutron/db/migration/alembic_migrations/versions/icehouse_release.py deleted file mode 100644 index fc8708f39..000000000 --- a/neutron/db/migration/alembic_migrations/versions/icehouse_release.py +++ /dev/null @@ -1,42 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2014 Yahoo! 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. -# - -"""icehouse - -Revision ID: icehouse -Revises: 5ac1c354a051 -Create Date: 2013-03-28 00:00:00.000000 - -""" - -# revision identifiers, used by Alembic. -revision = 'icehouse' -down_revision = '5ac1c354a051' - -# Change to ['*'] if this migration applies to all plugins - -migration_for_plugins = ['*'] - - -def upgrade(active_plugins=None, options=None): - """A no-op migration for marking the Icehouse release.""" - pass - - -def downgrade(active_plugins=None, options=None): - """A no-op migration for marking the Icehouse release.""" - pass diff --git a/neutron/db/migration/migrate_to_ml2.py b/neutron/db/migration/migrate_to_ml2.py deleted file mode 100755 index 504061ed7..000000000 --- a/neutron/db/migration/migrate_to_ml2.py +++ /dev/null @@ -1,462 +0,0 @@ -# Copyright (c) 2014 Red Hat, 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. - -""" -This script will migrate the database of an openvswitch or linuxbridge -plugin so that it can be used with the ml2 plugin. - -Known Limitations: - - - THIS SCRIPT IS DESTRUCTIVE! Make sure to backup your - Neutron database before running this script, in case anything goes - wrong. - - - It will be necessary to upgrade the database to the target release - via neutron-db-manage before attempting to migrate to ml2. - Initially, only the icehouse release is supported. - - - This script does not automate configuration migration. - -Example usage: - - python -m neutron.db.migration.migrate_to_ml2 openvswitch \ - mysql://login:pass@127.0.0.1/neutron - -Note that migration of tunneling state will only be attempted if the ---tunnel-type parameter is provided. - -To manually test migration from ovs to ml2 with devstack: - - - stack with Q_PLUGIN=openvswitch - - boot an instance and validate connectivity - - stop the neutron service and all agents - - run the neutron-migrate-to-ml2 script - - update /etc/neutron/neutron.conf as follows: - - core_plugin = neutron.plugins.ml2.plugin.Ml2Plugin - - - Create /etc/neutron/plugins/ml2/ml2_conf.ini and ensure that: - - ml2.mechanism_drivers includes 'openvswitch' - - ovs.local_ip is set correctly - - database.connection is set correctly - - Start the neutron service with the ml2 config file created in - the previous step in place of the openvswitch config file - - Start all the agents - - verify that the booted instance still has connectivity - - boot a second instance and validate connectivity -""" - -import argparse - -import sqlalchemy as sa - -from neutron.extensions import portbindings -from neutron.openstack.common import uuidutils -from neutron.plugins.common import constants as p_const -from neutron.plugins.ml2.drivers import type_vxlan - - -# Migration targets -LINUXBRIDGE = 'linuxbridge' -OPENVSWITCH = 'openvswitch' - -# Releases -ICEHOUSE = 'icehouse' - - -SUPPORTED_SCHEMA_VERSIONS = [ICEHOUSE] - - -def check_db_schema_version(engine, metadata): - """Check that current version of the db schema is supported.""" - version_table = sa.Table( - 'alembic_version', metadata, autoload=True, autoload_with=engine) - versions = [v[0] for v in engine.execute(version_table.select())] - if not versions: - raise ValueError(_("Missing version in alembic_versions table")) - elif len(versions) > 1: - raise ValueError(_("Multiple versions in alembic_versions table: %s") - % versions) - current_version = versions[0] - if current_version not in SUPPORTED_SCHEMA_VERSIONS: - raise SystemError(_("Unsupported database schema %(current)s. " - "Please migrate your database to one of following " - "versions: %(supported)s") - % {'current': current_version, - 'supported': ', '.join(SUPPORTED_SCHEMA_VERSIONS)} - ) - - -# Duplicated from neutron.plugins.linuxbridge.common.constants to -# avoid having any dependency on the linuxbridge plugin being -# installed. -def interpret_vlan_id(vlan_id): - """Return (network_type, segmentation_id) tuple for encoded vlan_id.""" - FLAT_VLAN_ID = -1 - LOCAL_VLAN_ID = -2 - if vlan_id == LOCAL_VLAN_ID: - return (p_const.TYPE_LOCAL, None) - elif vlan_id == FLAT_VLAN_ID: - return (p_const.TYPE_FLAT, None) - else: - return (p_const.TYPE_VLAN, vlan_id) - - -class BaseMigrateToMl2_Icehouse(object): - - def __init__(self, vif_type, driver_type, segment_table_name, - vlan_allocation_table_name, old_tables): - self.vif_type = vif_type - self.driver_type = driver_type - self.segment_table_name = segment_table_name - self.vlan_allocation_table_name = vlan_allocation_table_name - self.old_tables = old_tables - - def __call__(self, connection_url, save_tables=False, tunnel_type=None, - vxlan_udp_port=None): - engine = sa.create_engine(connection_url) - metadata = sa.MetaData() - check_db_schema_version(engine, metadata) - - self.define_ml2_tables(metadata) - - # Autoload the ports table to ensure that foreign keys to it and - # the network table can be created for the new tables. - sa.Table('ports', metadata, autoload=True, autoload_with=engine) - metadata.create_all(engine) - - self.migrate_network_segments(engine, metadata) - if tunnel_type: - self.migrate_tunnels(engine, tunnel_type, vxlan_udp_port) - self.migrate_vlan_allocations(engine) - self.migrate_port_bindings(engine, metadata) - - self.drop_old_tables(engine, save_tables) - - def migrate_segment_dict(self, binding): - binding['id'] = uuidutils.generate_uuid() - - def migrate_network_segments(self, engine, metadata): - # Migrating network segments requires loading the data to python - # so that a uuid can be generated for each segment. - source_table = sa.Table(self.segment_table_name, metadata, - autoload=True, autoload_with=engine) - source_segments = engine.execute(source_table.select()) - ml2_segments = [dict(x) for x in source_segments] - for segment in ml2_segments: - self.migrate_segment_dict(segment) - if ml2_segments: - ml2_network_segments = metadata.tables['ml2_network_segments'] - engine.execute(ml2_network_segments.insert(), ml2_segments) - - def migrate_tunnels(self, engine, tunnel_type, vxlan_udp_port=None): - """Override this method to perform plugin-specific tunnel migration.""" - pass - - def migrate_vlan_allocations(self, engine): - engine.execute((""" - INSERT INTO ml2_vlan_allocations - SELECT physical_network, vlan_id, allocated - FROM %(source_table)s - WHERE allocated = 1 - """) % {'source_table': self.vlan_allocation_table_name}) - - def get_port_segment_map(self, engine): - """Retrieve a mapping of port id to segment id. - - The monolithic plugins only support a single segment per - network, so the segment id can be uniquely identified by - the network associated with a given port. - - """ - port_segments = engine.execute(""" - SELECT ports_network.port_id, ml2_network_segments.id AS segment_id - FROM ml2_network_segments, ( - SELECT portbindingports.port_id, ports.network_id - FROM portbindingports, ports - WHERE portbindingports.port_id = ports.id - ) AS ports_network - WHERE ml2_network_segments.network_id = ports_network.network_id - """) - return dict(x for x in port_segments) - - def migrate_port_bindings(self, engine, metadata): - port_segment_map = self.get_port_segment_map(engine) - - port_binding_ports = sa.Table('portbindingports', metadata, - autoload=True, autoload_with=engine) - source_bindings = engine.execute(port_binding_ports.select()) - ml2_bindings = [dict(x) for x in source_bindings] - for binding in ml2_bindings: - binding['vif_type'] = self.vif_type - binding['driver'] = self.driver_type - segment = port_segment_map.get(binding['port_id']) - if segment: - binding['segment'] = segment - if ml2_bindings: - ml2_port_bindings = metadata.tables['ml2_port_bindings'] - engine.execute(ml2_port_bindings.insert(), ml2_bindings) - - def drop_old_tables(self, engine, save_tables=False): - if save_tables: - return - old_tables = self.old_tables + [self.vlan_allocation_table_name, - self.segment_table_name] - for table_name in old_tables: - engine.execute('DROP TABLE %s' % table_name) - - def define_ml2_tables(self, metadata): - - sa.Table( - 'arista_provisioned_nets', metadata, - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('network_id', sa.String(length=36), nullable=True), - sa.Column('segmentation_id', sa.Integer(), - autoincrement=False, nullable=True), - sa.PrimaryKeyConstraint('id'), - ) - - sa.Table( - 'arista_provisioned_vms', metadata, - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('vm_id', sa.String(length=255), nullable=True), - sa.Column('host_id', sa.String(length=255), nullable=True), - sa.Column('port_id', sa.String(length=36), nullable=True), - sa.Column('network_id', sa.String(length=36), nullable=True), - sa.PrimaryKeyConstraint('id'), - ) - - sa.Table( - 'arista_provisioned_tenants', metadata, - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.PrimaryKeyConstraint('id'), - ) - - sa.Table( - 'cisco_ml2_nexusport_bindings', metadata, - sa.Column('binding_id', sa.Integer(), nullable=False), - sa.Column('port_id', sa.String(length=255), nullable=True), - sa.Column('vlan_id', sa.Integer(), autoincrement=False, - nullable=False), - sa.Column('switch_ip', sa.String(length=255), nullable=True), - sa.Column('instance_id', sa.String(length=255), nullable=True), - sa.PrimaryKeyConstraint('binding_id'), - ) - - sa.Table( - 'cisco_ml2_credentials', metadata, - sa.Column('credential_id', sa.String(length=255), nullable=True), - sa.Column('tenant_id', sa.String(length=255), nullable=False), - sa.Column('credential_name', sa.String(length=255), - nullable=False), - sa.Column('user_name', sa.String(length=255), nullable=True), - sa.Column('password', sa.String(length=255), nullable=True), - sa.PrimaryKeyConstraint('tenant_id', 'credential_name'), - ) - - sa.Table( - 'ml2_flat_allocations', metadata, - sa.Column('physical_network', sa.String(length=64), - nullable=False), - sa.PrimaryKeyConstraint('physical_network'), - ) - - sa.Table( - 'ml2_gre_allocations', metadata, - sa.Column('gre_id', sa.Integer, nullable=False, - autoincrement=False), - sa.Column('allocated', sa.Boolean, nullable=False), - sa.PrimaryKeyConstraint('gre_id'), - ) - - sa.Table( - 'ml2_gre_endpoints', metadata, - sa.Column('ip_address', sa.String(length=64)), - sa.PrimaryKeyConstraint('ip_address'), - ) - - sa.Table( - 'ml2_network_segments', metadata, - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('network_id', sa.String(length=36), nullable=False), - sa.Column('network_type', sa.String(length=32), nullable=False), - sa.Column('physical_network', sa.String(length=64), nullable=True), - sa.Column('segmentation_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id'), - ) - - sa.Table( - 'ml2_port_bindings', metadata, - sa.Column('port_id', sa.String(length=36), nullable=False), - sa.Column('host', sa.String(length=255), nullable=False), - sa.Column('vif_type', sa.String(length=64), nullable=False), - sa.Column('driver', sa.String(length=64), nullable=True), - sa.Column('segment', sa.String(length=36), nullable=True), - sa.Column('vnic_type', sa.String(length=64), nullable=False, - server_default='normal'), - sa.Column('vif_details', sa.String(4095), nullable=False, - server_default=''), - sa.Column('profile', sa.String(4095), nullable=False, - server_default=''), - sa.ForeignKeyConstraint(['port_id'], ['ports.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['segment'], ['ml2_network_segments.id'], - ondelete='SET NULL'), - sa.PrimaryKeyConstraint('port_id'), - ) - - sa.Table( - 'ml2_vlan_allocations', metadata, - sa.Column('physical_network', sa.String(length=64), - nullable=False), - sa.Column('vlan_id', sa.Integer(), autoincrement=False, - nullable=False), - sa.Column('allocated', sa.Boolean(), autoincrement=False, - nullable=False), - sa.PrimaryKeyConstraint('physical_network', 'vlan_id'), - ) - - sa.Table( - 'ml2_vxlan_allocations', metadata, - sa.Column('vxlan_vni', sa.Integer, nullable=False, - autoincrement=False), - sa.Column('allocated', sa.Boolean, nullable=False), - sa.PrimaryKeyConstraint('vxlan_vni'), - ) - - sa.Table( - 'ml2_vxlan_endpoints', metadata, - sa.Column('ip_address', sa.String(length=64)), - sa.Column('udp_port', sa.Integer(), nullable=False, - autoincrement=False), - sa.PrimaryKeyConstraint('ip_address', 'udp_port'), - ) - - -class MigrateLinuxBridgeToMl2_Icehouse(BaseMigrateToMl2_Icehouse): - - def __init__(self): - super(MigrateLinuxBridgeToMl2_Icehouse, self).__init__( - vif_type=portbindings.VIF_TYPE_BRIDGE, - driver_type=LINUXBRIDGE, - segment_table_name='network_bindings', - vlan_allocation_table_name='network_states', - old_tables=['portbindingports']) - - def migrate_segment_dict(self, binding): - super(MigrateLinuxBridgeToMl2_Icehouse, self).migrate_segment_dict( - binding) - vlan_id = binding.pop('vlan_id') - network_type, segmentation_id = interpret_vlan_id(vlan_id) - binding['network_type'] = network_type - binding['segmentation_id'] = segmentation_id - - -class MigrateOpenvswitchToMl2_Icehouse(BaseMigrateToMl2_Icehouse): - - def __init__(self): - super(MigrateOpenvswitchToMl2_Icehouse, self).__init__( - vif_type=portbindings.VIF_TYPE_OVS, - driver_type=OPENVSWITCH, - segment_table_name='ovs_network_bindings', - vlan_allocation_table_name='ovs_vlan_allocations', - old_tables=[ - 'ovs_tunnel_allocations', - 'ovs_tunnel_endpoints', - 'portbindingports', - ]) - - def migrate_tunnels(self, engine, tunnel_type, vxlan_udp_port=None): - if tunnel_type == p_const.TYPE_GRE: - engine.execute(""" - INSERT INTO ml2_gre_allocations - SELECT tunnel_id as gre_id, allocated - FROM ovs_tunnel_allocations - WHERE allocated = 1 - """) - engine.execute(""" - INSERT INTO ml2_gre_endpoints - SELECT ip_address - FROM ovs_tunnel_endpoints - """) - elif tunnel_type == p_const.TYPE_VXLAN: - if not vxlan_udp_port: - vxlan_udp_port = type_vxlan.VXLAN_UDP_PORT - engine.execute(""" - INSERT INTO ml2_vxlan_allocations - SELECT tunnel_id as vxlan_vni, allocated - FROM ovs_tunnel_allocations - WHERE allocated = 1 - """) - engine.execute(sa.text(""" - INSERT INTO ml2_vxlan_endpoints - SELECT ip_address, :udp_port as udp_port - FROM ovs_tunnel_endpoints - """), udp_port=vxlan_udp_port) - else: - raise ValueError(_('Unknown tunnel type: %s') % tunnel_type) - - -migrate_map = { - ICEHOUSE: { - OPENVSWITCH: MigrateOpenvswitchToMl2_Icehouse, - LINUXBRIDGE: MigrateLinuxBridgeToMl2_Icehouse, - }, -} - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('plugin', choices=[OPENVSWITCH, LINUXBRIDGE], - help=_('The plugin type whose database will be ' - 'migrated')) - parser.add_argument('connection', - help=_('The connection url for the target db')) - parser.add_argument('--tunnel-type', choices=[p_const.TYPE_GRE, - p_const.TYPE_VXLAN], - help=_('The %s tunnel type to migrate from') % - OPENVSWITCH) - parser.add_argument('--vxlan-udp-port', default=None, type=int, - help=_('The UDP port to use for VXLAN tunnels.')) - parser.add_argument('--release', default=ICEHOUSE, choices=[ICEHOUSE]) - parser.add_argument('--save-tables', default=False, action='store_true', - help=_("Retain the old plugin's tables")) - #TODO(marun) Provide a verbose option - args = parser.parse_args() - - if args.plugin == LINUXBRIDGE and (args.tunnel_type or - args.vxlan_udp_port): - msg = _('Tunnel args (tunnel-type and vxlan-udp-port) are not valid ' - 'for the %s plugin') - parser.error(msg % LINUXBRIDGE) - - try: - migrate_func = migrate_map[args.release][args.plugin]() - except KeyError: - msg = _('Support for migrating %(plugin)s for release ' - '%(release)s is not yet implemented') - parser.error(msg % {'plugin': args.plugin, 'release': args.release}) - else: - migrate_func(args.connection, args.save_tables, args.tunnel_type, - args.vxlan_udp_port) - - -if __name__ == '__main__': - main() diff --git a/neutron/db/portbindings_base.py b/neutron/db/portbindings_base.py deleted file mode 100644 index 045b7e3f2..000000000 --- a/neutron/db/portbindings_base.py +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2013 UnitedStack 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: Yong Sheng Gong, UnitedStack Inc. - -from neutron.api.v2 import attributes -from neutron.db import db_base_plugin_v2 - - -class PortBindingBaseMixin(object): - base_binding_dict = None - - def _process_portbindings_create_and_update(self, context, port_data, - port): - self.extend_port_dict_binding(port, None) - - def extend_port_dict_binding(self, port_res, port_db): - if self.base_binding_dict: - port_res.update(self.base_binding_dict) - - -def _extend_port_dict_binding(plugin, port_res, port_db): - if not isinstance(plugin, PortBindingBaseMixin): - return - plugin.extend_port_dict_binding(port_res, port_db) - - -def register_port_dict_function(): - db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attributes.PORTS, [_extend_port_dict_binding]) diff --git a/neutron/db/portbindings_db.py b/neutron/db/portbindings_db.py deleted file mode 100644 index 1f94f8397..000000000 --- a/neutron/db/portbindings_db.py +++ /dev/null @@ -1,121 +0,0 @@ -# Copyright 2013 IBM Corp. -# 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: Yong Sheng Gong, IBM, Corp. - -import sqlalchemy as sa -from sqlalchemy import orm - -from neutron.api.v2 import attributes -from neutron.db import db_base_plugin_v2 -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.db import portbindings_base -from neutron.extensions import portbindings - - -class PortBindingPort(model_base.BASEV2): - port_id = sa.Column(sa.String(36), - sa.ForeignKey('ports.id', ondelete="CASCADE"), - primary_key=True) - host = sa.Column(sa.String(255), nullable=False) - port = orm.relationship( - models_v2.Port, - backref=orm.backref("portbinding", - lazy='joined', uselist=False, - cascade='delete')) - - -class PortBindingMixin(portbindings_base.PortBindingBaseMixin): - extra_binding_dict = None - - def _port_model_hook(self, context, original_model, query): - query = query.outerjoin(PortBindingPort, - (original_model.id == - 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 - if len(values) == 1: - query = query.filter(PortBindingPort.host == values[0]) - else: - query = query.filter(PortBindingPort.host.in_(values)) - return query - - db_base_plugin_v2.NeutronDbPluginV2.register_model_query_hook( - models_v2.Port, - "portbindings_port", - '_port_model_hook', - None, - '_port_result_filter_hook') - - def _process_portbindings_create_and_update(self, context, port_data, - port): - binding_profile = port.get(portbindings.PROFILE) - binding_profile_set = attributes.is_attr_set(binding_profile) - if not binding_profile_set and binding_profile is not None: - del port[portbindings.PROFILE] - - binding_vnic = port.get(portbindings.VNIC_TYPE) - binding_vnic_set = attributes.is_attr_set(binding_vnic) - if not binding_vnic_set and binding_vnic is not None: - del port[portbindings.VNIC_TYPE] - # REVISIT(irenab) Add support for vnic_type for plugins that - # can handle more than one type. - # Currently implemented for ML2 plugin that does not use - # PortBindingMixin. - - host = port_data.get(portbindings.HOST_ID) - host_set = attributes.is_attr_set(host) - with context.session.begin(subtransactions=True): - bind_port = context.session.query( - PortBindingPort).filter_by(port_id=port['id']).first() - if host_set: - if not bind_port: - context.session.add(PortBindingPort(port_id=port['id'], - host=host)) - else: - bind_port.host = host - else: - host = (bind_port and bind_port.host or None) - self._extend_port_dict_binding_host(port, host) - - def get_port_host(self, context, port_id): - with context.session.begin(subtransactions=True): - bind_port = context.session.query( - PortBindingPort).filter_by(port_id=port_id).first() - return bind_port and bind_port.host or None - - def _extend_port_dict_binding_host(self, port_res, host): - super(PortBindingMixin, self).extend_port_dict_binding( - port_res, None) - port_res[portbindings.HOST_ID] = host - - def extend_port_dict_binding(self, port_res, port_db): - host = (port_db.portbinding and port_db.portbinding.host or None) - self._extend_port_dict_binding_host(port_res, host) - - -def _extend_port_dict_binding(plugin, port_res, port_db): - if not isinstance(plugin, PortBindingMixin): - return - plugin.extend_port_dict_binding(port_res, port_db) - - -# Register dict extend functions for ports -db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attributes.PORTS, [_extend_port_dict_binding]) diff --git a/neutron/db/portsecurity_db.py b/neutron/db/portsecurity_db.py deleted file mode 100644 index d01eecd24..000000000 --- a/neutron/db/portsecurity_db.py +++ /dev/null @@ -1,185 +0,0 @@ -# Copyright 2013 VMware, 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. - -import sqlalchemy as sa -from sqlalchemy import orm -from sqlalchemy.orm import exc - -from neutron.api.v2 import attributes as attrs -from neutron.db import db_base_plugin_v2 -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.extensions import portsecurity as psec -from neutron.openstack.common import log as logging - -LOG = logging.getLogger(__name__) - - -class PortSecurityBinding(model_base.BASEV2): - port_id = sa.Column(sa.String(36), - sa.ForeignKey('ports.id', ondelete="CASCADE"), - primary_key=True) - port_security_enabled = sa.Column(sa.Boolean(), nullable=False) - - # Add a relationship to the Port model in order to be to able to - # instruct SQLAlchemy to eagerly load port security binding - port = orm.relationship( - models_v2.Port, - backref=orm.backref("port_security", uselist=False, - cascade='delete', lazy='joined')) - - -class NetworkSecurityBinding(model_base.BASEV2): - network_id = sa.Column(sa.String(36), - sa.ForeignKey('networks.id', ondelete="CASCADE"), - primary_key=True) - port_security_enabled = sa.Column(sa.Boolean(), nullable=False) - - # Add a relationship to the Port model in order to be able to instruct - # SQLAlchemy to eagerly load default port security setting for ports - # on this network - network = orm.relationship( - models_v2.Network, - backref=orm.backref("port_security", uselist=False, - cascade='delete', lazy='joined')) - - -class PortSecurityDbMixin(object): - """Mixin class to add port security.""" - - def _process_network_port_security_create( - self, context, network_req, network_res): - with context.session.begin(subtransactions=True): - db = NetworkSecurityBinding( - network_id=network_res['id'], - port_security_enabled=network_req[psec.PORTSECURITY]) - context.session.add(db) - network_res[psec.PORTSECURITY] = network_req[psec.PORTSECURITY] - return self._make_network_port_security_dict(db) - - def _process_port_port_security_create( - self, context, port_req, port_res): - with context.session.begin(subtransactions=True): - db = PortSecurityBinding( - port_id=port_res['id'], - port_security_enabled=port_req[psec.PORTSECURITY]) - context.session.add(db) - port_res[psec.PORTSECURITY] = port_req[psec.PORTSECURITY] - return self._make_port_security_dict(db) - - def _extend_port_security_dict(self, response_data, db_data): - if ('port-security' in - getattr(self, 'supported_extension_aliases', [])): - psec_value = db_data['port_security'][psec.PORTSECURITY] - response_data[psec.PORTSECURITY] = psec_value - - def _get_network_security_binding(self, context, network_id): - try: - query = self._model_query(context, NetworkSecurityBinding) - binding = query.filter( - NetworkSecurityBinding.network_id == network_id).one() - except exc.NoResultFound: - raise psec.PortSecurityBindingNotFound() - return binding[psec.PORTSECURITY] - - def _get_port_security_binding(self, context, port_id): - try: - query = self._model_query(context, PortSecurityBinding) - binding = query.filter( - PortSecurityBinding.port_id == port_id).one() - except exc.NoResultFound: - raise psec.PortSecurityBindingNotFound() - return binding[psec.PORTSECURITY] - - def _process_port_port_security_update( - self, context, port_req, port_res): - if psec.PORTSECURITY in port_req: - port_security_enabled = port_req[psec.PORTSECURITY] - else: - return - try: - query = self._model_query(context, PortSecurityBinding) - port_id = port_res['id'] - binding = query.filter( - PortSecurityBinding.port_id == port_id).one() - - binding.port_security_enabled = port_security_enabled - port_res[psec.PORTSECURITY] = port_security_enabled - except exc.NoResultFound: - raise psec.PortSecurityBindingNotFound() - - def _process_network_port_security_update( - self, context, network_req, network_res): - if psec.PORTSECURITY in network_req: - port_security_enabled = network_req[psec.PORTSECURITY] - else: - return - try: - query = self._model_query(context, NetworkSecurityBinding) - network_id = network_res['id'] - binding = query.filter( - NetworkSecurityBinding.network_id == network_id).one() - - binding.port_security_enabled = port_security_enabled - network_res[psec.PORTSECURITY] = port_security_enabled - except exc.NoResultFound: - raise psec.PortSecurityBindingNotFound() - - def _make_network_port_security_dict(self, port_security, fields=None): - res = {'network_id': port_security['network_id'], - psec.PORTSECURITY: port_security[psec.PORTSECURITY]} - return self._fields(res, fields) - - def _determine_port_security_and_has_ip(self, context, port): - """Returns a tuple of booleans (port_security_enabled, has_ip). - - Port_security is the value assocated with the port if one is present - otherwise the value associated with the network is returned. has_ip is - if the port is associated with an ip or not. - """ - has_ip = self._ip_on_port(port) - # we don't apply security groups for dhcp, router - if (port.get('device_owner') and - port['device_owner'].startswith('network:')): - return (False, has_ip) - - if (psec.PORTSECURITY in port and - isinstance(port[psec.PORTSECURITY], bool)): - port_security_enabled = port[psec.PORTSECURITY] - - # If port has an ip and security_groups are passed in - # conveniently set port_security_enabled to true this way - # user doesn't also have to pass in port_security_enabled=True - # when creating ports. - elif (has_ip and attrs.is_attr_set('security_groups')): - port_security_enabled = True - else: - port_security_enabled = self._get_network_security_binding( - context, port['network_id']) - - return (port_security_enabled, has_ip) - - def _make_port_security_dict(self, port, fields=None): - res = {'port_id': port['port_id'], - psec.PORTSECURITY: port[psec.PORTSECURITY]} - return self._fields(res, fields) - - def _ip_on_port(self, port): - return bool(port.get('fixed_ips')) - - # Register dict extend functions for ports and networks - db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attrs.NETWORKS, ['_extend_port_security_dict']) - db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attrs.PORTS, ['_extend_port_security_dict']) diff --git a/neutron/db/quota_db.py b/neutron/db/quota_db.py deleted file mode 100644 index dc6a3cf4b..000000000 --- a/neutron/db/quota_db.py +++ /dev/null @@ -1,179 +0,0 @@ -# Copyright 2011 OpenStack Foundation. -# 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. - -import sqlalchemy as sa - -from neutron.common import exceptions -from neutron.db import model_base -from neutron.db import models_v2 - - -class Quota(model_base.BASEV2, models_v2.HasId): - """Represent a single quota override for a tenant. - - If there is no row for a given tenant id and resource, then the - default for the quota class is used. - """ - tenant_id = sa.Column(sa.String(255), index=True) - resource = sa.Column(sa.String(255)) - limit = sa.Column(sa.Integer) - - -class DbQuotaDriver(object): - """Driver to perform necessary checks to enforce quotas and obtain quota - information. - - The default driver utilizes the local database. - """ - - @staticmethod - def get_tenant_quotas(context, resources, tenant_id): - """Given a list of resources, retrieve the quotas for the given - tenant. - - :param context: The request context, for access checks. - :param resources: A dictionary of the registered resource keys. - :param tenant_id: The ID of the tenant to return quotas for. - :return dict: from resource name to dict of name and limit - """ - - # init with defaults - tenant_quota = dict((key, resource.default) - for key, resource in resources.items()) - - # update with tenant specific limits - q_qry = context.session.query(Quota).filter_by(tenant_id=tenant_id) - tenant_quota.update((q['resource'], q['limit']) for q in q_qry) - - return tenant_quota - - @staticmethod - def delete_tenant_quota(context, tenant_id): - """Delete the quota entries for a given tenant_id. - - Atfer deletion, this tenant will use default quota values in conf. - """ - with context.session.begin(): - tenant_quotas = context.session.query(Quota) - tenant_quotas = tenant_quotas.filter_by(tenant_id=tenant_id) - tenant_quotas.delete() - - @staticmethod - def get_all_quotas(context, resources): - """Given a list of resources, retrieve the quotas for the all tenants. - - :param context: The request context, for access checks. - :param resources: A dictionary of the registered resource keys. - :return quotas: list of dict of tenant_id:, resourcekey1: - resourcekey2: ... - """ - tenant_default = dict((key, resource.default) - for key, resource in resources.items()) - - all_tenant_quotas = {} - - for quota in context.session.query(Quota): - tenant_id = quota['tenant_id'] - - # avoid setdefault() because only want to copy when actually req'd - tenant_quota = all_tenant_quotas.get(tenant_id) - if tenant_quota is None: - tenant_quota = tenant_default.copy() - tenant_quota['tenant_id'] = tenant_id - all_tenant_quotas[tenant_id] = tenant_quota - - tenant_quota[quota['resource']] = quota['limit'] - - return all_tenant_quotas.values() - - @staticmethod - def update_quota_limit(context, tenant_id, resource, limit): - with context.session.begin(): - tenant_quota = context.session.query(Quota).filter_by( - tenant_id=tenant_id, resource=resource).first() - - if tenant_quota: - tenant_quota.update({'limit': limit}) - else: - tenant_quota = Quota(tenant_id=tenant_id, - resource=resource, - limit=limit) - context.session.add(tenant_quota) - - def _get_quotas(self, context, tenant_id, resources, keys): - """Retrieves the quotas for specific resources. - - A helper method which retrieves the quotas for the specific - resources identified by keys, and which apply to the current - context. - - :param context: The request context, for access checks. - :param tenant_id: the tenant_id to check quota. - :param resources: A dictionary of the registered resources. - :param keys: A list of the desired quotas to retrieve. - - """ - desired = set(keys) - sub_resources = dict((k, v) for k, v in resources.items() - if k in desired) - - # Make sure we accounted for all of them... - if len(keys) != len(sub_resources): - unknown = desired - set(sub_resources.keys()) - raise exceptions.QuotaResourceUnknown(unknown=sorted(unknown)) - - # Grab and return the quotas (without usages) - quotas = DbQuotaDriver.get_tenant_quotas( - context, sub_resources, tenant_id) - - return dict((k, v) for k, v in quotas.items()) - - def limit_check(self, context, tenant_id, resources, values): - """Check simple quota limits. - - For limits--those quotas for which there is no usage - synchronization function--this method checks that a set of - proposed values are permitted by the limit restriction. - - This method will raise a QuotaResourceUnknown exception if a - given resource is unknown or if it is not a simple limit - resource. - - If any of the proposed values is over the defined quota, an - OverQuota exception will be raised with the sorted list of the - resources which are too high. Otherwise, the method returns - nothing. - - :param context: The request context, for access checks. - :param tenant_id: The tenant_id to check the quota. - :param resources: A dictionary of the registered resources. - :param values: A dictionary of the values to check against the - quota. - """ - - # Ensure no value is less than zero - unders = [key for key, val in values.items() if val < 0] - if unders: - raise exceptions.InvalidQuotaValue(unders=sorted(unders)) - - # Get the applicable quotas - quotas = self._get_quotas(context, tenant_id, resources, values.keys()) - - # Check the quotas and construct a list of the resources that - # would be put over limit by the desired values - overs = [key for key, val in values.items() - if quotas[key] >= 0 and quotas[key] < val] - if overs: - raise exceptions.OverQuota(overs=sorted(overs)) diff --git a/neutron/db/routedserviceinsertion_db.py b/neutron/db/routedserviceinsertion_db.py deleted file mode 100644 index 25b87ca42..000000000 --- a/neutron/db/routedserviceinsertion_db.py +++ /dev/null @@ -1,106 +0,0 @@ -# Copyright 2013 VMware, 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: Kaiwei Fan, VMware, Inc - -import sqlalchemy as sa -from sqlalchemy import event - -from neutron.common import exceptions as qexception -from neutron.db import model_base -from neutron.extensions import routedserviceinsertion as rsi - - -class ServiceRouterBinding(model_base.BASEV2): - resource_id = sa.Column(sa.String(36), - primary_key=True) - resource_type = sa.Column(sa.String(36), - primary_key=True) - router_id = sa.Column(sa.String(36), - sa.ForeignKey('routers.id'), - nullable=False) - - -class AttributeException(qexception.NeutronException): - message = _("Resource type '%(resource_type)s' is longer " - "than %(maxlen)d characters") - - -@event.listens_for(ServiceRouterBinding.resource_type, 'set', retval=True) -def validate_resource_type(target, value, oldvalue, initiator): - """Make sure the resource type fit the resource_type column.""" - maxlen = ServiceRouterBinding.resource_type.property.columns[0].type.length - if len(value) > maxlen: - raise AttributeException(resource_type=value, maxlen=maxlen) - return value - - -class RoutedServiceInsertionDbMixin(object): - """Mixin class to add router service insertion.""" - - def _process_create_resource_router_id(self, context, resource, model): - with context.session.begin(subtransactions=True): - db = ServiceRouterBinding( - resource_id=resource['id'], - resource_type=model.__tablename__, - router_id=resource[rsi.ROUTER_ID]) - context.session.add(db) - return self._make_resource_router_id_dict(db, model) - - def _extend_resource_router_id_dict(self, context, resource, model): - binding = self._get_resource_router_id_binding( - context, resource['resource_id'], model) - resource[rsi.ROUTER_ID] = binding['router_id'] - - def _get_resource_router_id_binding(self, context, model, - resource_id=None, - router_id=None): - query = self._model_query(context, ServiceRouterBinding) - query = query.filter( - ServiceRouterBinding.resource_type == model.__tablename__) - if resource_id: - query = query.filter( - ServiceRouterBinding.resource_id == resource_id) - if router_id: - query = query.filter( - ServiceRouterBinding.router_id == router_id) - return query.first() - - def _get_resource_router_id_bindings(self, context, model, - resource_ids=None, - router_ids=None): - query = self._model_query(context, ServiceRouterBinding) - query = query.filter( - ServiceRouterBinding.resource_type == model.__tablename__) - if resource_ids: - query = query.filter( - ServiceRouterBinding.resource_id.in_(resource_ids)) - if router_ids: - query = query.filter( - ServiceRouterBinding.router_id.in_(router_ids)) - return query.all() - - def _make_resource_router_id_dict(self, resource_router_binding, model, - fields=None): - resource = {'resource_id': resource_router_binding['resource_id'], - 'resource_type': model.__tablename__, - rsi.ROUTER_ID: resource_router_binding[rsi.ROUTER_ID]} - return self._fields(resource, fields) - - def _delete_resource_router_id_binding(self, context, resource_id, model): - with context.session.begin(subtransactions=True): - binding = self._get_resource_router_id_binding( - context, model, resource_id=resource_id) - if binding: - context.session.delete(binding) diff --git a/neutron/db/routerservicetype_db.py b/neutron/db/routerservicetype_db.py deleted file mode 100644 index 9037a0bb4..000000000 --- a/neutron/db/routerservicetype_db.py +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright 2013 VMware, 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: Kaiwei Fan, VMware, Inc - -import sqlalchemy as sa - -from neutron.db import model_base -from neutron.extensions import routerservicetype as rst - - -class RouterServiceTypeBinding(model_base.BASEV2): - router_id = sa.Column(sa.String(36), - sa.ForeignKey('routers.id', ondelete="CASCADE"), - primary_key=True) - service_type_id = sa.Column(sa.String(36), - nullable=False) - - -class RouterServiceTypeDbMixin(object): - """Mixin class to add router service type.""" - - def _process_create_router_service_type_id(self, context, router): - with context.session.begin(subtransactions=True): - db = RouterServiceTypeBinding( - router_id=router['id'], - service_type_id=router[rst.SERVICE_TYPE_ID]) - context.session.add(db) - return self._make_router_service_type_id_dict(db) - - def _extend_router_service_type_id_dict(self, context, router): - rsbind = self._get_router_service_type_id_binding( - context, router['id']) - if rsbind: - router[rst.SERVICE_TYPE_ID] = rsbind['service_type_id'] - - def _get_router_service_type_id_binding(self, context, router_id): - query = self._model_query(context, RouterServiceTypeBinding) - query = query.filter( - RouterServiceTypeBinding.router_id == router_id) - return query.first() - - def _make_router_service_type_id_dict(self, router_service_type): - res = {'router_id': router_service_type['router_id'], - 'service_type_id': router_service_type[rst.SERVICE_TYPE_ID]} - return self._fields(res, None) diff --git a/neutron/db/securitygroups_db.py b/neutron/db/securitygroups_db.py deleted file mode 100644 index c897071b3..000000000 --- a/neutron/db/securitygroups_db.py +++ /dev/null @@ -1,564 +0,0 @@ -# Copyright 2012 VMware, 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. - -import netaddr -import sqlalchemy as sa -from sqlalchemy import orm -from sqlalchemy.orm import exc -from sqlalchemy.orm import scoped_session - -from neutron.api.v2 import attributes as attr -from neutron.common import constants -from neutron.db import db_base_plugin_v2 -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.extensions import securitygroup as ext_sg -from neutron.openstack.common import uuidutils - - -IP_PROTOCOL_MAP = {constants.PROTO_NAME_TCP: constants.PROTO_NUM_TCP, - constants.PROTO_NAME_UDP: constants.PROTO_NUM_UDP, - constants.PROTO_NAME_ICMP: constants.PROTO_NUM_ICMP, - constants.PROTO_NAME_ICMP_V6: constants.PROTO_NUM_ICMP_V6} - - -class SecurityGroup(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): - """Represents a v2 neutron security group.""" - - name = sa.Column(sa.String(255)) - description = sa.Column(sa.String(255)) - - -class SecurityGroupPortBinding(model_base.BASEV2): - """Represents binding between neutron ports and security profiles.""" - - port_id = sa.Column(sa.String(36), - sa.ForeignKey("ports.id", - ondelete='CASCADE'), - primary_key=True) - security_group_id = sa.Column(sa.String(36), - sa.ForeignKey("securitygroups.id"), - primary_key=True) - - # Add a relationship to the Port model in order to instruct SQLAlchemy to - # eagerly load security group bindings - ports = orm.relationship( - models_v2.Port, - backref=orm.backref("security_groups", - lazy='joined', cascade='delete')) - - -class SecurityGroupRule(model_base.BASEV2, models_v2.HasId, - models_v2.HasTenant): - """Represents a v2 neutron security group rule.""" - - security_group_id = sa.Column(sa.String(36), - sa.ForeignKey("securitygroups.id", - ondelete="CASCADE"), - nullable=False) - - remote_group_id = sa.Column(sa.String(36), - sa.ForeignKey("securitygroups.id", - ondelete="CASCADE"), - nullable=True) - - direction = sa.Column(sa.Enum('ingress', 'egress', - name='securitygrouprules_direction')) - ethertype = sa.Column(sa.String(40)) - protocol = sa.Column(sa.String(40)) - port_range_min = sa.Column(sa.Integer) - port_range_max = sa.Column(sa.Integer) - remote_ip_prefix = sa.Column(sa.String(255)) - security_group = orm.relationship( - SecurityGroup, - backref=orm.backref('rules', cascade='all,delete'), - primaryjoin="SecurityGroup.id==SecurityGroupRule.security_group_id") - source_group = orm.relationship( - SecurityGroup, - backref=orm.backref('source_rules', cascade='all,delete'), - primaryjoin="SecurityGroup.id==SecurityGroupRule.remote_group_id") - - -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 create_security_group(self, context, security_group, default_sg=False): - """Create security group. - - If default_sg is true that means we are a default security group for - a given tenant if it does not exist. - """ - s = security_group['security_group'] - tenant_id = self._get_tenant_id_for_create(context, s) - - if not default_sg: - self._ensure_default_security_group(context, tenant_id) - - with context.session.begin(subtransactions=True): - security_group_db = SecurityGroup(id=s.get('id') or ( - uuidutils.generate_uuid()), - description=s['description'], - tenant_id=tenant_id, - name=s['name']) - context.session.add(security_group_db) - for ethertype in ext_sg.sg_supported_ethertypes: - if s.get('name') == 'default': - # Allow intercommunication - ingress_rule = SecurityGroupRule( - id=uuidutils.generate_uuid(), tenant_id=tenant_id, - security_group=security_group_db, - direction='ingress', - ethertype=ethertype, - source_group=security_group_db) - context.session.add(ingress_rule) - - egress_rule = SecurityGroupRule( - id=uuidutils.generate_uuid(), tenant_id=tenant_id, - security_group=security_group_db, - direction='egress', - ethertype=ethertype) - context.session.add(egress_rule) - - return self._make_security_group_dict(security_group_db) - - def get_security_groups(self, context, filters=None, fields=None, - sorts=None, limit=None, - marker=None, page_reverse=False, default_sg=False): - - # If default_sg is True do not call _ensure_default_security_group() - # so this can be done recursively. Context.tenant_id is checked - # because all the unit tests do not explicitly set the context on - # GETS. TODO(arosen) context handling can probably be improved here. - if not default_sg and context.tenant_id: - self._ensure_default_security_group(context, context.tenant_id) - marker_obj = self._get_marker_obj(context, 'security_group', limit, - marker) - return self._get_collection(context, - SecurityGroup, - self._make_security_group_dict, - filters=filters, fields=fields, - sorts=sorts, - limit=limit, marker_obj=marker_obj, - page_reverse=page_reverse) - - def get_security_groups_count(self, context, filters=None): - return self._get_collection_count(context, SecurityGroup, - filters=filters) - - def get_security_group(self, context, id, fields=None, tenant_id=None): - """Tenant id is given to handle the case when creating a security - group rule on behalf of another use. - """ - - if tenant_id: - tmp_context_tenant_id = context.tenant_id - context.tenant_id = tenant_id - - try: - with context.session.begin(subtransactions=True): - ret = self._make_security_group_dict(self._get_security_group( - context, id), fields) - ret['security_group_rules'] = self.get_security_group_rules( - context, {'security_group_id': [id]}) - finally: - if tenant_id: - context.tenant_id = tmp_context_tenant_id - return ret - - def _get_security_group(self, context, id): - try: - query = self._model_query(context, SecurityGroup) - sg = query.filter(SecurityGroup.id == id).one() - - except exc.NoResultFound: - raise ext_sg.SecurityGroupNotFound(id=id) - return sg - - def delete_security_group(self, context, id): - filters = {'security_group_id': [id]} - ports = self._get_port_security_group_bindings(context, filters) - if ports: - raise ext_sg.SecurityGroupInUse(id=id) - # confirm security group exists - sg = self._get_security_group(context, id) - - if sg['name'] == 'default' and not context.is_admin: - raise ext_sg.SecurityGroupCannotRemoveDefault() - with context.session.begin(subtransactions=True): - context.session.delete(sg) - - def update_security_group(self, context, id, security_group): - s = security_group['security_group'] - with context.session.begin(subtransactions=True): - sg = self._get_security_group(context, id) - if sg['name'] == 'default' and 'name' in s: - raise ext_sg.SecurityGroupCannotUpdateDefault() - sg.update(s) - return self._make_security_group_dict(sg) - - def _make_security_group_dict(self, security_group, fields=None): - res = {'id': security_group['id'], - 'name': security_group['name'], - 'tenant_id': security_group['tenant_id'], - 'description': security_group['description']} - res['security_group_rules'] = [self._make_security_group_rule_dict(r) - for r in security_group.rules] - return self._fields(res, fields) - - def _make_security_group_binding_dict(self, security_group, fields=None): - res = {'port_id': security_group['port_id'], - 'security_group_id': security_group['security_group_id']} - return self._fields(res, fields) - - def _create_port_security_group_binding(self, context, port_id, - security_group_id): - with context.session.begin(subtransactions=True): - db = SecurityGroupPortBinding(port_id=port_id, - security_group_id=security_group_id) - context.session.add(db) - - def _get_port_security_group_bindings(self, context, - filters=None, fields=None): - return self._get_collection(context, - SecurityGroupPortBinding, - self._make_security_group_binding_dict, - filters=filters, fields=fields) - - def _delete_port_security_group_bindings(self, context, port_id): - query = self._model_query(context, SecurityGroupPortBinding) - bindings = query.filter( - SecurityGroupPortBinding.port_id == port_id) - with context.session.begin(subtransactions=True): - for binding in bindings: - context.session.delete(binding) - - def create_security_group_rule_bulk(self, context, security_group_rule): - return self._create_bulk('security_group_rule', context, - security_group_rule) - - def create_security_group_rule_bulk_native(self, context, - security_group_rule): - r = security_group_rule['security_group_rules'] - - scoped_session(context.session) - security_group_id = self._validate_security_group_rules( - context, security_group_rule) - with context.session.begin(subtransactions=True): - if not self.get_security_group(context, security_group_id): - raise ext_sg.SecurityGroupNotFound(id=security_group_id) - - self._check_for_duplicate_rules(context, r) - ret = [] - for rule_dict in r: - rule = rule_dict['security_group_rule'] - tenant_id = self._get_tenant_id_for_create(context, rule) - db = SecurityGroupRule( - id=uuidutils.generate_uuid(), tenant_id=tenant_id, - security_group_id=rule['security_group_id'], - direction=rule['direction'], - remote_group_id=rule.get('remote_group_id'), - ethertype=rule['ethertype'], - protocol=rule['protocol'], - port_range_min=rule['port_range_min'], - port_range_max=rule['port_range_max'], - remote_ip_prefix=rule.get('remote_ip_prefix')) - context.session.add(db) - ret.append(self._make_security_group_rule_dict(db)) - return ret - - def create_security_group_rule(self, context, security_group_rule): - bulk_rule = {'security_group_rules': [security_group_rule]} - return self.create_security_group_rule_bulk_native(context, - bulk_rule)[0] - - def _get_ip_proto_number(self, protocol): - if protocol is None: - return - return IP_PROTOCOL_MAP.get(protocol, protocol) - - def _validate_port_range(self, rule): - """Check that port_range is valid.""" - if (rule['port_range_min'] is None and - rule['port_range_max'] is None): - return - if not rule['protocol']: - raise ext_sg.SecurityGroupProtocolRequiredWithPorts() - ip_proto = self._get_ip_proto_number(rule['protocol']) - if ip_proto in [constants.PROTO_NUM_TCP, constants.PROTO_NUM_UDP]: - if (rule['port_range_min'] is not None and - rule['port_range_min'] <= rule['port_range_max']): - pass - else: - raise ext_sg.SecurityGroupInvalidPortRange() - elif ip_proto == constants.PROTO_NUM_ICMP: - for attr, field in [('port_range_min', 'type'), - ('port_range_max', 'code')]: - if rule[attr] > 255: - raise ext_sg.SecurityGroupInvalidIcmpValue( - field=field, attr=attr, value=rule[attr]) - if (rule['port_range_min'] is None and - rule['port_range_max']): - raise ext_sg.SecurityGroupMissingIcmpType( - value=rule['port_range_max']) - - def _validate_security_group_rules(self, context, security_group_rule): - """Check that rules being installed. - - Check that all rules belong to the same security - group, remote_group_id/security_group_id belong to the same tenant, - and rules are valid. - """ - new_rules = set() - tenant_ids = set() - for rules in security_group_rule['security_group_rules']: - rule = rules.get('security_group_rule') - new_rules.add(rule['security_group_id']) - - self._validate_port_range(rule) - self._validate_ip_prefix(rule) - - if rule['remote_ip_prefix'] and rule['remote_group_id']: - raise ext_sg.SecurityGroupRemoteGroupAndRemoteIpPrefix() - - if rule['tenant_id'] not in tenant_ids: - tenant_ids.add(rule['tenant_id']) - remote_group_id = rule.get('remote_group_id') - # Check that remote_group_id exists for tenant - if remote_group_id: - self.get_security_group(context, remote_group_id, - tenant_id=rule['tenant_id']) - if len(new_rules) > 1: - raise ext_sg.SecurityGroupNotSingleGroupRules() - security_group_id = new_rules.pop() - - # Confirm single tenant and that the tenant has permission - # to add rules to this security group. - if len(tenant_ids) > 1: - raise ext_sg.SecurityGroupRulesNotSingleTenant() - for tenant_id in tenant_ids: - self.get_security_group(context, security_group_id, - tenant_id=tenant_id) - return security_group_id - - def _make_security_group_rule_dict(self, security_group_rule, fields=None): - res = {'id': security_group_rule['id'], - 'tenant_id': security_group_rule['tenant_id'], - 'security_group_id': security_group_rule['security_group_id'], - 'ethertype': security_group_rule['ethertype'], - 'direction': security_group_rule['direction'], - 'protocol': security_group_rule['protocol'], - 'port_range_min': security_group_rule['port_range_min'], - 'port_range_max': security_group_rule['port_range_max'], - 'remote_ip_prefix': security_group_rule['remote_ip_prefix'], - 'remote_group_id': security_group_rule['remote_group_id']} - - return self._fields(res, fields) - - def _make_security_group_rule_filter_dict(self, security_group_rule): - sgr = security_group_rule['security_group_rule'] - res = {'tenant_id': [sgr['tenant_id']], - 'security_group_id': [sgr['security_group_id']], - 'direction': [sgr['direction']]} - - include_if_present = ['protocol', 'port_range_max', 'port_range_min', - 'ethertype', 'remote_ip_prefix', - 'remote_group_id'] - for key in include_if_present: - value = sgr.get(key) - if value: - res[key] = [value] - return res - - def _check_for_duplicate_rules(self, context, security_group_rules): - for i in security_group_rules: - found_self = False - for j in security_group_rules: - if i['security_group_rule'] == j['security_group_rule']: - if found_self: - raise ext_sg.DuplicateSecurityGroupRuleInPost(rule=i) - found_self = True - - # Check in database if rule exists - filters = self._make_security_group_rule_filter_dict(i) - db_rules = self.get_security_group_rules(context, filters) - # Note(arosen): the call to get_security_group_rules wildcards - # values in the filter that have a value of [None]. For - # example, filters = {'remote_group_id': [None]} will return - # all security group rules regardless of their value of - # remote_group_id. Therefore it is not possible to do this - # query unless the behavior of _get_collection() - # is changed which cannot be because other methods are already - # relying on this behavor. Therefore, we do the filtering - # below to check for these corner cases. - for db_rule in db_rules: - # need to remove id from db_rule for matching - id = db_rule.pop('id') - if (i['security_group_rule'] == db_rule): - raise ext_sg.SecurityGroupRuleExists(id=id) - - def _validate_ip_prefix(self, rule): - """Check that a valid cidr was specified as remote_ip_prefix - - No need to check that it is in fact an IP address as this is already - validated by attribute validators. - Check that rule ethertype is consistent with remote_ip_prefix ip type. - Add mask to ip_prefix if absent (192.168.1.10 -> 192.168.1.10/32). - """ - input_prefix = rule['remote_ip_prefix'] - if input_prefix: - addr = netaddr.IPNetwork(input_prefix) - # set input_prefix to always include the netmask: - rule['remote_ip_prefix'] = str(addr) - # check consistency of ethertype with addr version - if rule['ethertype'] != "IPv%d" % (addr.version): - raise ext_sg.SecurityGroupRuleParameterConflict( - ethertype=rule['ethertype'], cidr=input_prefix) - - def get_security_group_rules(self, context, filters=None, fields=None, - sorts=None, limit=None, marker=None, - page_reverse=False): - marker_obj = self._get_marker_obj(context, 'security_group_rule', - limit, marker) - return self._get_collection(context, - SecurityGroupRule, - self._make_security_group_rule_dict, - filters=filters, fields=fields, - sorts=sorts, - limit=limit, marker_obj=marker_obj, - page_reverse=page_reverse) - - def get_security_group_rules_count(self, context, filters=None): - return self._get_collection_count(context, SecurityGroupRule, - filters=filters) - - def get_security_group_rule(self, context, id, fields=None): - security_group_rule = self._get_security_group_rule(context, id) - return self._make_security_group_rule_dict(security_group_rule, fields) - - def _get_security_group_rule(self, context, id): - try: - query = self._model_query(context, SecurityGroupRule) - sgr = query.filter(SecurityGroupRule.id == id).one() - except exc.NoResultFound: - raise ext_sg.SecurityGroupRuleNotFound(id=id) - return sgr - - def delete_security_group_rule(self, context, id): - with context.session.begin(subtransactions=True): - rule = self._get_security_group_rule(context, id) - context.session.delete(rule) - - def _extend_port_dict_security_group(self, port_res, port_db): - # Security group bindings will be retrieved from the sqlalchemy - # model. As they're loaded eagerly with ports because of the - # joined load they will not cause an extra query. - security_group_ids = [sec_group_mapping['security_group_id'] for - sec_group_mapping in port_db.security_groups] - port_res[ext_sg.SECURITYGROUPS] = security_group_ids - return port_res - - # Register dict extend functions for ports - db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attr.PORTS, ['_extend_port_dict_security_group']) - - def _process_port_create_security_group(self, context, port, - security_group_ids): - if attr.is_attr_set(security_group_ids): - for security_group_id in security_group_ids: - self._create_port_security_group_binding(context, port['id'], - security_group_id) - # Convert to list as a set might be passed here and - # this has to be serialized - port[ext_sg.SECURITYGROUPS] = (security_group_ids and - list(security_group_ids) or []) - - def _ensure_default_security_group(self, context, tenant_id): - """Create a default security group if one doesn't exist. - - :returns: the default security group id. - """ - filters = {'name': ['default'], 'tenant_id': [tenant_id]} - default_group = self.get_security_groups(context, filters, - default_sg=True) - if not default_group: - security_group = {'security_group': {'name': 'default', - 'tenant_id': tenant_id, - 'description': 'default'}} - ret = self.create_security_group(context, security_group, True) - return ret['id'] - else: - return default_group[0]['id'] - - def _get_security_groups_on_port(self, context, port): - """Check that all security groups on port belong to tenant. - - :returns: all security groups IDs on port belonging to tenant. - """ - p = port['port'] - if not attr.is_attr_set(p.get(ext_sg.SECURITYGROUPS)): - return - if p.get('device_owner') and p['device_owner'].startswith('network:'): - return - - port_sg = p.get(ext_sg.SECURITYGROUPS, []) - valid_groups = set(g['id'] for g in - self.get_security_groups(context, fields=['id'], - filters={'id': port_sg})) - - requested_groups = set(port_sg) - port_sg_missing = requested_groups - valid_groups - if port_sg_missing: - raise ext_sg.SecurityGroupNotFound(id=str(port_sg_missing[0])) - - return requested_groups - - def _ensure_default_security_group_on_port(self, context, port): - # we don't apply security groups for dhcp, router - if (port['port'].get('device_owner') and - port['port']['device_owner'].startswith('network:')): - return - tenant_id = self._get_tenant_id_for_create(context, - port['port']) - default_sg = self._ensure_default_security_group(context, tenant_id) - if attr.is_attr_set(port['port'].get(ext_sg.SECURITYGROUPS)): - sgids = port['port'].get(ext_sg.SECURITYGROUPS) - else: - sgids = [default_sg] - port['port'][ext_sg.SECURITYGROUPS] = sgids - - def _check_update_deletes_security_groups(self, port): - """Return True if port has as a security group and it's value - is either [] or not is_attr_set, otherwise return False - """ - if (ext_sg.SECURITYGROUPS in port['port'] and - not (attr.is_attr_set(port['port'][ext_sg.SECURITYGROUPS]) - and port['port'][ext_sg.SECURITYGROUPS] != [])): - return True - return False - - def _check_update_has_security_groups(self, port): - """Return True if port has as a security group and False if the - security_group field is is_attr_set or []. - """ - if (ext_sg.SECURITYGROUPS in port['port'] and - (attr.is_attr_set(port['port'][ext_sg.SECURITYGROUPS]) and - port['port'][ext_sg.SECURITYGROUPS] != [])): - return True - return False diff --git a/neutron/db/securitygroups_rpc_base.py b/neutron/db/securitygroups_rpc_base.py deleted file mode 100644 index b9db8b394..000000000 --- a/neutron/db/securitygroups_rpc_base.py +++ /dev/null @@ -1,374 +0,0 @@ -# Copyright 2012, Nachi Ueno, NTT MCL, 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. - -import netaddr -from sqlalchemy.orm import exc - -from neutron.common import constants as q_const -from neutron.common import ipv6_utils as ipv6 -from neutron.common import utils -from neutron.db import models_v2 -from neutron.db import securitygroups_db as sg_db -from neutron.extensions import securitygroup as ext_sg -from neutron.openstack.common import log as logging - -LOG = logging.getLogger(__name__) - - -IP_MASK = {q_const.IPv4: 32, - q_const.IPv6: 128} - - -DIRECTION_IP_PREFIX = {'ingress': 'source_ip_prefix', - 'egress': 'dest_ip_prefix'} - - -class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin): - - def create_security_group_rule(self, context, security_group_rule): - bulk_rule = {'security_group_rules': [security_group_rule]} - rule = self.create_security_group_rule_bulk_native(context, - bulk_rule)[0] - sgids = [rule['security_group_id']] - self.notifier.security_groups_rule_updated(context, sgids) - return rule - - def create_security_group_rule_bulk(self, context, - security_group_rule): - rules = super(SecurityGroupServerRpcMixin, - self).create_security_group_rule_bulk_native( - context, security_group_rule) - sgids = set([r['security_group_id'] for r in rules]) - self.notifier.security_groups_rule_updated(context, list(sgids)) - return rules - - def delete_security_group_rule(self, context, sgrid): - rule = self.get_security_group_rule(context, sgrid) - super(SecurityGroupServerRpcMixin, - self).delete_security_group_rule(context, sgrid) - self.notifier.security_groups_rule_updated(context, - [rule['security_group_id']]) - - 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 utils.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 - - def is_security_group_member_updated(self, context, - original_port, updated_port): - """Check security group member updated or not. - - 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 - if (original_port['fixed_ips'] != updated_port['fixed_ips'] or - not utils.compare_elements( - original_port.get(ext_sg.SECURITYGROUPS), - updated_port.get(ext_sg.SECURITYGROUPS))): - need_notify = True - return need_notify - - def notify_security_groups_member_updated(self, context, port): - """Notify update event of security group members. - - The agent setups the iptables rule to allow - ingress packet from the dhcp server (as a part of provider rules), - so we need to notify an update of dhcp server ip - address to the plugin agent. - security_groups_provider_updated() just notifies that an event - occurs and the plugin agent fetches the update provider - rule in the other RPC call (security_group_rules_for_devices). - """ - if port['device_owner'] == q_const.DEVICE_OWNER_DHCP: - self.notifier.security_groups_provider_updated(context) - else: - self.notifier.security_groups_member_updated( - context, port.get(ext_sg.SECURITYGROUPS)) - - -class SecurityGroupServerRpcCallbackMixin(object): - """A mix-in that enable SecurityGroup agent support in plugin - implementations. - """ - - def security_group_rules_for_devices(self, context, **kwargs): - """Return security group rules for each port. - - also convert remote_group_id rule - to source_ip_prefix and dest_ip_prefix rule - - :params devices: list of devices - :returns: port correspond to the devices with security group rules - """ - devices = kwargs.get('devices') - - ports = {} - for device in devices: - port = self.get_port_from_device(device) - if not port: - continue - if port['device_owner'].startswith('network:'): - continue - ports[port['id']] = port - return self._security_group_rules_for_ports(context, ports) - - def _select_rules_for_ports(self, context, ports): - if not ports: - return [] - sg_binding_port = sg_db.SecurityGroupPortBinding.port_id - sg_binding_sgid = sg_db.SecurityGroupPortBinding.security_group_id - - sgr_sgid = sg_db.SecurityGroupRule.security_group_id - - query = context.session.query(sg_db.SecurityGroupPortBinding, - sg_db.SecurityGroupRule) - query = query.join(sg_db.SecurityGroupRule, - sgr_sgid == sg_binding_sgid) - query = query.filter(sg_binding_port.in_(ports.keys())) - return query.all() - - def _select_ips_for_remote_group(self, context, remote_group_ids): - ips_by_group = {} - if not remote_group_ids: - return ips_by_group - for remote_group_id in remote_group_ids: - ips_by_group[remote_group_id] = [] - - ip_port = models_v2.IPAllocation.port_id - sg_binding_port = sg_db.SecurityGroupPortBinding.port_id - sg_binding_sgid = sg_db.SecurityGroupPortBinding.security_group_id - - query = context.session.query(sg_binding_sgid, - models_v2.Port, - models_v2.IPAllocation.ip_address) - query = query.join(models_v2.IPAllocation, - ip_port == sg_binding_port) - query = query.join(models_v2.Port, - ip_port == models_v2.Port.id) - query = query.filter(sg_binding_sgid.in_(remote_group_ids)) - for security_group_id, port, ip_address in query: - ips_by_group[security_group_id].append(ip_address) - # if there are allowed_address_pairs add them - if getattr(port, 'allowed_address_pairs', None): - for address_pair in port.allowed_address_pairs: - ips_by_group[security_group_id].append( - address_pair['ip_address']) - return ips_by_group - - def _select_remote_group_ids(self, ports): - remote_group_ids = [] - for port in ports.values(): - for rule in port.get('security_group_rules'): - remote_group_id = rule.get('remote_group_id') - if remote_group_id: - remote_group_ids.append(remote_group_id) - return remote_group_ids - - def _select_network_ids(self, ports): - return set((port['network_id'] for port in ports.values())) - - def _select_dhcp_ips_for_network_ids(self, context, network_ids): - if not network_ids: - return {} - query = context.session.query(models_v2.Port, - models_v2.IPAllocation.ip_address) - query = query.join(models_v2.IPAllocation) - query = query.filter(models_v2.Port.network_id.in_(network_ids)) - owner = q_const.DEVICE_OWNER_DHCP - query = query.filter(models_v2.Port.device_owner == owner) - ips = {} - - for network_id in network_ids: - ips[network_id] = [] - - for port, ip in query: - ips[port['network_id']].append(ip) - return ips - - def _select_ra_ips_for_network_ids(self, context, network_ids): - """Select IP addresses to allow sending router advertisement from. - - If OpenStack dnsmasq sends RA, get link local address of - gateway and allow RA from this Link Local address. - The gateway port link local address will only be obtained - when router is created before VM instance is booted and - subnet is attached to router. - - If OpenStack doesn't send RA, allow RA from gateway IP. - Currently, the gateway IP needs to be link local to be able - to send RA to VM. - """ - if not network_ids: - return {} - ips = {} - for network_id in network_ids: - ips[network_id] = set([]) - query = context.session.query(models_v2.Subnet) - subnets = query.filter(models_v2.Subnet.network_id.in_(network_ids)) - for subnet in subnets: - gateway_ip = subnet['gateway_ip'] - if subnet['ip_version'] != 6 or not gateway_ip: - continue - # TODO(xuhanp): Figure out how to call the following code - # each time router is created or updated. - if not netaddr.IPAddress(gateway_ip).is_link_local(): - if subnet['ipv6_ra_mode']: - gateway_ip = self._get_lla_gateway_ip_for_subnet(context, - subnet) - else: - # TODO(xuhanp):Figure out how to allow gateway IP from - # existing device to be global address and figure out the - # link local address by other method. - continue - if gateway_ip: - ips[subnet['network_id']].add(gateway_ip) - - return ips - - def _get_lla_gateway_ip_for_subnet(self, context, subnet): - query = context.session.query(models_v2.Port) - query = query.join(models_v2.IPAllocation) - query = query.filter( - models_v2.IPAllocation.subnet_id == subnet['id']) - query = query.filter( - models_v2.IPAllocation.ip_address == subnet['gateway_ip']) - query = query.filter(models_v2.Port.device_owner == - q_const.DEVICE_OWNER_ROUTER_INTF) - try: - gateway_port = query.one() - except (exc.NoResultFound, exc.MultipleResultsFound): - LOG.warn(_('No valid gateway port on subnet %s is ' - 'found for IPv6 RA'), subnet['id']) - return - mac_address = gateway_port['mac_address'] - lla_ip = str(ipv6.get_ipv6_addr_by_EUI64( - q_const.IPV6_LLA_PREFIX, - mac_address)) - return lla_ip - - def _convert_remote_group_id_to_ip_prefix(self, context, ports): - remote_group_ids = self._select_remote_group_ids(ports) - ips = self._select_ips_for_remote_group(context, remote_group_ids) - for port in ports.values(): - updated_rule = [] - for rule in port.get('security_group_rules'): - remote_group_id = rule.get('remote_group_id') - direction = rule.get('direction') - direction_ip_prefix = DIRECTION_IP_PREFIX[direction] - if not remote_group_id: - updated_rule.append(rule) - continue - - port['security_group_source_groups'].append(remote_group_id) - base_rule = rule - for ip in ips[remote_group_id]: - if ip in port.get('fixed_ips', []): - continue - ip_rule = base_rule.copy() - version = netaddr.IPNetwork(ip).version - ethertype = 'IPv%s' % version - if base_rule['ethertype'] != ethertype: - continue - ip_rule[direction_ip_prefix] = str( - netaddr.IPNetwork(ip).cidr) - updated_rule.append(ip_rule) - port['security_group_rules'] = updated_rule - return ports - - def _add_ingress_dhcp_rule(self, port, ips): - dhcp_ips = ips.get(port['network_id']) - for dhcp_ip in dhcp_ips: - if not netaddr.IPAddress(dhcp_ip).version == 4: - return - - dhcp_rule = {'direction': 'ingress', - 'ethertype': q_const.IPv4, - 'protocol': 'udp', - 'port_range_min': 68, - 'port_range_max': 68, - 'source_port_range_min': 67, - 'source_port_range_max': 67} - dhcp_rule['source_ip_prefix'] = "%s/%s" % (dhcp_ip, - IP_MASK[q_const.IPv4]) - port['security_group_rules'].append(dhcp_rule) - - def _add_ingress_ra_rule(self, port, ips): - ra_ips = ips.get(port['network_id']) - for ra_ip in ra_ips: - if not netaddr.IPAddress(ra_ip).version == 6: - return - - ra_rule = {'direction': 'ingress', - 'ethertype': q_const.IPv6, - 'protocol': q_const.PROTO_NAME_ICMP_V6, - 'source_ip_prefix': ra_ip, - 'source_port_range_min': q_const.ICMPV6_TYPE_RA} - port['security_group_rules'].append(ra_rule) - - def _apply_provider_rule(self, context, ports): - network_ids = self._select_network_ids(ports) - ips_dhcp = self._select_dhcp_ips_for_network_ids(context, network_ids) - ips_ra = self._select_ra_ips_for_network_ids(context, network_ids) - for port in ports.values(): - self._add_ingress_ra_rule(port, ips_ra) - self._add_ingress_dhcp_rule(port, ips_dhcp) - - def _security_group_rules_for_ports(self, context, ports): - rules_in_db = self._select_rules_for_ports(context, ports) - for (binding, rule_in_db) in rules_in_db: - port_id = binding['port_id'] - port = ports[port_id] - direction = rule_in_db['direction'] - rule_dict = { - 'security_group_id': rule_in_db['security_group_id'], - 'direction': direction, - 'ethertype': rule_in_db['ethertype'], - } - for key in ('protocol', 'port_range_min', 'port_range_max', - 'remote_ip_prefix', 'remote_group_id'): - if rule_in_db.get(key): - if key == 'remote_ip_prefix': - direction_ip_prefix = DIRECTION_IP_PREFIX[direction] - rule_dict[direction_ip_prefix] = rule_in_db[key] - continue - rule_dict[key] = rule_in_db[key] - port['security_group_rules'].append(rule_dict) - self._apply_provider_rule(context, ports) - return self._convert_remote_group_id_to_ip_prefix(context, ports) diff --git a/neutron/db/servicetype_db.py b/neutron/db/servicetype_db.py deleted file mode 100644 index 3e9ad15e0..000000000 --- a/neutron/db/servicetype_db.py +++ /dev/null @@ -1,99 +0,0 @@ -# Copyright 2013 OpenStack Foundation. -# 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, VMware -# - -import sqlalchemy as sa - -from neutron.db import api as db -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.openstack.common import log as logging -from neutron.services import provider_configuration as pconf - -LOG = logging.getLogger(__name__) - - -class ProviderResourceAssociation(model_base.BASEV2): - provider_name = sa.Column(sa.String(255), - nullable=False, primary_key=True) - # should be manualy deleted on resource deletion - resource_id = sa.Column(sa.String(36), nullable=False, primary_key=True, - unique=True) - - -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._initialize_db() - self._load_conf() - - def _initialize_db(self): - db.configure_db() - db.register_models(models_v2.model_base.BASEV2) - - def _load_conf(self): - self.conf = pconf.ProviderConfiguration( - pconf.parse_service_provider_opt()) - - def get_service_providers(self, context, filters=None, fields=None): - return self.conf.get_service_providers(filters, fields) - - def get_default_service_provider(self, context, service_type): - """Return the default provider for a given service type.""" - filters = {'service_type': [service_type], - 'default': [True]} - providers = self.get_service_providers(context, filters=filters) - # By construction we expect at most a single item in provider - if not providers: - raise pconf.DefaultServiceProviderNotFound( - service_type=service_type - ) - return providers[0] - - def add_resource_association(self, context, service_type, provider_name, - resource_id): - r = self.conf.get_service_providers( - filters={'service_type': [service_type], 'name': [provider_name]}) - if not r: - raise pconf.ServiceProviderNotFound(provider=provider_name, - service_type=service_type) - - with context.session.begin(subtransactions=True): - # we don't actually need service type for association. - # resource_id is unique and belongs to specific service - # which knows its type - assoc = ProviderResourceAssociation(provider_name=provider_name, - resource_id=resource_id) - context.session.add(assoc) - - def del_resource_associations(self, context, resource_ids): - if not resource_ids: - return - with context.session.begin(subtransactions=True): - (context.session.query(ProviderResourceAssociation). - filter( - ProviderResourceAssociation.resource_id.in_(resource_ids)). - delete(synchronize_session='fetch')) diff --git a/neutron/db/vpn/__init__.py b/neutron/db/vpn/__init__.py deleted file mode 100644 index 7f4f3b9f8..000000000 --- a/neutron/db/vpn/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# (c) Copyright 2013 Hewlett-Packard Development Company, L.P. -# 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: Swaminathan Vasudevan, Hewlett-Packard. diff --git a/neutron/db/vpn/vpn_db.py b/neutron/db/vpn/vpn_db.py deleted file mode 100644 index a434b26ba..000000000 --- a/neutron/db/vpn/vpn_db.py +++ /dev/null @@ -1,691 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# (c) Copyright 2013 Hewlett-Packard Development Company, L.P. -# 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: Swaminathan Vasudevan, Hewlett-Packard. - -import netaddr -import sqlalchemy as sa -from sqlalchemy import orm -from sqlalchemy.orm import exc - -from neutron.common import constants as n_constants -from neutron.db import api as qdbapi -from neutron.db import db_base_plugin_v2 as base_db -from neutron.db import l3_agentschedulers_db as l3_agent_db -from neutron.db import l3_db -from neutron.db import model_base -from neutron.db import models_v2 -from neutron.extensions import vpnaas -from neutron import manager -from neutron.openstack.common import excutils -from neutron.openstack.common import log as logging -from neutron.openstack.common import uuidutils -from neutron.plugins.common import constants -from neutron.plugins.common import utils - -LOG = logging.getLogger(__name__) - -IP_MIN_MTU = {4: 68, 6: 1280} - - -class IPsecPeerCidr(model_base.BASEV2): - """Internal representation of a IPsec Peer Cidrs.""" - - cidr = sa.Column(sa.String(32), nullable=False, primary_key=True) - ipsec_site_connection_id = sa.Column( - sa.String(36), - sa.ForeignKey('ipsec_site_connections.id', - ondelete="CASCADE"), - primary_key=True) - - -class IPsecPolicy(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): - """Represents a v2 IPsecPolicy Object.""" - __tablename__ = 'ipsecpolicies' - name = sa.Column(sa.String(255)) - description = sa.Column(sa.String(255)) - transform_protocol = sa.Column(sa.Enum("esp", "ah", "ah-esp", - name="ipsec_transform_protocols"), - nullable=False) - auth_algorithm = sa.Column(sa.Enum("sha1", - name="vpn_auth_algorithms"), - nullable=False) - encryption_algorithm = sa.Column(sa.Enum("3des", "aes-128", - "aes-256", "aes-192", - name="vpn_encrypt_algorithms"), - nullable=False) - encapsulation_mode = sa.Column(sa.Enum("tunnel", "transport", - name="ipsec_encapsulations"), - nullable=False) - lifetime_units = sa.Column(sa.Enum("seconds", "kilobytes", - name="vpn_lifetime_units"), - nullable=False) - lifetime_value = sa.Column(sa.Integer, nullable=False) - pfs = sa.Column(sa.Enum("group2", "group5", "group14", - name="vpn_pfs"), nullable=False) - - -class IKEPolicy(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): - """Represents a v2 IKEPolicy Object.""" - __tablename__ = 'ikepolicies' - name = sa.Column(sa.String(255)) - description = sa.Column(sa.String(255)) - auth_algorithm = sa.Column(sa.Enum("sha1", - name="vpn_auth_algorithms"), - nullable=False) - encryption_algorithm = sa.Column(sa.Enum("3des", "aes-128", - "aes-256", "aes-192", - name="vpn_encrypt_algorithms"), - nullable=False) - phase1_negotiation_mode = sa.Column(sa.Enum("main", - name="ike_phase1_mode"), - nullable=False) - lifetime_units = sa.Column(sa.Enum("seconds", "kilobytes", - name="vpn_lifetime_units"), - nullable=False) - lifetime_value = sa.Column(sa.Integer, nullable=False) - ike_version = sa.Column(sa.Enum("v1", "v2", name="ike_versions"), - nullable=False) - pfs = sa.Column(sa.Enum("group2", "group5", "group14", - name="vpn_pfs"), nullable=False) - - -class IPsecSiteConnection(model_base.BASEV2, - models_v2.HasId, models_v2.HasTenant): - """Represents a IPsecSiteConnection Object.""" - __tablename__ = 'ipsec_site_connections' - name = sa.Column(sa.String(255)) - description = sa.Column(sa.String(255)) - peer_address = sa.Column(sa.String(255), nullable=False) - peer_id = sa.Column(sa.String(255), nullable=False) - route_mode = sa.Column(sa.String(8), nullable=False) - mtu = sa.Column(sa.Integer, nullable=False) - initiator = sa.Column(sa.Enum("bi-directional", "response-only", - name="vpn_initiators"), nullable=False) - auth_mode = sa.Column(sa.String(16), nullable=False) - psk = sa.Column(sa.String(255), nullable=False) - dpd_action = sa.Column(sa.Enum("hold", "clear", - "restart", "disabled", - "restart-by-peer", name="vpn_dpd_actions"), - nullable=False) - dpd_interval = sa.Column(sa.Integer, nullable=False) - dpd_timeout = sa.Column(sa.Integer, nullable=False) - status = sa.Column(sa.String(16), nullable=False) - admin_state_up = sa.Column(sa.Boolean(), nullable=False) - vpnservice_id = sa.Column(sa.String(36), - sa.ForeignKey('vpnservices.id'), - nullable=False) - ipsecpolicy_id = sa.Column(sa.String(36), - sa.ForeignKey('ipsecpolicies.id'), - nullable=False) - ikepolicy_id = sa.Column(sa.String(36), - sa.ForeignKey('ikepolicies.id'), - nullable=False) - ipsecpolicy = orm.relationship( - IPsecPolicy, backref='ipsec_site_connection') - ikepolicy = orm.relationship(IKEPolicy, backref='ipsec_site_connection') - peer_cidrs = orm.relationship(IPsecPeerCidr, - backref='ipsec_site_connection', - lazy='joined', - cascade='all, delete, delete-orphan') - - -class VPNService(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): - """Represents a v2 VPNService Object.""" - name = sa.Column(sa.String(255)) - description = sa.Column(sa.String(255)) - status = sa.Column(sa.String(16), nullable=False) - admin_state_up = sa.Column(sa.Boolean(), nullable=False) - subnet_id = sa.Column(sa.String(36), sa.ForeignKey('subnets.id'), - nullable=False) - router_id = sa.Column(sa.String(36), sa.ForeignKey('routers.id'), - nullable=False) - subnet = orm.relationship(models_v2.Subnet) - router = orm.relationship(l3_db.Router) - ipsec_site_connections = orm.relationship( - IPsecSiteConnection, - backref='vpnservice', - cascade="all, delete-orphan") - - -class VPNPluginDb(vpnaas.VPNPluginBase, base_db.CommonDbMixin): - """VPN plugin database class using SQLAlchemy models.""" - - def __init__(self): - """Do the initialization for the vpn service plugin here.""" - qdbapi.register_models() - - def update_status(self, context, model, v_id, status): - with context.session.begin(subtransactions=True): - v_db = self._get_resource(context, model, v_id) - v_db.update({'status': status}) - - def _get_resource(self, context, model, v_id): - try: - r = self._get_by_id(context, model, v_id) - except exc.NoResultFound: - with excutils.save_and_reraise_exception(reraise=False) as ctx: - if issubclass(model, IPsecSiteConnection): - raise vpnaas.IPsecSiteConnectionNotFound( - ipsec_site_conn_id=v_id - ) - elif issubclass(model, IKEPolicy): - raise vpnaas.IKEPolicyNotFound(ikepolicy_id=v_id) - elif issubclass(model, IPsecPolicy): - raise vpnaas.IPsecPolicyNotFound(ipsecpolicy_id=v_id) - elif issubclass(model, VPNService): - raise vpnaas.VPNServiceNotFound(vpnservice_id=v_id) - ctx.reraise = True - return r - - def assert_update_allowed(self, obj): - status = getattr(obj, 'status', None) - _id = getattr(obj, 'id', None) - if utils.in_pending_status(status): - raise vpnaas.VPNStateInvalidToUpdate(id=_id, state=status) - - def _make_ipsec_site_connection_dict(self, ipsec_site_conn, fields=None): - - res = {'id': ipsec_site_conn['id'], - 'tenant_id': ipsec_site_conn['tenant_id'], - 'name': ipsec_site_conn['name'], - 'description': ipsec_site_conn['description'], - 'peer_address': ipsec_site_conn['peer_address'], - 'peer_id': ipsec_site_conn['peer_id'], - 'route_mode': ipsec_site_conn['route_mode'], - 'mtu': ipsec_site_conn['mtu'], - 'auth_mode': ipsec_site_conn['auth_mode'], - 'psk': ipsec_site_conn['psk'], - 'initiator': ipsec_site_conn['initiator'], - 'dpd': { - 'action': ipsec_site_conn['dpd_action'], - 'interval': ipsec_site_conn['dpd_interval'], - 'timeout': ipsec_site_conn['dpd_timeout'] - }, - 'admin_state_up': ipsec_site_conn['admin_state_up'], - 'status': ipsec_site_conn['status'], - 'vpnservice_id': ipsec_site_conn['vpnservice_id'], - 'ikepolicy_id': ipsec_site_conn['ikepolicy_id'], - 'ipsecpolicy_id': ipsec_site_conn['ipsecpolicy_id'], - 'peer_cidrs': [pcidr['cidr'] - for pcidr in ipsec_site_conn['peer_cidrs']] - } - - return self._fields(res, fields) - - def create_ipsec_site_connection(self, context, ipsec_site_connection): - ipsec_sitecon = ipsec_site_connection['ipsec_site_connection'] - dpd = ipsec_sitecon['dpd'] - ipsec_sitecon['dpd_action'] = dpd.get('action', 'hold') - ipsec_sitecon['dpd_interval'] = dpd.get('interval', 30) - ipsec_sitecon['dpd_timeout'] = dpd.get('timeout', 120) - tenant_id = self._get_tenant_id_for_create(context, ipsec_sitecon) - self._check_dpd(ipsec_sitecon) - with context.session.begin(subtransactions=True): - #Check permissions - self._get_resource(context, - VPNService, - ipsec_sitecon['vpnservice_id']) - self._get_resource(context, - IKEPolicy, - ipsec_sitecon['ikepolicy_id']) - self._get_resource(context, - IPsecPolicy, - ipsec_sitecon['ipsecpolicy_id']) - self._check_mtu(context, - ipsec_sitecon['mtu'], - ipsec_sitecon['vpnservice_id']) - ipsec_site_conn_db = IPsecSiteConnection( - id=uuidutils.generate_uuid(), - tenant_id=tenant_id, - name=ipsec_sitecon['name'], - description=ipsec_sitecon['description'], - peer_address=ipsec_sitecon['peer_address'], - peer_id=ipsec_sitecon['peer_id'], - route_mode='static', - mtu=ipsec_sitecon['mtu'], - auth_mode='psk', - psk=ipsec_sitecon['psk'], - initiator=ipsec_sitecon['initiator'], - dpd_action=ipsec_sitecon['dpd_action'], - dpd_interval=ipsec_sitecon['dpd_interval'], - dpd_timeout=ipsec_sitecon['dpd_timeout'], - admin_state_up=ipsec_sitecon['admin_state_up'], - status=constants.PENDING_CREATE, - vpnservice_id=ipsec_sitecon['vpnservice_id'], - ikepolicy_id=ipsec_sitecon['ikepolicy_id'], - ipsecpolicy_id=ipsec_sitecon['ipsecpolicy_id'] - ) - context.session.add(ipsec_site_conn_db) - for cidr in ipsec_sitecon['peer_cidrs']: - peer_cidr_db = IPsecPeerCidr( - cidr=cidr, - ipsec_site_connection_id=ipsec_site_conn_db['id'] - ) - context.session.add(peer_cidr_db) - return self._make_ipsec_site_connection_dict(ipsec_site_conn_db) - - def _check_dpd(self, ipsec_sitecon): - if ipsec_sitecon['dpd_timeout'] <= ipsec_sitecon['dpd_interval']: - raise vpnaas.IPsecSiteConnectionDpdIntervalValueError( - attr='dpd_timeout') - - def _check_mtu(self, context, mtu, vpnservice_id): - vpn_service_db = self._get_vpnservice(context, vpnservice_id) - subnet = vpn_service_db.subnet['cidr'] - version = netaddr.IPNetwork(subnet).version - if mtu < IP_MIN_MTU[version]: - raise vpnaas.IPsecSiteConnectionMtuError(mtu=mtu, version=version) - - def update_ipsec_site_connection( - self, context, - ipsec_site_conn_id, ipsec_site_connection): - conn = ipsec_site_connection['ipsec_site_connection'] - changed_peer_cidrs = False - with context.session.begin(subtransactions=True): - ipsec_site_conn_db = self._get_resource( - context, - IPsecSiteConnection, - ipsec_site_conn_id) - dpd = conn.get('dpd', {}) - if dpd.get('action'): - conn['dpd_action'] = dpd.get('action') - if dpd.get('interval') or dpd.get('timeout'): - conn['dpd_interval'] = dpd.get( - 'interval', ipsec_site_conn_db.dpd_interval) - conn['dpd_timeout'] = dpd.get( - 'timeout', ipsec_site_conn_db.dpd_timeout) - self._check_dpd(conn) - - if 'mtu' in conn: - self._check_mtu(context, - conn['mtu'], - ipsec_site_conn_db.vpnservice_id) - - self.assert_update_allowed(ipsec_site_conn_db) - - if "peer_cidrs" in conn: - changed_peer_cidrs = True - old_peer_cidr_list = ipsec_site_conn_db['peer_cidrs'] - old_peer_cidr_dict = dict( - (peer_cidr['cidr'], peer_cidr) - for peer_cidr in old_peer_cidr_list) - new_peer_cidr_set = set(conn["peer_cidrs"]) - old_peer_cidr_set = set(old_peer_cidr_dict) - - new_peer_cidrs = list(new_peer_cidr_set) - for peer_cidr in old_peer_cidr_set - new_peer_cidr_set: - context.session.delete(old_peer_cidr_dict[peer_cidr]) - for peer_cidr in new_peer_cidr_set - old_peer_cidr_set: - pcidr = IPsecPeerCidr( - cidr=peer_cidr, - ipsec_site_connection_id=ipsec_site_conn_id) - context.session.add(pcidr) - del conn["peer_cidrs"] - if conn: - ipsec_site_conn_db.update(conn) - result = self._make_ipsec_site_connection_dict(ipsec_site_conn_db) - if changed_peer_cidrs: - result['peer_cidrs'] = new_peer_cidrs - return result - - def delete_ipsec_site_connection(self, context, ipsec_site_conn_id): - with context.session.begin(subtransactions=True): - ipsec_site_conn_db = self._get_resource( - context, IPsecSiteConnection, ipsec_site_conn_id - ) - context.session.delete(ipsec_site_conn_db) - - def _get_ipsec_site_connection( - self, context, ipsec_site_conn_id): - return self._get_resource( - context, IPsecSiteConnection, ipsec_site_conn_id) - - def get_ipsec_site_connection(self, context, - ipsec_site_conn_id, fields=None): - ipsec_site_conn_db = self._get_ipsec_site_connection( - context, ipsec_site_conn_id) - return self._make_ipsec_site_connection_dict( - ipsec_site_conn_db, fields) - - def get_ipsec_site_connections(self, context, filters=None, fields=None): - return self._get_collection(context, IPsecSiteConnection, - self._make_ipsec_site_connection_dict, - filters=filters, fields=fields) - - def update_ipsec_site_conn_status(self, context, conn_id, new_status): - with context.session.begin(): - self._update_connection_status(context, conn_id, new_status, True) - - def _update_connection_status(self, context, conn_id, new_status, - updated_pending): - """Update the connection status, if changed. - - If the connection is not in a pending state, unconditionally update - the status. Likewise, if in a pending state, and have an indication - that the status has changed, then update the database. - """ - try: - conn_db = self._get_ipsec_site_connection(context, conn_id) - except vpnaas.IPsecSiteConnectionNotFound: - return - if not utils.in_pending_status(conn_db.status) or updated_pending: - conn_db.status = new_status - - def _make_ikepolicy_dict(self, ikepolicy, fields=None): - res = {'id': ikepolicy['id'], - 'tenant_id': ikepolicy['tenant_id'], - 'name': ikepolicy['name'], - 'description': ikepolicy['description'], - 'auth_algorithm': ikepolicy['auth_algorithm'], - 'encryption_algorithm': ikepolicy['encryption_algorithm'], - 'phase1_negotiation_mode': ikepolicy['phase1_negotiation_mode'], - 'lifetime': { - 'units': ikepolicy['lifetime_units'], - 'value': ikepolicy['lifetime_value'], - }, - 'ike_version': ikepolicy['ike_version'], - 'pfs': ikepolicy['pfs'] - } - - return self._fields(res, fields) - - def create_ikepolicy(self, context, ikepolicy): - ike = ikepolicy['ikepolicy'] - tenant_id = self._get_tenant_id_for_create(context, ike) - lifetime_info = ike.get('lifetime', []) - lifetime_units = lifetime_info.get('units', 'seconds') - lifetime_value = lifetime_info.get('value', 3600) - - with context.session.begin(subtransactions=True): - ike_db = IKEPolicy( - id=uuidutils.generate_uuid(), - tenant_id=tenant_id, - name=ike['name'], - description=ike['description'], - auth_algorithm=ike['auth_algorithm'], - encryption_algorithm=ike['encryption_algorithm'], - phase1_negotiation_mode=ike['phase1_negotiation_mode'], - lifetime_units=lifetime_units, - lifetime_value=lifetime_value, - ike_version=ike['ike_version'], - pfs=ike['pfs'] - ) - - context.session.add(ike_db) - return self._make_ikepolicy_dict(ike_db) - - def update_ikepolicy(self, context, ikepolicy_id, ikepolicy): - ike = ikepolicy['ikepolicy'] - with context.session.begin(subtransactions=True): - ikepolicy = context.session.query(IPsecSiteConnection).filter_by( - ikepolicy_id=ikepolicy_id).first() - if ikepolicy: - raise vpnaas.IKEPolicyInUse(ikepolicy_id=ikepolicy_id) - ike_db = self._get_resource(context, IKEPolicy, ikepolicy_id) - if ike: - lifetime_info = ike.get('lifetime') - if lifetime_info: - if lifetime_info.get('units'): - ike['lifetime_units'] = lifetime_info['units'] - if lifetime_info.get('value'): - ike['lifetime_value'] = lifetime_info['value'] - ike_db.update(ike) - return self._make_ikepolicy_dict(ike_db) - - def delete_ikepolicy(self, context, ikepolicy_id): - with context.session.begin(subtransactions=True): - ikepolicy = context.session.query(IPsecSiteConnection).filter_by( - ikepolicy_id=ikepolicy_id).first() - if ikepolicy: - raise vpnaas.IKEPolicyInUse(ikepolicy_id=ikepolicy_id) - ike_db = self._get_resource(context, IKEPolicy, ikepolicy_id) - context.session.delete(ike_db) - - def get_ikepolicy(self, context, ikepolicy_id, fields=None): - ike_db = self._get_resource(context, IKEPolicy, ikepolicy_id) - return self._make_ikepolicy_dict(ike_db, fields) - - def get_ikepolicies(self, context, filters=None, fields=None): - return self._get_collection(context, IKEPolicy, - self._make_ikepolicy_dict, - filters=filters, fields=fields) - - def _make_ipsecpolicy_dict(self, ipsecpolicy, fields=None): - - res = {'id': ipsecpolicy['id'], - 'tenant_id': ipsecpolicy['tenant_id'], - 'name': ipsecpolicy['name'], - 'description': ipsecpolicy['description'], - 'transform_protocol': ipsecpolicy['transform_protocol'], - 'auth_algorithm': ipsecpolicy['auth_algorithm'], - 'encryption_algorithm': ipsecpolicy['encryption_algorithm'], - 'encapsulation_mode': ipsecpolicy['encapsulation_mode'], - 'lifetime': { - 'units': ipsecpolicy['lifetime_units'], - 'value': ipsecpolicy['lifetime_value'], - }, - 'pfs': ipsecpolicy['pfs'] - } - - return self._fields(res, fields) - - def create_ipsecpolicy(self, context, ipsecpolicy): - ipsecp = ipsecpolicy['ipsecpolicy'] - tenant_id = self._get_tenant_id_for_create(context, ipsecp) - lifetime_info = ipsecp['lifetime'] - lifetime_units = lifetime_info.get('units', 'seconds') - lifetime_value = lifetime_info.get('value', 3600) - - with context.session.begin(subtransactions=True): - ipsecp_db = IPsecPolicy(id=uuidutils.generate_uuid(), - tenant_id=tenant_id, - name=ipsecp['name'], - description=ipsecp['description'], - transform_protocol=ipsecp['transform_' - 'protocol'], - auth_algorithm=ipsecp['auth_algorithm'], - encryption_algorithm=ipsecp['encryption_' - 'algorithm'], - encapsulation_mode=ipsecp['encapsulation_' - 'mode'], - lifetime_units=lifetime_units, - lifetime_value=lifetime_value, - pfs=ipsecp['pfs']) - context.session.add(ipsecp_db) - return self._make_ipsecpolicy_dict(ipsecp_db) - - def update_ipsecpolicy(self, context, ipsecpolicy_id, ipsecpolicy): - ipsecp = ipsecpolicy['ipsecpolicy'] - with context.session.begin(subtransactions=True): - ipsecpolicy = context.session.query(IPsecSiteConnection).filter_by( - ipsecpolicy_id=ipsecpolicy_id).first() - if ipsecpolicy: - raise vpnaas.IPsecPolicyInUse(ipsecpolicy_id=ipsecpolicy_id) - ipsecp_db = self._get_resource(context, - IPsecPolicy, - ipsecpolicy_id) - if ipsecp: - lifetime_info = ipsecp.get('lifetime') - if lifetime_info: - if lifetime_info.get('units'): - ipsecp['lifetime_units'] = lifetime_info['units'] - if lifetime_info.get('value'): - ipsecp['lifetime_value'] = lifetime_info['value'] - ipsecp_db.update(ipsecp) - return self._make_ipsecpolicy_dict(ipsecp_db) - - def delete_ipsecpolicy(self, context, ipsecpolicy_id): - with context.session.begin(subtransactions=True): - ipsecpolicy = context.session.query(IPsecSiteConnection).filter_by( - ipsecpolicy_id=ipsecpolicy_id).first() - if ipsecpolicy: - raise vpnaas.IPsecPolicyInUse(ipsecpolicy_id=ipsecpolicy_id) - ipsec_db = self._get_resource(context, IPsecPolicy, ipsecpolicy_id) - context.session.delete(ipsec_db) - - def get_ipsecpolicy(self, context, ipsecpolicy_id, fields=None): - ipsec_db = self._get_resource(context, IPsecPolicy, ipsecpolicy_id) - return self._make_ipsecpolicy_dict(ipsec_db, fields) - - def get_ipsecpolicies(self, context, filters=None, fields=None): - return self._get_collection(context, IPsecPolicy, - self._make_ipsecpolicy_dict, - filters=filters, fields=fields) - - def _make_vpnservice_dict(self, vpnservice, fields=None): - res = {'id': vpnservice['id'], - 'name': vpnservice['name'], - 'description': vpnservice['description'], - 'tenant_id': vpnservice['tenant_id'], - 'subnet_id': vpnservice['subnet_id'], - 'router_id': vpnservice['router_id'], - 'admin_state_up': vpnservice['admin_state_up'], - 'status': vpnservice['status']} - return self._fields(res, fields) - - def _check_router(self, context, router_id): - l3_plugin = manager.NeutronManager.get_service_plugins().get( - constants.L3_ROUTER_NAT) - router = l3_plugin.get_router(context, router_id) - if not router.get(l3_db.EXTERNAL_GW_INFO): - raise vpnaas.RouterIsNotExternal(router_id=router_id) - - def _check_subnet_id(self, context, router_id, subnet_id): - core_plugin = manager.NeutronManager.get_plugin() - ports = core_plugin.get_ports( - context, - filters={ - 'fixed_ips': {'subnet_id': [subnet_id]}, - 'device_id': [router_id]}) - if not ports: - raise vpnaas.SubnetIsNotConnectedToRouter( - subnet_id=subnet_id, - router_id=router_id) - - def create_vpnservice(self, context, vpnservice): - vpns = vpnservice['vpnservice'] - tenant_id = self._get_tenant_id_for_create(context, vpns) - self._check_router(context, vpns['router_id']) - self._check_subnet_id(context, vpns['router_id'], vpns['subnet_id']) - with context.session.begin(subtransactions=True): - vpnservice_db = VPNService(id=uuidutils.generate_uuid(), - tenant_id=tenant_id, - name=vpns['name'], - description=vpns['description'], - subnet_id=vpns['subnet_id'], - router_id=vpns['router_id'], - admin_state_up=vpns['admin_state_up'], - status=constants.PENDING_CREATE) - context.session.add(vpnservice_db) - return self._make_vpnservice_dict(vpnservice_db) - - def update_vpnservice(self, context, vpnservice_id, vpnservice): - vpns = vpnservice['vpnservice'] - with context.session.begin(subtransactions=True): - vpns_db = self._get_resource(context, VPNService, vpnservice_id) - self.assert_update_allowed(vpns_db) - if vpns: - vpns_db.update(vpns) - return self._make_vpnservice_dict(vpns_db) - - def delete_vpnservice(self, context, vpnservice_id): - with context.session.begin(subtransactions=True): - if context.session.query(IPsecSiteConnection).filter_by( - vpnservice_id=vpnservice_id - ).first(): - raise vpnaas.VPNServiceInUse(vpnservice_id=vpnservice_id) - vpns_db = self._get_resource(context, VPNService, vpnservice_id) - context.session.delete(vpns_db) - - def _get_vpnservice(self, context, vpnservice_id): - return self._get_resource(context, VPNService, vpnservice_id) - - def get_vpnservice(self, context, vpnservice_id, fields=None): - vpns_db = self._get_resource(context, VPNService, vpnservice_id) - return self._make_vpnservice_dict(vpns_db, fields) - - def get_vpnservices(self, context, filters=None, fields=None): - return self._get_collection(context, VPNService, - self._make_vpnservice_dict, - filters=filters, fields=fields) - - def check_router_in_use(self, context, router_id): - vpnservices = self.get_vpnservices( - context, filters={'router_id': [router_id]}) - if vpnservices: - raise vpnaas.RouterInUseByVPNService( - router_id=router_id, - vpnservice_id=vpnservices[0]['id']) - - -class VPNPluginRpcDbMixin(): - def _get_agent_hosting_vpn_services(self, context, host): - - plugin = manager.NeutronManager.get_plugin() - agent = plugin._get_agent_by_type_and_host( - context, n_constants.AGENT_TYPE_L3, host) - if not agent.admin_state_up: - return [] - query = context.session.query(VPNService) - query = query.join(IPsecSiteConnection) - query = query.join(IKEPolicy) - query = query.join(IPsecPolicy) - query = query.join(IPsecPeerCidr) - query = query.join(l3_agent_db.RouterL3AgentBinding, - l3_agent_db.RouterL3AgentBinding.router_id == - VPNService.router_id) - query = query.filter( - l3_agent_db.RouterL3AgentBinding.l3_agent_id == agent.id) - return query - - def update_status_by_agent(self, context, service_status_info_list): - """Updating vpnservice and vpnconnection status. - - :param context: context variable - :param service_status_info_list: list of status - The structure is - [{id: vpnservice_id, - status: ACTIVE|DOWN|ERROR, - updated_pending_status: True|False - ipsec_site_connections: { - ipsec_site_connection_id: { - status: ACTIVE|DOWN|ERROR, - updated_pending_status: True|False - } - }] - The agent will set updated_pending_status as True, - when agent update any pending status. - """ - with context.session.begin(subtransactions=True): - for vpnservice in service_status_info_list: - try: - vpnservice_db = self._get_vpnservice( - context, vpnservice['id']) - except vpnaas.VPNServiceNotFound: - LOG.warn(_('vpnservice %s in db is already deleted'), - vpnservice['id']) - continue - - if (not utils.in_pending_status(vpnservice_db.status) - or vpnservice['updated_pending_status']): - vpnservice_db.status = vpnservice['status'] - for conn_id, conn in vpnservice[ - 'ipsec_site_connections'].items(): - self._update_connection_status( - context, conn_id, conn['status'], - conn['updated_pending_status'])