Ejemplo n.º 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)
 def _create_segment_allocation_range(self, **kwargs):
     """Create a segment allocation range in the database."""
     sa_dict = self._make_segment_allocation_range_dict(**kwargs)
     sa_range = db_api.segment_allocation_range_create(self.context, **sa_dict)
     self.context.session.flush()
     self._populate_segment_allocation_range(sa_range)
     return sa_range
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def _create_segment_allocation_range(self, **kwargs):
     """Create a segment allocation range in the database."""
     sa_dict = self._make_segment_allocation_range_dict(**kwargs)
     sa_range = db_api.segment_allocation_range_create(
         self.context, **sa_dict)
     self.context.session.flush()
     self._populate_segment_allocation_range(sa_range)
     return sa_range