}
volume = self.db.volume_create(context, options)
+
+ QUOTAS.commit(context, reservations)
+
self._cast_create_volume(context, volume['id'], snapshot_id,
- image_id, reservations)
+ image_id)
return volume
def _cast_create_volume(self, context, volume_id, snapshot_id,
- image_id, reservations):
+ image_id):
# NOTE(Rongze Zhu): It is a simple solution for bug 1008866
# If snapshot_id is set, make the call create volume directly to
{"method": "create_volume",
"args": {"volume_id": volume_id,
"snapshot_id": snapshot_id,
- "image_id": image_id,
- "reservations": reservations}})
+ "image_id": image_id}})
else:
rpc.cast(context,
FLAGS.scheduler_topic,
"args": {"topic": FLAGS.volume_topic,
"volume_id": volume_id,
"snapshot_id": snapshot_id,
- "image_id": image_id,
- "reservations": reservations}})
+ "image_id": image_id}})
@wrap_check_policy
def delete(self, context, volume, force=False):
volume_id = volume['id']
if not volume['host']:
# NOTE(vish): scheduling failed, so delete it
+ # Note(zhiteng): update volume quota reservation
+ try:
+ reservations = QUOTAS.reserve(context, volumes=-1,
+ gigabytes=-volume['size'])
+ except Exception:
+ reservations = None
+ LOG.exception(_("Failed to update quota for deleting volume"))
+
self.db.volume_destroy(context, volume_id)
+
+ if reservations:
+ QUOTAS.commit(context, reservations)
return
if not force and volume['status'] not in ["available", "error"]:
msg = _("Volume status must be available or error")
LOG.debug(_('Resuming any in progress delete operations'))
for volume in volumes:
if volume['status'] == 'deleting':
- LOG.info(_('Resuming delete on volume: %s' % volume['id']))
+ LOG.info(_('Resuming delete on volume: %s') % volume['id'])
self.delete_volume(ctxt, volume['id'])
def create_volume(self, context, volume_id, snapshot_id=None,
- image_id=None, reservations=None):
+ image_id=None):
"""Creates and exports the volume."""
context = context.elevated()
volume_ref = self.db.volume_get(context, volume_id)
if model_update:
self.db.volume_update(context, volume_ref['id'], model_update)
- # Commit the reservation
- if reservations:
- QUOTAS.commit(context, reservations)
except Exception:
with excutils.save_and_reraise_exception():
- if reservations:
- QUOTAS.rollback(context, reservations)
self.db.volume_update(context,
volume_ref['id'], {'status': 'error'})