Relocate _delete_expired_default_network_segment_ranges

Relocate "_delete_expired_default_network_segment_ranges" to avoid
code redundancy.

Now instead of searching all objects and deleting one by one,
"delete_objects" is used.

Trivial-Fix

Change-Id: I1753263cb15ce2988ac4ccae03b7395069f2c4e9
changes/24/739124/1
Rodolfo Alonso Hernandez 2 years ago
parent 5ce9c4d8a2
commit 6fa6e4135c
  1. 8
      neutron/plugins/ml2/drivers/helpers.py
  2. 13
      neutron/plugins/ml2/drivers/type_tunnel.py
  3. 13
      neutron/plugins/ml2/drivers/type_vlan.py

@ -15,6 +15,7 @@
import functools
from neutron_lib import context
from neutron_lib.db import api as db_api
from neutron_lib import exceptions
from neutron_lib.plugins import constants as plugin_constants
@ -151,3 +152,10 @@ class SegmentTypeDriver(BaseTypeDriver):
return alloc
raise db_exc.RetryRequest(
exceptions.NoNetworkFoundInMaximumAllowedAttempts())
@db_api.retry_db_errors
def _delete_expired_default_network_segment_ranges(self):
ctx = context.get_admin_context()
with db_api.CONTEXT_WRITER.using(ctx):
filters = {'default': True, 'network_type': self.get_type()}
ns_range.NetworkSegmentRange.delete_objects(ctx, **filters)

@ -163,19 +163,6 @@ class _TunnelTypeDriverBase(helpers.SegmentTypeDriver, metaclass=abc.ABCMeta):
range_obj.NetworkSegmentRange(ctx, **res))
new_default_range_obj.create()
@db_api.retry_db_errors
def _delete_expired_default_network_segment_ranges(self):
ctx = context.get_admin_context()
with db_api.CONTEXT_WRITER.using(ctx):
filters = {
'default': True,
'network_type': self.get_type(),
}
old_default_range_objs = range_obj.NetworkSegmentRange.get_objects(
ctx, **filters)
for obj in old_default_range_objs:
obj.delete()
@db_api.retry_db_errors
def _get_network_segment_ranges_from_db(self):
ranges = []

@ -77,19 +77,6 @@ class VlanTypeDriver(helpers.SegmentTypeDriver):
range_obj.NetworkSegmentRange(ctx, **res))
new_default_range_obj.create()
@db_api.retry_db_errors
def _delete_expired_default_network_segment_ranges(self):
ctx = context.get_admin_context()
with db_api.CONTEXT_WRITER.using(ctx):
filters = {
'default': True,
'network_type': p_const.TYPE_VLAN,
}
old_default_range_objs = range_obj.NetworkSegmentRange.get_objects(
ctx, **filters)
for obj in old_default_range_objs:
obj.delete()
def _parse_network_vlan_ranges(self):
try:
self.network_vlan_ranges = plugin_utils.parse_network_vlan_ranges(

Loading…
Cancel
Save