def create_allocation(self, context, values): allocation = models.Allocation() allocation.update(values) try: allocation.save() except db_exc.DBDuplicateEntry as e: fields = {c: values[c] for c in e.columns} raise exception.UniqueConstraintViolated(fields=fields) return allocation
def create_inventory(self, context, provider_id, values): values['resource_provider_id'] = provider_id inventory = models.Inventory() inventory.update(values) try: inventory.save() except db_exc.DBDuplicateEntry as e: fields = {c: values[c] for c in e.columns} raise exception.UniqueConstraintViolated(fields=fields) return inventory