Ejemplo n.º 1
0
 def _create_resource_delta(self, resource, reservation_id, amount):
     resource_delta = quota.ResourceDelta(self.context,
                                          resource=resource,
                                          reservation_id=reservation_id,
                                          amount=amount)
     resource_delta.create()
     return resource_delta
Ejemplo n.º 2
0
 def test_reservation_synthetic_field(self):
     res = self._create_test_reservation()
     resource = 'test-res'
     res_delta = quota.ResourceDelta(self.context,
         resource=resource, reservation_id=res.id, amount='10')
     res_delta.create()
     obj = self._test_class.get_object(self.context, id=res.id)
     self.assertEqual(res_delta, obj.resource_deltas[0])
     res_delta.delete()
     obj.update()
     # NOTE(manjeets) update on reservation should reflect
     # changes on synthetic field when it is deleted.
     obj = self._test_class.get_object(self.context, id=res.id)
     self.assertEqual([], obj.resource_deltas)
Ejemplo n.º 3
0
def create_reservation(context, tenant_id, deltas, expiration=None):
    # This method is usually called from within another transaction.
    # Consider using begin_nested
    expiration = expiration or (utcnow() + datetime.timedelta(0, 120))
    delta_objs = []
    for (resource, delta) in deltas.items():
        delta_objs.append(
            quota_obj.ResourceDelta(context, resource=resource, amount=delta))
    reserv_obj = quota_obj.Reservation(context,
                                       project_id=tenant_id,
                                       expiration=expiration,
                                       resource_deltas=delta_objs)
    reserv_obj.create()
    return ReservationInfo(
        reserv_obj['id'], reserv_obj['project_id'], reserv_obj['expiration'],
        dict((delta.resource, delta.amount)
             for delta in reserv_obj.resource_deltas))