示例#1
0
    def _create_range(self, context, sa_range):
        with context.session.begin(subtransactions=True):
            # Validate any range-specific things, like min/max ids.
            self._validate_range(context, sa_range)

            # Check any existing ranges for this segment for collisions
            segment_id = sa_range["segment_id"]
            segment_type = sa_range["segment_type"]

            filters = {"segment_id": segment_id,
                       "segment_type": segment_type}
            existing_ranges = db_api.segment_allocation_range_find(
                context, lock_mode=True, scope=db_api.ALL, **filters)

            collides = self._check_collisions(
                (sa_range["first_id"], sa_range["last_id"]),
                [(r["first_id"], r["last_id"]) for r in existing_ranges])

            if collides:
                raise q_exc.InvalidSegmentAllocationRange(
                    msg=("The specified allocation collides with existing "
                         "range"))

            return db_api.segment_allocation_range_create(
                context, **sa_range)
示例#2
0
 def _validate_range(self, context, sa_range):
     # Validate that the range is legal and makes sense.
     try:
         first_id = sa_range["first_id"]
         last_id = sa_range["last_id"]
         first_id, last_id = (int(first_id), int(last_id))
         assert first_id >= self.VXLAN_MIN
         assert last_id <= self.VXLAN_MAX
         assert first_id <= last_id
     except Exception:
         raise q_exc.InvalidSegmentAllocationRange(
             msg="The specified allocation range is invalid")