Merge "Improve floating IP delete speed."
This commit is contained in:
commit
608b75e125
|
@ -63,7 +63,6 @@ import optparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
# If ../nova/__init__.py exists, add ../ to Python search path, so that
|
# If ../nova/__init__.py exists, add ../ to Python search path, so that
|
||||||
# it will override what happens to be installed in /usr/(local/)lib/python...
|
# it will override what happens to be installed in /usr/(local/)lib/python...
|
||||||
POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
|
POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
|
||||||
|
@ -396,12 +395,11 @@ class FloatingIpCommands(object):
|
||||||
@args('--ip_range', dest="ip_range", metavar='<range>', help='IP range')
|
@args('--ip_range', dest="ip_range", metavar='<range>', help='IP range')
|
||||||
def delete(self, ip_range):
|
def delete(self, ip_range):
|
||||||
"""Deletes floating ips by range"""
|
"""Deletes floating ips by range"""
|
||||||
for address in self.address_to_hosts(ip_range):
|
admin_context = context.get_admin_context()
|
||||||
try:
|
|
||||||
db.floating_ip_destroy(context.get_admin_context(),
|
ips = ({'address': str(address)}
|
||||||
str(address))
|
for address in self.address_to_hosts(ip_range))
|
||||||
except exception.FloatingIpNotFoundForAddress as ex:
|
db.floating_ip_bulk_destroy(admin_context, ips)
|
||||||
print "Warning: %s" % ex
|
|
||||||
|
|
||||||
@args('--host', dest="host", metavar='<host>', help='Host')
|
@args('--host', dest="host", metavar='<host>', help='Host')
|
||||||
def list(self, host=None):
|
def list(self, host=None):
|
||||||
|
|
|
@ -274,6 +274,11 @@ def floating_ip_bulk_create(context, ips):
|
||||||
return IMPL.floating_ip_bulk_create(context, ips)
|
return IMPL.floating_ip_bulk_create(context, ips)
|
||||||
|
|
||||||
|
|
||||||
|
def floating_ip_bulk_destroy(context, ips):
|
||||||
|
"""Destroy a lot of floating ips from the values dictionary."""
|
||||||
|
return IMPL.floating_ip_bulk_destroy(context, ips)
|
||||||
|
|
||||||
|
|
||||||
def floating_ip_create(context, values):
|
def floating_ip_create(context, values):
|
||||||
"""Create a floating ip from the values dictionary."""
|
"""Create a floating ip from the values dictionary."""
|
||||||
return IMPL.floating_ip_create(context, values)
|
return IMPL.floating_ip_create(context, values)
|
||||||
|
|
|
@ -734,6 +734,35 @@ def floating_ip_bulk_create(context, ips):
|
||||||
session.add(model)
|
session.add(model)
|
||||||
|
|
||||||
|
|
||||||
|
def _ip_range_splitter(ips):
|
||||||
|
"""Yields blocks of IPs no more than 256 elements long."""
|
||||||
|
out = []
|
||||||
|
count = 0
|
||||||
|
for ip in ips:
|
||||||
|
out.append(ip['address'])
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
if count > 255:
|
||||||
|
yield out
|
||||||
|
out = []
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
if out:
|
||||||
|
yield out
|
||||||
|
|
||||||
|
|
||||||
|
@require_context
|
||||||
|
def floating_ip_bulk_destroy(context, ips):
|
||||||
|
session = get_session()
|
||||||
|
with session.begin():
|
||||||
|
for ip_block in _ip_range_splitter(ips):
|
||||||
|
model_query(context, models.FloatingIp).\
|
||||||
|
filter(models.FloatingIp.address.in_(ip_block)).\
|
||||||
|
update({'deleted': True,
|
||||||
|
'deleted_at': timeutils.utcnow()},
|
||||||
|
synchronize_session='fetch')
|
||||||
|
|
||||||
|
|
||||||
@require_context
|
@require_context
|
||||||
def floating_ip_create(context, values, session=None):
|
def floating_ip_create(context, values, session=None):
|
||||||
if not session:
|
if not session:
|
||||||
|
@ -838,8 +867,9 @@ def floating_ip_set_auto_assigned(context, address):
|
||||||
floating_ip_ref.save(session=session)
|
floating_ip_ref.save(session=session)
|
||||||
|
|
||||||
|
|
||||||
def _floating_ip_get_all(context):
|
def _floating_ip_get_all(context, session=None):
|
||||||
return model_query(context, models.FloatingIp, read_deleted="no")
|
return model_query(context, models.FloatingIp, read_deleted="no",
|
||||||
|
session=session)
|
||||||
|
|
||||||
|
|
||||||
@require_admin_context
|
@require_admin_context
|
||||||
|
|
Loading…
Reference in New Issue