From: Jenkins Date: Fri, 20 Nov 2015 22:05:59 +0000 (+0000) Subject: Merge "Use compare-and-swap for IpamAvailabilityRange" X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=01dc4e913ea498af94964266e4403603589060f9;p=openstack-build%2Fneutron-build.git Merge "Use compare-and-swap for IpamAvailabilityRange" --- 01dc4e913ea498af94964266e4403603589060f9 diff --cc neutron/ipam/drivers/neutrondb_ipam/db_api.py index 58bb8367a,dd73841a9..4fc3c0ca2 --- a/neutron/ipam/drivers/neutrondb_ipam/db_api.py +++ b/neutron/ipam/drivers/neutrondb_ipam/db_api.py @@@ -150,9 -143,49 +143,49 @@@ class IpamSubnetManager(object) db_models.IpamAllocationPool).filter_by( id=allocation_pool_id) + def update_range(self, session, db_range, first_ip=None, last_ip=None): + """Updates db_range to have new first_ip and last_ip. + + :param session: database session + :param db_range: IpamAvailabilityRange db object + :param first_ip: first ip address in range + :param last_ip: last ip address in range + :return: count of updated rows + """ + opts = {} + if first_ip: + opts['first_ip'] = str(first_ip) + if last_ip: + opts['last_ip'] = str(last_ip) + if not opts: + raise ipam_exc.IpamAvailabilityRangeNoChanges() + try: + return session.query( + db_models.IpamAvailabilityRange).filter_by( + allocation_pool_id=db_range.allocation_pool_id).filter_by( + first_ip=db_range.first_ip).filter_by( + last_ip=db_range.last_ip).update(opts) + except orm_exc.ObjectDeletedError: + raise db_exc.RetryRequest(ipam_exc.IPAllocationFailed) + + def delete_range(self, session, db_range): + """Return count of deleted ranges + + :param session: database session + :param db_range: IpamAvailabilityRange db object + """ + try: + return session.query( + db_models.IpamAvailabilityRange).filter_by( + allocation_pool_id=db_range.allocation_pool_id).filter_by( + first_ip=db_range.first_ip).filter_by( + last_ip=db_range.last_ip).delete() + except orm_exc.ObjectDeletedError: + raise db_exc.RetryRequest(ipam_exc.IPAllocationFailed) + def create_range(self, session, allocation_pool_id, range_start, range_end): - """Create an availabilty range for a given pool. + """Create an availability range for a given pool. This method does not perform any validation on parameters; it simply persist data on the database.