use context manager from neutron-lib
Access to neutron.db.api's context manager is already in neutron-lib and in fact neutron is already using it as a shim. This patch switches over context manager access to use neutron-lib's accessors. Also see https://review.openstack.org/#/c/613122 Change-Id: I13eb3a25a5bd83bb00dfa4a7430324551fea0f2e
This commit is contained in:
parent
00708913cb
commit
d29a0baa80
@ -18,6 +18,7 @@ import random
|
||||
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import context as n_context
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib import exceptions
|
||||
from neutron_lib.exceptions import l3 as l3_exc
|
||||
from oslo_log import log
|
||||
@ -27,7 +28,6 @@ from oslo_utils import timeutils
|
||||
import six
|
||||
|
||||
from neutron.db import _model_query as model_query
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db.models import external_net as external_net_db
|
||||
from neutron.db.models import l3 as l3_db
|
||||
from neutron.db import models_v2
|
||||
@ -302,7 +302,7 @@ class NsxSynchronizer(object):
|
||||
# do nothing
|
||||
return
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
try:
|
||||
network = self._plugin._get_network(context,
|
||||
neutron_network_data['id'])
|
||||
@ -384,7 +384,7 @@ class NsxSynchronizer(object):
|
||||
# do nothing
|
||||
return
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
try:
|
||||
router = self._plugin._get_router(context,
|
||||
neutron_router_data['id'])
|
||||
@ -436,7 +436,7 @@ class NsxSynchronizer(object):
|
||||
(models_v2.Network.id ==
|
||||
external_net_db.ExternalNetwork.network_id))]
|
||||
if neutron_port_data['network_id'] in ext_networks:
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
neutron_port_data['status'] = constants.PORT_STATUS_ACTIVE
|
||||
return
|
||||
|
||||
@ -479,7 +479,7 @@ class NsxSynchronizer(object):
|
||||
# do nothing
|
||||
return
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
try:
|
||||
port = self._plugin._get_port(context,
|
||||
neutron_port_data['id'])
|
||||
|
@ -23,8 +23,6 @@ from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
import neutron.db.api as db
|
||||
|
||||
from vmware_nsx.common import exceptions as nsx_exc
|
||||
from vmware_nsx.db import nsx_models
|
||||
|
||||
@ -440,7 +438,7 @@ def delete_port_mirror_session_mapping(session, tf_id):
|
||||
filter_by(tap_flow_id=tf_id).delete())
|
||||
|
||||
|
||||
@db.context_manager.writer
|
||||
@db_api.CONTEXT_WRITER
|
||||
def save_sg_mappings(context, sg_id, nsgroup_id, section_id):
|
||||
context.session.add(
|
||||
nsx_models.NeutronNsxFirewallSectionMapping(neutron_id=sg_id,
|
||||
|
@ -21,7 +21,6 @@ from sqlalchemy.orm import exc
|
||||
from sqlalchemy import sql
|
||||
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db.models import securitygroup as securitygroups_db
|
||||
from neutron.extensions import securitygroup as ext_sg
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
@ -30,6 +29,7 @@ from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants as n_constants
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import model_base
|
||||
from neutron_lib.objects import registry as obj_reg
|
||||
from neutron_lib.utils import helpers
|
||||
@ -97,7 +97,7 @@ class ExtendedSecurityGroupPropertiesMixin(object):
|
||||
if not default_sg:
|
||||
self._ensure_default_security_group(context, tenant_id)
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
sg = obj_reg.new_instance(
|
||||
'SecurityGroup', context,
|
||||
id=s.get('id') or uuidutils.generate_uuid(),
|
||||
@ -123,7 +123,7 @@ class ExtendedSecurityGroupPropertiesMixin(object):
|
||||
default_sg=False):
|
||||
self._validate_security_group_properties_create(
|
||||
context, sg_req, default_sg)
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
properties = NsxExtendedSecurityGroupProperties(
|
||||
security_group_id=sg_res['id'],
|
||||
logging=sg_req.get(sg_logging.LOGGING, False),
|
||||
@ -135,7 +135,7 @@ class ExtendedSecurityGroupPropertiesMixin(object):
|
||||
sg_res[sg_policy.POLICY] = sg_req.get(sg_policy.POLICY)
|
||||
|
||||
def _get_security_group_properties(self, context, security_group_id):
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
try:
|
||||
prop = context.session.query(
|
||||
NsxExtendedSecurityGroupProperties).filter_by(
|
||||
@ -152,7 +152,7 @@ class ExtendedSecurityGroupPropertiesMixin(object):
|
||||
(sg_policy.POLICY in sg_req and
|
||||
(sg_req[sg_policy.POLICY] !=
|
||||
sg_res.get(sg_policy.POLICY)))):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
prop = context.session.query(
|
||||
NsxExtendedSecurityGroupProperties).filter_by(
|
||||
security_group_id=sg_res['id']).one()
|
||||
|
@ -19,10 +19,10 @@ from sqlalchemy import orm
|
||||
from sqlalchemy.orm import exc
|
||||
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db.models import securitygroup
|
||||
from neutron.extensions import securitygroup as ext_sg
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib import exceptions as nexception
|
||||
from vmware_nsx._i18n import _
|
||||
from vmware_nsx.extensions import secgroup_rule_local_ip_prefix as ext_local_ip
|
||||
@ -75,7 +75,7 @@ class ExtendedSecurityGroupRuleMixin(object):
|
||||
rule_req.get(ext_local_ip.LOCAL_IP_PREFIX)):
|
||||
return
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
properties = NsxExtendedSecurityGroupRuleProperties(
|
||||
rule_id=rule_res['id'],
|
||||
local_ip_prefix=rule_req[ext_local_ip.LOCAL_IP_PREFIX])
|
||||
@ -93,7 +93,7 @@ class ExtendedSecurityGroupRuleMixin(object):
|
||||
sg_rule_res[ext_local_ip.LOCAL_IP_PREFIX] = None
|
||||
|
||||
def _get_security_group_rule_local_ip(self, context, rule_id):
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
try:
|
||||
prop = context.session.query(
|
||||
NsxExtendedSecurityGroupRuleProperties).filter_by(
|
||||
|
@ -15,6 +15,7 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from neutron_lib.db import api as db_api
|
||||
from oslo_db import exception as d_exc
|
||||
from oslo_log import log as logging
|
||||
from sqlalchemy import orm
|
||||
@ -23,27 +24,26 @@ from vmware_nsx._i18n import _
|
||||
from vmware_nsx.common import exceptions as p_exc
|
||||
from vmware_nsx.db import nsx_models
|
||||
|
||||
from neutron.db import api as db_api
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def lsn_add(context, network_id, lsn_id):
|
||||
"""Add Logical Service Node information to persistent datastore."""
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
lsn = nsx_models.Lsn(network_id, lsn_id)
|
||||
context.session.add(lsn)
|
||||
|
||||
|
||||
def lsn_remove(context, lsn_id):
|
||||
"""Remove Logical Service Node information from datastore given its id."""
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
context.session.query(nsx_models.Lsn).filter_by(lsn_id=lsn_id).delete()
|
||||
|
||||
|
||||
def lsn_remove_for_network(context, network_id):
|
||||
"""Remove information about the Logical Service Node given its network."""
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
context.session.query(nsx_models.Lsn).filter_by(
|
||||
net_id=network_id).delete()
|
||||
|
||||
@ -65,14 +65,14 @@ def lsn_get_for_network(context, network_id, raise_on_err=True):
|
||||
|
||||
def lsn_port_add_for_lsn(context, lsn_port_id, subnet_id, mac, lsn_id):
|
||||
"""Add Logical Service Node Port information to persistent datastore."""
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
lsn_port = nsx_models.LsnPort(lsn_port_id, subnet_id, mac, lsn_id)
|
||||
context.session.add(lsn_port)
|
||||
|
||||
|
||||
def lsn_port_get_for_subnet(context, subnet_id, raise_on_err=True):
|
||||
"""Return Logical Service Node Port information given its subnet id."""
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
try:
|
||||
return (context.session.query(nsx_models.LsnPort).
|
||||
filter_by(sub_id=subnet_id).one())
|
||||
@ -85,7 +85,7 @@ def lsn_port_get_for_subnet(context, subnet_id, raise_on_err=True):
|
||||
|
||||
def lsn_port_get_for_mac(context, mac_address, raise_on_err=True):
|
||||
"""Return Logical Service Node Port information given its mac address."""
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
try:
|
||||
return (context.session.query(nsx_models.LsnPort).
|
||||
filter_by(mac_addr=mac_address).one())
|
||||
@ -98,6 +98,6 @@ def lsn_port_get_for_mac(context, mac_address, raise_on_err=True):
|
||||
|
||||
def lsn_port_remove(context, lsn_port_id):
|
||||
"""Remove Logical Service Node port from the given Logical Service Node."""
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
(context.session.query(nsx_models.LsnPort).
|
||||
filter_by(lsn_port_id=lsn_port_id).delete())
|
||||
|
@ -17,9 +17,9 @@ from sqlalchemy.orm import exc
|
||||
|
||||
from neutron.db import _model_query as model_query
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import api as db_api
|
||||
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import utils as db_utils
|
||||
|
||||
from oslo_log import log as logging
|
||||
@ -59,7 +59,7 @@ class MacLearningDbMixin(object):
|
||||
mac.MAC_LEARNING: enabled})
|
||||
|
||||
def _create_mac_learning_state(self, context, port):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
enabled = port[mac.MAC_LEARNING]
|
||||
state = nsx_models.MacLearningState(
|
||||
port_id=port['id'],
|
||||
|
@ -15,8 +15,8 @@
|
||||
from sqlalchemy.orm import exc as sa_orm_exc
|
||||
|
||||
from neutron.db import _model_query as model_query
|
||||
from neutron.db import api as db_api
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import utils as db_utils
|
||||
from neutron_lib import exceptions
|
||||
from neutron_lib.plugins import utils
|
||||
@ -180,12 +180,12 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
|
||||
return query.one() if only_one else query.all()
|
||||
|
||||
def _unset_default_network_gateways(self, context):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
context.session.query(nsx_models.NetworkGateway).update(
|
||||
{nsx_models.NetworkGateway.default: False})
|
||||
|
||||
def _set_default_network_gateway(self, context, gw_id):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
gw = (context.session.query(nsx_models.NetworkGateway).
|
||||
filter_by(id=gw_id).one())
|
||||
gw['default'] = True
|
||||
@ -220,7 +220,7 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
|
||||
validate_device_list=True):
|
||||
gw_data = network_gateway[self.gateway_resource]
|
||||
tenant_id = gw_data['tenant_id']
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
gw_db = nsx_models.NetworkGateway(
|
||||
id=gw_data.get('id', uuidutils.generate_uuid()),
|
||||
tenant_id=tenant_id,
|
||||
@ -238,7 +238,7 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
|
||||
|
||||
def update_network_gateway(self, context, id, network_gateway):
|
||||
gw_data = network_gateway[self.gateway_resource]
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
gw_db = self._get_network_gateway(context, id)
|
||||
if gw_db.default:
|
||||
raise NetworkGatewayUnchangeable(gateway_id=id)
|
||||
@ -253,7 +253,7 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
|
||||
return self._make_network_gateway_dict(gw_db, fields)
|
||||
|
||||
def delete_network_gateway(self, context, id):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
gw_db = self._get_network_gateway(context, id)
|
||||
if gw_db.network_connections:
|
||||
raise GatewayInUse(gateway_id=id)
|
||||
@ -281,7 +281,7 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
|
||||
"'%(network_gateway_id)s'",
|
||||
{'network_id': network_id,
|
||||
'network_gateway_id': network_gateway_id})
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
gw_db = self._get_network_gateway(context, network_gateway_id)
|
||||
tenant_id = gw_db['tenant_id']
|
||||
if context.is_admin and not tenant_id:
|
||||
@ -358,7 +358,7 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
|
||||
"'%(network_gateway_id)s'",
|
||||
{'network_id': network_id,
|
||||
'network_gateway_id': network_gateway_id})
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# Uniquely identify connection, otherwise raise
|
||||
try:
|
||||
net_connection = self._retrieve_gateway_connections(
|
||||
@ -442,7 +442,7 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
|
||||
initial_status=STATUS_UNKNOWN):
|
||||
device_data = gateway_device[self.device_resource]
|
||||
tenant_id = device_data['tenant_id']
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
device_db = nsx_models.NetworkGatewayDevice(
|
||||
id=device_data.get('id', uuidutils.generate_uuid()),
|
||||
tenant_id=tenant_id,
|
||||
@ -457,7 +457,7 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
|
||||
def update_gateway_device(self, context, gateway_device_id,
|
||||
gateway_device, include_nsx_id=False):
|
||||
device_data = gateway_device[self.device_resource]
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
device_db = self._get_gateway_device(context, gateway_device_id)
|
||||
# Ensure there is something to update before doing it
|
||||
if any([device_db[k] != device_data[k] for k in device_data]):
|
||||
@ -468,7 +468,7 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
|
||||
device_db, include_nsx_id=include_nsx_id)
|
||||
|
||||
def delete_gateway_device(self, context, device_id):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# A gateway device should not be deleted
|
||||
# if it is used in any network gateway service
|
||||
if self._is_device_in_use(context, device_id):
|
||||
|
@ -21,12 +21,12 @@ from neutron_lib.api.definitions import portbindings as pbin
|
||||
from neutron_lib.api.definitions import provider_net as pnet
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib import exceptions
|
||||
from neutron_lib.plugins import directory
|
||||
from neutron_lib.plugins import utils as p_utils
|
||||
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import portbindings_db as pbin_db
|
||||
from neutron.plugins.ml2 import models as pbin_model
|
||||
from vmware_nsx._i18n import _
|
||||
@ -112,7 +112,7 @@ class NsxPortBindingMixin(pbin_db.PortBindingMixin):
|
||||
elif network.get(pnet.NETWORK_TYPE) == c_utils.NsxVNetworkTypes.VLAN:
|
||||
vif_details[pbin.VIF_DETAILS_VLAN] = network[pnet.SEGMENTATION_ID]
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
port_binding = context.session.query(
|
||||
pbin_model.PortBinding).filter_by(port_id=port_id).first()
|
||||
|
||||
|
@ -17,11 +17,11 @@ from sqlalchemy.orm import exc
|
||||
|
||||
from neutron.db import _model_query as model_query
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import models_v2
|
||||
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import utils as db_utils
|
||||
|
||||
from oslo_log import log
|
||||
@ -39,7 +39,7 @@ class QoSDbMixin(qos.QueuePluginBase):
|
||||
|
||||
def create_qos_queue(self, context, qos_queue):
|
||||
q = qos_queue['qos_queue']
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
qos_queue = nsx_models.QoSQueue(
|
||||
id=q.get('id', uuidutils.generate_uuid()),
|
||||
name=q.get('name'),
|
||||
@ -75,7 +75,7 @@ class QoSDbMixin(qos.QueuePluginBase):
|
||||
page_reverse=page_reverse)
|
||||
|
||||
def delete_qos_queue(self, context, queue_id):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
qos_queue = self._get_qos_queue(context, queue_id)
|
||||
context.session.delete(qos_queue)
|
||||
|
||||
@ -83,7 +83,7 @@ class QoSDbMixin(qos.QueuePluginBase):
|
||||
port_data[qos.QUEUE] = queue_id
|
||||
if not queue_id:
|
||||
return
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
context.session.add(nsx_models.PortQueueMapping(
|
||||
port_id=port_data['id'],
|
||||
queue_id=queue_id))
|
||||
@ -105,14 +105,14 @@ class QoSDbMixin(qos.QueuePluginBase):
|
||||
# did not already have a queue on it. There is no need to check
|
||||
# if there is one before deleting if we return here.
|
||||
return
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
context.session.delete(binding)
|
||||
|
||||
def _process_network_queue_mapping(self, context, net_data, queue_id):
|
||||
net_data[qos.QUEUE] = queue_id
|
||||
if not queue_id:
|
||||
return
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
context.session.add(
|
||||
nsx_models.NetworkQueueMapping(network_id=net_data['id'],
|
||||
queue_id=queue_id))
|
||||
@ -126,7 +126,7 @@ class QoSDbMixin(qos.QueuePluginBase):
|
||||
|
||||
def _delete_network_queue_mapping(self, context, network_id):
|
||||
query = self._model_query(context, nsx_models.NetworkQueueMapping)
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
binding = query.filter_by(network_id=network_id).first()
|
||||
if binding:
|
||||
context.session.delete(binding)
|
||||
|
@ -15,13 +15,13 @@
|
||||
#
|
||||
|
||||
from neutron_lib import constants as const
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib import exceptions as ntn_exc
|
||||
from oslo_config import cfg
|
||||
from oslo_db import exception as db_exc
|
||||
from oslo_log import log as logging
|
||||
|
||||
from neutron.api.rpc.agentnotifiers import dhcp_rpc_agent_api
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.db import models_v2
|
||||
|
||||
@ -159,7 +159,7 @@ def _find_dhcp_disabled_subnet_by_port(plugin, context, ports):
|
||||
# of the vmware plugin (and base db neutron plugin) to engine
|
||||
# facade to avoid cross transaction session cache reuse but such
|
||||
# change wouldn't happen overnight.
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
subnet = plugin.get_subnet(context, fixed_ip['subnet_id'])
|
||||
if not subnet['enable_dhcp']:
|
||||
return subnet
|
||||
|
@ -18,7 +18,6 @@ from oslo_log import log as logging
|
||||
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import address_scope_db
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.db import l3_attrs_db
|
||||
from neutron.db import l3_db
|
||||
@ -38,6 +37,7 @@ from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import context as n_context
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from neutron_lib.exceptions import allowedaddresspairs as addr_exc
|
||||
from neutron_lib.plugins import directory
|
||||
@ -70,7 +70,7 @@ class NsxPluginBase(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
ctx = n_context.get_admin_context()
|
||||
# get the core plugin as this is a static method with no 'self'
|
||||
plugin = directory.get_plugin()
|
||||
with db_api.context_manager.writer.using(ctx):
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
plugin._extension_manager.extend_network_dict(
|
||||
ctx.session, netdb, result)
|
||||
|
||||
@ -80,7 +80,7 @@ class NsxPluginBase(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
ctx = n_context.get_admin_context()
|
||||
# get the core plugin as this is a static method with no 'self'
|
||||
plugin = directory.get_plugin()
|
||||
with db_api.context_manager.writer.using(ctx):
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
plugin._extension_manager.extend_port_dict(
|
||||
ctx.session, portdb, result)
|
||||
|
||||
@ -90,7 +90,7 @@ class NsxPluginBase(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
ctx = n_context.get_admin_context()
|
||||
# get the core plugin as this is a static method with no 'self'
|
||||
plugin = directory.get_plugin()
|
||||
with db_api.context_manager.writer.using(ctx):
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
plugin._extension_manager.extend_subnet_dict(
|
||||
ctx.session, subnetdb, result)
|
||||
|
||||
|
@ -27,7 +27,6 @@ from neutron.api import extensions as neutron_extensions
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import agentschedulers_db
|
||||
from neutron.db import allowedaddresspairs_db as addr_pair_db
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import dns_db
|
||||
from neutron.db import external_net_db
|
||||
from neutron.db import l3_db
|
||||
@ -46,6 +45,7 @@ from neutron_lib.api.definitions import provider_net as pnet
|
||||
from neutron_lib.api.definitions import vlantransparent as vlan_apidef
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from neutron_lib.plugins import utils
|
||||
|
||||
@ -212,7 +212,7 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
LOG.warning('One or more hosts may not be configured')
|
||||
|
||||
try:
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
new_net = super(NsxDvsV2, self).create_network(context,
|
||||
network)
|
||||
self._extension_manager.process_create_network(
|
||||
@ -293,7 +293,7 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
network = self._get_network(context, id)
|
||||
dvs_id = self._dvs_get_id(network)
|
||||
bindings = nsx_db.get_network_bindings(context.session, id)
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
nsx_db.delete_network_bindings(context.session, id)
|
||||
super(NsxDvsV2, self).delete_network(context, id)
|
||||
try:
|
||||
@ -308,7 +308,7 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
self._dvs_delete_network(context, id)
|
||||
|
||||
def _dvs_get_network(self, context, id, fields=None):
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
# goto to the plugin DB and fetch the network
|
||||
network = self._get_network(context, id)
|
||||
# Don't do field selection here otherwise we won't be able
|
||||
@ -325,7 +325,7 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
filters = filters or {}
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
networks = (
|
||||
super(NsxDvsV2, self).get_networks(
|
||||
context, filters, fields, sorts,
|
||||
@ -340,7 +340,7 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
net_attrs = network['network']
|
||||
providernet._raise_if_updates_provider_attributes(net_attrs)
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
net_res = super(NsxDvsV2, self).update_network(context, id,
|
||||
network)
|
||||
self._extension_manager.process_update_network(context, net_attrs,
|
||||
@ -374,7 +374,7 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
# shared network that is not owned by the tenant.
|
||||
port_data = port['port']
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# First we allocate port in neutron database
|
||||
neutron_db = super(NsxDvsV2, self).create_port(context, port)
|
||||
self._extension_manager.process_create_port(
|
||||
@ -439,7 +439,7 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
port)
|
||||
has_addr_pairs = self._check_update_has_allowed_address_pairs(port)
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
ret_port = super(NsxDvsV2, self).update_port(
|
||||
context, id, port)
|
||||
# Save current mac learning state to check whether it's
|
||||
@ -497,7 +497,7 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
"""
|
||||
neutron_db_port = self.get_port(context, id)
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# metadata_dhcp_host_route
|
||||
self.handle_port_metadata_access(
|
||||
context, neutron_db_port, is_delete=True)
|
||||
@ -509,7 +509,7 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
filters = filters or {}
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
ports = (
|
||||
super(NsxDvsV2, self).get_ports(
|
||||
context, filters, fields, sorts,
|
||||
|
@ -20,7 +20,7 @@ from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import context as n_context
|
||||
from neutron_lib.db import api as lib_db_api
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import utils as db_utils
|
||||
from neutron_lib.plugins import constants as plugin_constants
|
||||
from neutron_lib.plugins import directory
|
||||
@ -33,7 +33,6 @@ from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import agents_db
|
||||
from neutron.db import agentschedulers_db
|
||||
from neutron.db import allowedaddresspairs_db as addr_pair_db
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db.availability_zone import router as router_az_db
|
||||
from neutron.db import external_net_db
|
||||
from neutron.db import extradhcpopt_db
|
||||
@ -364,7 +363,7 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
p = self._get_plugin_from_project(context, tenant_id)
|
||||
return p.create_network(context, network)
|
||||
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
@db_api.retry_if_session_inactive()
|
||||
def create_network_bulk(self, context, networks):
|
||||
#Implement create bulk so that the plugin calculation will be done once
|
||||
objects = []
|
||||
@ -378,7 +377,7 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
|
||||
# create all networks one by one
|
||||
try:
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
for item in items:
|
||||
objects.append(p.create_network(context, item))
|
||||
except Exception:
|
||||
@ -426,7 +425,7 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
req_p = self._get_plugin_for_request(context, filters,
|
||||
keys=['shared'])
|
||||
filters = filters or {}
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
networks = (
|
||||
super(NsxTVDPlugin, self).get_networks(
|
||||
context, filters, fields, sorts,
|
||||
@ -485,7 +484,7 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
'network_id',
|
||||
'fixed_ips'])
|
||||
filters = filters or {}
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
ports = (
|
||||
super(NsxTVDPlugin, self).get_ports(
|
||||
context, filters, fields, sorts,
|
||||
@ -823,7 +822,7 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
# get the core plugin as this is a static method with no 'self'
|
||||
plugin = directory.get_plugin()
|
||||
p = plugin._get_plugin_from_project(ctx, netdb['tenant_id'])
|
||||
with db_api.context_manager.writer.using(ctx):
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
p._extension_manager.extend_network_dict(
|
||||
ctx.session, netdb, result)
|
||||
|
||||
@ -834,7 +833,7 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
# get the core plugin as this is a static method with no 'self'
|
||||
plugin = directory.get_plugin()
|
||||
p = plugin._get_plugin_from_project(ctx, portdb['tenant_id'])
|
||||
with db_api.context_manager.writer.using(ctx):
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
p._extension_manager.extend_port_dict(
|
||||
ctx.session, portdb, result)
|
||||
|
||||
@ -845,7 +844,7 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
# get the core plugin as this is a static method with no 'self'
|
||||
plugin = directory.get_plugin()
|
||||
p = plugin._get_plugin_from_project(ctx, subnetdb['tenant_id'])
|
||||
with db_api.context_manager.writer.using(ctx):
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
p._extension_manager.extend_subnet_dict(
|
||||
ctx.session, subnetdb, result)
|
||||
|
||||
|
@ -43,7 +43,6 @@ from neutron.db import _model_query as model_query
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import agentschedulers_db
|
||||
from neutron.db import allowedaddresspairs_db as addr_pair_db
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.db import dns_db
|
||||
from neutron.db import external_net_db
|
||||
@ -68,6 +67,7 @@ from neutron_lib.api.definitions import extraroute as xroute_apidef
|
||||
from neutron_lib.api.definitions import multiprovidernet as mpnet_apidef
|
||||
from neutron_lib.api.definitions import portbindings as pbin
|
||||
from neutron_lib.api.definitions import provider_net as pnet
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.exceptions import extraroute as xroute_exc
|
||||
from neutron_lib.exceptions import multiprovidernet as mpnet_exc
|
||||
from neutron_lib.plugins import utils
|
||||
@ -965,7 +965,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
transport_zone_config,
|
||||
shared=net_data.get(constants.SHARED))
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
new_net = super(NsxPluginV2, self).create_network(context,
|
||||
network)
|
||||
# Process port security extension
|
||||
@ -1037,7 +1037,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
LOG.debug("Delete network complete for network: %s", id)
|
||||
|
||||
def get_network(self, context, id, fields=None):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# goto to the plugin DB and fetch the network
|
||||
network = self._get_network(context, id)
|
||||
if (self.nsx_sync_opts.always_read_status or
|
||||
@ -1057,7 +1057,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
filters = filters or {}
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
networks = (
|
||||
super(NsxPluginV2, self).get_networks(
|
||||
context, filters, fields, sorts,
|
||||
@ -1073,7 +1073,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
if network["network"].get("admin_state_up") is False:
|
||||
raise NotImplementedError(_("admin_state_up=False networks "
|
||||
"are not supported."))
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
net = super(NsxPluginV2, self).update_network(context, id, network)
|
||||
if psec.PORTSECURITY in network['network']:
|
||||
self._process_network_port_security_update(
|
||||
@ -1117,7 +1117,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
dhcp_opts = port_data.get(edo_ext.EXTRADHCPOPTS, [])
|
||||
# Set port status as 'DOWN'. This will be updated by backend sync.
|
||||
port_data['status'] = constants.PORT_STATUS_DOWN
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# First we allocate port in neutron database
|
||||
neutron_db = super(NsxPluginV2, self).create_port(context, port)
|
||||
neutron_port_id = neutron_db['id']
|
||||
@ -1188,7 +1188,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
LOG.warning("Logical switch for network %s was not "
|
||||
"found in NSX.", port_data['network_id'])
|
||||
# Put port in error on neutron DB
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
port = self._get_port(context, neutron_port_id)
|
||||
port_data['status'] = constants.PORT_STATUS_ERROR
|
||||
port['status'] = port_data['status']
|
||||
@ -1198,7 +1198,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error("Unable to create port or set port "
|
||||
"attachment in NSX.")
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
self.ipam.delete_port(context, neutron_port_id)
|
||||
# this extra lookup is necessary to get the
|
||||
# latest db model for the extension functions
|
||||
@ -1215,7 +1215,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
port)
|
||||
has_addr_pairs = self._check_update_has_allowed_address_pairs(port)
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
ret_port = super(NsxPluginV2, self).update_port(
|
||||
context, id, port)
|
||||
|
||||
@ -1363,7 +1363,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
|
||||
port_delete_func(context, neutron_db_port)
|
||||
self.disassociate_floatingips(context, id)
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
queue = self._get_port_queue_bindings(context, {'port_id': [id]})
|
||||
# metadata_dhcp_host_route
|
||||
self.handle_port_metadata_access(
|
||||
@ -1376,7 +1376,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
context, neutron_db_port, action='delete_port')
|
||||
|
||||
def get_port(self, context, id, fields=None):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
if (self.nsx_sync_opts.always_read_status or
|
||||
fields and 'status' in fields):
|
||||
# Perform explicit state synchronization
|
||||
@ -1388,7 +1388,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
return super(NsxPluginV2, self).get_port(context, id, fields)
|
||||
|
||||
def get_router(self, context, id, fields=None):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
if (self.nsx_sync_opts.always_read_status or
|
||||
fields and 'status' in fields):
|
||||
db_router = self._get_router(context, id)
|
||||
@ -1489,10 +1489,10 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
lrouter = self._create_lrouter(context, r, nexthop)
|
||||
# TODO(salv-orlando): Deal with backend object removal in case
|
||||
# of db failures
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# Transaction nesting is needed to avoid foreign key violations
|
||||
# when processing the distributed router binding
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
router_db = l3_db_models.Router(
|
||||
id=neutron_router_id,
|
||||
tenant_id=tenant_id,
|
||||
@ -1579,7 +1579,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
# object is not found in the underlying backend
|
||||
except n_exc.NotFound:
|
||||
# Put the router in ERROR status
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
router_db = self._get_router(context, router_id)
|
||||
router_db['status'] = constants.NET_STATUS_ERROR
|
||||
raise nsx_exc.NsxPluginException(
|
||||
@ -1611,7 +1611,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
routerlib.delete_lrouter(self.cluster, nsx_router_id)
|
||||
|
||||
def delete_router(self, context, router_id):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# NOTE(salv-orlando): These checks will be repeated anyway when
|
||||
# calling the superclass. This is wasteful, but is the simplest
|
||||
# way of ensuring a consistent removal of the router both in
|
||||
@ -2095,7 +2095,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
"""
|
||||
# Ensure the default gateway in the config file is in sync with the db
|
||||
self._ensure_default_network_gateway()
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
try:
|
||||
super(NsxPluginV2, self).delete_network_gateway(
|
||||
context, gateway_id)
|
||||
@ -2161,7 +2161,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
new_status=None, is_create=False):
|
||||
LOG.error("Rolling back database changes for gateway device %s "
|
||||
"because of an error in the NSX backend", device_id)
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
query = model_query.query_with_hooks(
|
||||
context, nsx_models.NetworkGatewayDevice).filter(
|
||||
nsx_models.NetworkGatewayDevice.id == device_id)
|
||||
@ -2197,7 +2197,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
nsx_res['uuid'])
|
||||
|
||||
# set NSX GW device in neutron database and update status
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
query = model_query.query_with_hooks(
|
||||
context, nsx_models.NetworkGatewayDevice).filter(
|
||||
nsx_models.NetworkGatewayDevice.id == neutron_id)
|
||||
@ -2236,7 +2236,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
device_status = nsx_utils.get_nsx_device_status(self.cluster,
|
||||
nsx_id)
|
||||
# update status
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
query = model_query.query_with_hooks(
|
||||
context, nsx_models.NetworkGatewayDevice).filter(
|
||||
nsx_models.NetworkGatewayDevice.id == neutron_id)
|
||||
@ -2271,7 +2271,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
device_status = nsx_utils.get_nsx_device_status(self.cluster, nsx_id)
|
||||
# TODO(salv-orlando): Asynchronous sync for gateway device status
|
||||
# Update status in database
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
query = model_query.query_with_hooks(
|
||||
context, nsx_models.NetworkGatewayDevice).filter(
|
||||
nsx_models.NetworkGatewayDevice.id == device_id)
|
||||
@ -2292,7 +2292,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
nsx_statuses = nsx_utils.get_nsx_device_statuses(self.cluster,
|
||||
tenant_id)
|
||||
# Update statuses in database
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
for device in devices:
|
||||
new_status = nsx_statuses.get(device['nsx_id'])
|
||||
if new_status:
|
||||
@ -2367,7 +2367,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
neutron_id = str(uuidutils.generate_uuid())
|
||||
nsx_secgroup = secgrouplib.create_security_profile(
|
||||
self.cluster, tenant_id, neutron_id, s)
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
s['id'] = neutron_id
|
||||
sec_group = super(NsxPluginV2, self).create_security_group(
|
||||
context, security_group, default_sg)
|
||||
@ -2404,7 +2404,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
|
||||
:param security_group_id: security group rule to remove.
|
||||
"""
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
security_group = super(NsxPluginV2, self).get_security_group(
|
||||
context, security_group_id)
|
||||
if not security_group:
|
||||
@ -2476,7 +2476,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
|
||||
# TODO(arosen) is there anyway we could avoid having the update of
|
||||
# the security group rules in nsx outside of this transaction?
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
security_group_id = self._validate_security_group_rules(
|
||||
context, security_group_rules)
|
||||
# Check to make sure security group exists
|
||||
@ -2506,7 +2506,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
"""Delete a security group rule
|
||||
:param sgrid: security group id to remove.
|
||||
"""
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# determine security profile id
|
||||
security_group_rule = (
|
||||
super(NsxPluginV2, self).get_security_group_rule(
|
||||
|
@ -24,7 +24,6 @@ import webob.exc
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import agentschedulers_db
|
||||
from neutron.db import allowedaddresspairs_db as addr_pair_db
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import dns_db
|
||||
from neutron.db import external_net_db
|
||||
from neutron.db import extradhcpopt_db
|
||||
@ -51,6 +50,7 @@ from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants as const
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import utils as db_utils
|
||||
from neutron_lib import exceptions as n_exc
|
||||
|
||||
@ -292,7 +292,7 @@ class NsxPolicyPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
self._validate_external_net_create(net_data)
|
||||
|
||||
# Create the neutron network
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# Create network in Neutron
|
||||
created_net = super(NsxPolicyPlugin, self).create_network(
|
||||
context, network)
|
||||
@ -322,7 +322,7 @@ class NsxPolicyPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
return created_net
|
||||
|
||||
def delete_network(self, context, network_id):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
self._process_l3_delete(context, network_id)
|
||||
super(NsxPolicyPlugin, self).delete_network(
|
||||
context, network_id)
|
||||
@ -354,7 +354,7 @@ class NsxPolicyPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
return updated_net
|
||||
|
||||
def get_network(self, context, id, fields=None):
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
# Get network from Neutron database
|
||||
network = self._get_network(context, id)
|
||||
# Don't do field selection here otherwise we won't be able to add
|
||||
@ -367,7 +367,7 @@ class NsxPolicyPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
page_reverse=False):
|
||||
# Get networks from Neutron database
|
||||
filters = filters or {}
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
networks = (
|
||||
super(NsxPolicyPlugin, self).get_networks(
|
||||
context, filters, fields, sorts,
|
||||
@ -460,7 +460,7 @@ class NsxPolicyPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
self._validate_max_ips_per_port(port_data.get('fixed_ips', []),
|
||||
port_data.get('device_owner'))
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
is_external_net = self._network_is_external(
|
||||
context, port_data['network_id'])
|
||||
if is_external_net:
|
||||
@ -514,7 +514,7 @@ class NsxPolicyPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
pass
|
||||
|
||||
def update_port(self, context, id, port):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# get the original port, and keep it honest as it is later used
|
||||
# for notifications
|
||||
original_port = super(NsxPolicyPlugin, self).get_port(context, id)
|
||||
@ -572,7 +572,7 @@ class NsxPolicyPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
page_reverse=False):
|
||||
filters = filters or {}
|
||||
self._update_filters_with_sec_group(context, filters)
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
ports = (
|
||||
super(NsxPolicyPlugin, self).get_ports(
|
||||
context, filters, fields, sorts,
|
||||
@ -601,7 +601,7 @@ class NsxPolicyPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
def create_router(self, context, router):
|
||||
r = router['router']
|
||||
gw_info = self._extract_external_gw(context, router, is_extract=True)
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
router = super(NsxPolicyPlugin, self).create_router(
|
||||
context, router)
|
||||
router_db = self._get_router(context, router['id'])
|
||||
@ -1041,7 +1041,7 @@ class NsxPolicyPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
self._create_project_domain(project_id)
|
||||
|
||||
# create the Neutron SG
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
if secgroup.get(provider_sg.PROVIDER) is True:
|
||||
secgroup_db = self.create_provider_security_group(
|
||||
context, security_group)
|
||||
@ -1086,7 +1086,7 @@ class NsxPolicyPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
sg_data = security_group['security_group']
|
||||
|
||||
# update the neutron security group
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
secgroup_res = super(NsxPolicyPlugin, self).update_security_group(
|
||||
context, sg_id, security_group)
|
||||
self._process_security_group_properties_update(
|
||||
@ -1150,7 +1150,7 @@ class NsxPolicyPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
sg_id = example_rule['security_group_id']
|
||||
self._prevent_non_admin_edit_provider_sg(context, sg_id)
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
rules_db = (super(NsxPolicyPlugin,
|
||||
self).create_security_group_rule_bulk_native(
|
||||
context, security_group_rules))
|
||||
|
@ -38,7 +38,7 @@ from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import context as n_context
|
||||
from neutron_lib.db import api as lib_db_api
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import constants as db_const
|
||||
from neutron_lib.db import utils as db_utils
|
||||
from neutron_lib import exceptions as n_exc
|
||||
@ -69,7 +69,6 @@ from neutron.common import utils as n_utils
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import agents_db
|
||||
from neutron.db import allowedaddresspairs_db as addr_pair_db
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db.availability_zone import router as router_az_db
|
||||
from neutron.db import dns_db
|
||||
from neutron.db import external_net_db
|
||||
@ -1343,7 +1342,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
predefined = False
|
||||
sg_policy_id, predefined = self._prepare_spoofguard_policy(
|
||||
network_type, net_data, net_morefs)
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
new_net = super(NsxVPluginV2, self).create_network(context,
|
||||
network)
|
||||
self._extension_manager.process_create_network(
|
||||
@ -1567,7 +1566,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
'Reason: %(e)s',
|
||||
{'port_id': port_id, 'e': e})
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
self._process_l3_delete(context, id)
|
||||
# We would first delete subnet db if the backend dhcp service is
|
||||
# deleted in case of entering delete_subnet logic and retrying
|
||||
@ -1606,7 +1605,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
context, net['id'])
|
||||
|
||||
def get_network(self, context, id, fields=None):
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
# goto to the plugin DB and fetch the network
|
||||
network = self._get_network(context, id)
|
||||
# Don't do field selection here otherwise we won't be able
|
||||
@ -1620,7 +1619,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
filters = filters or {}
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
networks = (
|
||||
super(NsxVPluginV2, self).get_networks(
|
||||
context, filters, fields, sorts,
|
||||
@ -1762,7 +1761,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
if updated_morefs:
|
||||
net_morefs = list(new_dvs_pg_mappings.values())
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
net_res = super(NsxVPluginV2, self).update_network(context, id,
|
||||
network)
|
||||
self._extension_manager.process_update_network(context, net_attrs,
|
||||
@ -1876,7 +1875,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
filter(models_v2.Port.mac_address == mac_address).
|
||||
count())
|
||||
|
||||
@lib_db_api.retry_db_errors
|
||||
@db_api.retry_db_errors
|
||||
def base_create_port(self, context, port):
|
||||
created_port = super(NsxVPluginV2, self).create_port(context, port)
|
||||
self._extension_manager.process_create_port(
|
||||
@ -1937,7 +1936,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
direct_vnic_type = self._validate_port_vnic_type(
|
||||
context, port_data, port_data['network_id'])
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# First we allocate port in neutron database
|
||||
neutron_db = super(NsxVPluginV2, self).create_port(context, port)
|
||||
self._extension_manager.process_create_port(
|
||||
@ -2290,7 +2289,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
"mac_learning")
|
||||
raise n_exc.InvalidInput(error_message=err_msg)
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
ret_port = super(NsxVPluginV2, self).update_port(
|
||||
context, id, port)
|
||||
self._extension_manager.process_update_port(
|
||||
@ -2528,7 +2527,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
page_reverse=False):
|
||||
filters = filters or {}
|
||||
self._update_filters_with_sec_group(context, filters)
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
ports = (
|
||||
super(NsxVPluginV2, self).get_ports(
|
||||
context, filters, fields, sorts,
|
||||
@ -2624,7 +2623,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
expected_count=1)
|
||||
|
||||
self.disassociate_floatingips(context, id)
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
super(NsxVPluginV2, self).delete_port(context, id)
|
||||
|
||||
# deleting the dhcp binding anyway
|
||||
@ -2654,7 +2653,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
with locking.LockManager.get_lock(network_id):
|
||||
with locking.LockManager.get_lock('nsx-dhcp-edge-pool'):
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
self.base_delete_subnet(context, id)
|
||||
|
||||
if subnet['enable_dhcp']:
|
||||
@ -3260,7 +3259,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
gw_info = self._extract_external_gw(context, router)
|
||||
lrouter = super(NsxVPluginV2, self).create_router(context, router)
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
router_db = self._get_router(context, lrouter['id'])
|
||||
self._process_extra_attr_router_create(context, router_db, r)
|
||||
self._process_nsx_router_create(context, router_db, r)
|
||||
@ -3272,7 +3271,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.delete_router(context, lrouter['id'])
|
||||
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
lrouter = super(NsxVPluginV2, self).get_router(context,
|
||||
lrouter['id'])
|
||||
try:
|
||||
@ -3296,7 +3295,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
self.delete_router(context, lrouter['id'])
|
||||
|
||||
# re-read the router with the updated data, and return it
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
return self.get_router(context, lrouter['id'])
|
||||
|
||||
def _validate_router_migration(self, context, router_id,
|
||||
@ -3364,7 +3363,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
old_router_driver.detach_router(context, router_id, router)
|
||||
|
||||
# update the router-type
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
router_db = self._get_router(context, router_id)
|
||||
self._process_nsx_router_create(
|
||||
context, router_db, router['router'])
|
||||
@ -3400,7 +3399,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
return router_driver.update_router(context, router_id, router)
|
||||
|
||||
def _check_router_in_use(self, context, router_id):
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
# Ensure that the router is not used
|
||||
router_filter = {'router_id': [router_id]}
|
||||
fips = self.get_floatingips_count(context.elevated(),
|
||||
@ -4260,7 +4259,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
sg_id = sg_data["id"] = str(uuidutils.generate_uuid())
|
||||
self._validate_security_group(context, sg_data, default_sg)
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
is_provider = True if sg_data.get(provider_sg.PROVIDER) else False
|
||||
is_policy = True if sg_data.get(sg_policy.POLICY) else False
|
||||
if is_provider or is_policy:
|
||||
@ -4571,7 +4570,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
try:
|
||||
# Save new rules in Database, including mappings between Nsx rules
|
||||
# and Neutron security-groups rules
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
if create_base:
|
||||
new_rule_list = super(
|
||||
NsxVPluginV2,
|
||||
|
@ -26,6 +26,7 @@ from neutron_lib.api.definitions import port_security as psec
|
||||
from neutron_lib.api import extensions
|
||||
from neutron_lib.api import faults
|
||||
from neutron_lib.api.validators import availability_zone as az_validator
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import utils as db_utils
|
||||
from neutron_lib.exceptions import allowedaddresspairs as addr_exc
|
||||
from neutron_lib.exceptions import l3 as l3_exc
|
||||
@ -42,7 +43,6 @@ from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import agents_db
|
||||
from neutron.db import agentschedulers_db
|
||||
from neutron.db import allowedaddresspairs_db as addr_pair_db
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db.availability_zone import router as router_az_db
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.db import dns_db
|
||||
@ -1296,7 +1296,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
|
||||
try:
|
||||
rollback_network = False
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# Create network in Neutron
|
||||
created_net = super(NsxV3Plugin, self).create_network(context,
|
||||
network)
|
||||
@ -1434,7 +1434,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
first_try = True
|
||||
while True:
|
||||
try:
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
self._process_l3_delete(context, network_id)
|
||||
return super(NsxV3Plugin, self).delete_network(
|
||||
context, network_id)
|
||||
@ -1889,7 +1889,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
collection = "%ss" % resource
|
||||
items = request_items[collection]
|
||||
try:
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
for item in items:
|
||||
obj_creator = getattr(self, 'create_%s' % resource)
|
||||
obj = obj_creator(context, item)
|
||||
@ -2213,7 +2213,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
get_network_policy_id(context, network['id']))
|
||||
|
||||
def get_network(self, context, id, fields=None):
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
# Get network from Neutron database
|
||||
network = self._get_network(context, id)
|
||||
# Don't do field selection here otherwise we won't be able to add
|
||||
@ -2227,7 +2227,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
page_reverse=False):
|
||||
# Get networks from Neutron database
|
||||
filters = filters or {}
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
networks = (
|
||||
super(NsxV3Plugin, self).get_networks(
|
||||
context, filters, fields, sorts,
|
||||
@ -2540,7 +2540,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
for fixed_ip in fixed_ips:
|
||||
if netaddr.IPNetwork(fixed_ip['ip_address']).version != 4:
|
||||
continue
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
subnet = self.get_subnet(context, fixed_ip['subnet_id'])
|
||||
if subnet['enable_dhcp']:
|
||||
ips.append(fixed_ip)
|
||||
@ -2899,7 +2899,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
context, port_data, port_data['network_id'],
|
||||
projectpluginmap.NsxPlugins.NSX_T)
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
neutron_db = self.base_create_port(context, port)
|
||||
port["port"].update(neutron_db)
|
||||
|
||||
@ -3381,7 +3381,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
validate_port_sec = False
|
||||
break
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# get the original port, and keep it honest as it is later used
|
||||
# for notifications
|
||||
original_port = super(NsxV3Plugin, self).get_port(context, id)
|
||||
@ -3476,7 +3476,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
LOG.exception("Unable to update NSX backend, rolling back "
|
||||
"changes on neutron")
|
||||
with excutils.save_and_reraise_exception(reraise=False):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
super(NsxV3Plugin, self).update_port(
|
||||
context, id, {'port': original_port})
|
||||
|
||||
@ -3549,7 +3549,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
page_reverse=False):
|
||||
filters = filters or {}
|
||||
self._update_filters_with_sec_group(context, filters)
|
||||
with db_api.context_manager.reader.using(context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
ports = (
|
||||
super(NsxV3Plugin, self).get_ports(
|
||||
context, filters, fields, sorts,
|
||||
@ -3847,7 +3847,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
router['id'],
|
||||
{'router': {az_def.AZ_HINTS: az_hints}})
|
||||
router_db = self._get_router(context, r['id'])
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
self._process_extra_attr_router_create(context, router_db, r)
|
||||
# Create backend entries here in case neutron DB exception
|
||||
# occurred during super.create_router(), which will cause
|
||||
@ -4054,7 +4054,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
|
||||
return self._update_router_wrapper(context, router_id, router)
|
||||
except nsx_lib_exc.ResourceNotFound:
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
router_db = self._get_router(context, router_id)
|
||||
router_db['status'] = const.NET_STATUS_ERROR
|
||||
raise nsx_exc.NsxPluginException(
|
||||
@ -4785,7 +4785,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
# REVISIT(roeyc): Ideally, at this point we need not be under an
|
||||
# open db transactions, however, unittests fail if omitting
|
||||
# subtransactions=True.
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# NOTE(arosen): a neutron security group be default adds rules
|
||||
# that allow egress traffic. We do not want this behavior for
|
||||
# provider security_groups
|
||||
@ -4861,7 +4861,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
orig_secgroup = self.get_security_group(
|
||||
context, id, fields=['id', 'name', 'description'])
|
||||
self._prevent_non_admin_edit_provider_sg(context, id)
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
secgroup_res = (
|
||||
super(NsxV3Plugin, self).update_security_group(context, id,
|
||||
security_group))
|
||||
@ -4906,7 +4906,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
r['security_group_rule'].get('id') or
|
||||
uuidutils.generate_uuid())
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
|
||||
rules_db = (super(NsxV3Plugin,
|
||||
self).create_security_group_rule_bulk_native(
|
||||
|
@ -15,13 +15,13 @@
|
||||
import re
|
||||
import xml.etree.ElementTree as et
|
||||
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db.models import securitygroup as sg_models
|
||||
from neutron.db import models_v2
|
||||
from neutron.db import securitygroups_db
|
||||
from neutron.extensions import securitygroup as ext_sg
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib import context as n_context
|
||||
from neutron_lib.db import api as db_api
|
||||
from oslo_log import log as logging
|
||||
|
||||
from vmware_nsx.common import utils as com_utils
|
||||
@ -96,7 +96,7 @@ class NeutronSecurityGroupDB(
|
||||
return False
|
||||
|
||||
def delete_security_group_section_mapping(self, sg_id):
|
||||
with db_api.context_manager.writer.using(self.context):
|
||||
with db_api.CONTEXT_WRITER.using(self.context):
|
||||
fw_mapping = self.context.session.query(
|
||||
nsxv_models.NsxvSecurityGroupSectionMapping).filter_by(
|
||||
neutron_id=sg_id).one_or_none()
|
||||
@ -104,7 +104,7 @@ class NeutronSecurityGroupDB(
|
||||
self.context.session.delete(fw_mapping)
|
||||
|
||||
def delete_security_group_backend_mapping(self, sg_id):
|
||||
with db_api.context_manager.writer.using(self.context):
|
||||
with db_api.CONTEXT_WRITER.using(self.context):
|
||||
sg_mapping = self.context.session.query(
|
||||
nsx_models.NeutronNsxSecurityGroupMapping).filter_by(
|
||||
neutron_id=sg_id).one_or_none()
|
||||
|
@ -12,11 +12,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import common_db_mixin as common_db
|
||||
from neutron.db import securitygroups_db
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib import context as neutron_context
|
||||
from neutron_lib.db import api as db_api
|
||||
from oslo_log import log as logging
|
||||
|
||||
from vmware_nsx.db import db as nsx_db
|
||||
@ -67,7 +67,7 @@ class NeutronSecurityGroupApi(securitygroups_db.SecurityGroupDbMixin,
|
||||
return [b['port_id'] for b in secgroups_bindings]
|
||||
|
||||
def delete_security_group_section_mapping(self, sg_id):
|
||||
with db_api.context_manager.writer.using(self.context):
|
||||
with db_api.CONTEXT_WRITER.using(self.context):
|
||||
fw_mapping = self.context.session.query(
|
||||
nsx_models.NeutronNsxFirewallSectionMapping).filter_by(
|
||||
neutron_id=sg_id).one_or_none()
|
||||
@ -75,7 +75,7 @@ class NeutronSecurityGroupApi(securitygroups_db.SecurityGroupDbMixin,
|
||||
self.context.session.delete(fw_mapping)
|
||||
|
||||
def delete_security_group_backend_mapping(self, sg_id):
|
||||
with db_api.context_manager.writer.using(self.context):
|
||||
with db_api.CONTEXT_WRITER.using(self.context):
|
||||
sg_mapping = self.context.session.query(
|
||||
nsx_models.NeutronNsxSecurityGroupMapping).filter_by(
|
||||
neutron_id=sg_id).one_or_none()
|
||||
|
@ -15,12 +15,12 @@
|
||||
import mock
|
||||
import webob.exc
|
||||
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.db import securitygroups_db
|
||||
from neutron.extensions import securitygroup as ext_sg
|
||||
from neutron.tests.unit.extensions import test_securitygroup
|
||||
from neutron_lib import context
|
||||
from neutron_lib.db import api as db_api
|
||||
|
||||
from vmware_nsx.db import extended_security_group
|
||||
from vmware_nsx.extensions import providersecuritygroup as provider_sg
|
||||
@ -45,7 +45,7 @@ class ProviderSecurityGroupTestPlugin(
|
||||
|
||||
def create_security_group(self, context, security_group, default_sg=False):
|
||||
secgroup = security_group['security_group']
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# NOTE(arosen): a neutron security group by default adds rules
|
||||
# that allow egress traffic. We do not want this behavior for
|
||||
# provider security_groups
|
||||
@ -67,7 +67,7 @@ class ProviderSecurityGroupTestPlugin(
|
||||
def create_port(self, context, port, l2gw_port_check=False):
|
||||
port_data = port['port']
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
self._ensure_default_security_group_on_port(context, port)
|
||||
(sgids, provider_groups) = self._get_port_security_groups_lists(
|
||||
context, port)
|
||||
@ -86,7 +86,7 @@ class ProviderSecurityGroupTestPlugin(
|
||||
return port_data
|
||||
|
||||
def update_port(self, context, id, port):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
original_port = super(ProviderSecurityGroupTestPlugin,
|
||||
self).get_port(context, id)
|
||||
updated_port = super(ProviderSecurityGroupTestPlugin,
|
||||
|
@ -18,12 +18,12 @@ import webob.exc
|
||||
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.db import securitygroups_db
|
||||
from neutron.extensions import securitygroup as ext_sg
|
||||
from neutron.tests.unit.extensions import test_securitygroup
|
||||
from neutron_lib import constants as const
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.plugins import directory
|
||||
|
||||
from vmware_nsx.db import extended_security_group_rule as ext_rule_db
|
||||
@ -50,7 +50,7 @@ class ExtendedRuleTestPlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
def create_security_group_rule(self, context, security_group_rule):
|
||||
rule = security_group_rule['security_group_rule']
|
||||
self._check_local_ip_prefix(context, rule)
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
res = super(ExtendedRuleTestPlugin,
|
||||
self).create_security_group_rule(
|
||||
context, security_group_rule)
|
||||
|
@ -17,11 +17,11 @@ from oslo_config import cfg
|
||||
from oslo_db import exception as d_exc
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.tests.unit.db import test_db_base_plugin_v2 as test_db_plugin
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import context as neutron_context
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.plugins import directory
|
||||
|
||||
from vmware_nsx.db import vnic_index_db
|
||||
@ -49,7 +49,7 @@ class VnicIndexTestPlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
self._set_port_vnic_index_mapping(
|
||||
context, id, device_id, vnic_idx)
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
p = port['port']
|
||||
ret_port = super(VnicIndexTestPlugin, self).update_port(
|
||||
context, id, port)
|
||||
@ -65,7 +65,7 @@ class VnicIndexTestPlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
vnic_idx = port_db.get(vnicidx.VNIC_INDEX)
|
||||
if validators.is_attr_set(vnic_idx):
|
||||
self._delete_port_vnic_index_mapping(context, id)
|
||||
with db_api.context_manager.writer.using(context):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
super(VnicIndexTestPlugin, self).delete_port(context, id)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user