}
volume = self.db.volume_create(context, options)
- self._cast_create_volume(context, volume['id'], snapshot_id, image_id)
+ self._cast_create_volume(context, volume['id'], snapshot_id,
+ image_id, reservations)
return volume
- def _cast_create_volume(self, context, volume_id, snapshot_id, image_id):
+ def _cast_create_volume(self, context, volume_id, snapshot_id,
+ image_id, reservations):
# 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}})
+ "image_id": image_id,
+ "reservations": reservations}})
else:
rpc.cast(context,
FLAGS.scheduler_topic,
"args": {"topic": FLAGS.volume_topic,
"volume_id": volume_id,
"snapshot_id": snapshot_id,
- "image_id": image_id}})
+ "image_id": image_id,
+ "reservations": reservations}})
@wrap_check_policy
def delete(self, context, volume, force=False):
from cinder.openstack.common import excutils
from cinder.openstack.common import importutils
from cinder.openstack.common import timeutils
+from cinder import quota
from cinder import utils
from cinder.volume import utils as volume_utils
LOG = logging.getLogger(__name__)
+QUOTAS = quota.QUOTAS
+
volume_manager_opts = [
cfg.StrOpt('volume_driver',
default='cinder.volume.driver.ISCSIDriver',
LOG.info(_("volume %s: skipping export"), volume['name'])
def create_volume(self, context, volume_id, snapshot_id=None,
- image_id=None):
+ image_id=None, reservations=None):
"""Creates and exports the volume."""
context = context.elevated()
volume_ref = self.db.volume_get(context, volume_id)
model_update = self.driver.create_export(context, volume_ref)
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'})
volume_ref['id'],
{'status': 'error_deleting'})
+ # Get reservations
+ try:
+ reservations = QUOTAS.reserve(context, volumes=-1,
+ gigabytes=-volume_ref['size'])
+ except Exception:
+ reservations = None
+ LOG.exception(_("Failed to update usages deleting volume"))
+
self.db.volume_destroy(context, volume_id)
LOG.debug(_("volume %s: deleted successfully"), volume_ref['name'])
self._notify_about_volume_usage(context, volume_ref, "delete.end")
+
+ # Commit the reservations
+ if reservations:
+ QUOTAS.commit(context, reservations)
+
return True
def create_snapshot(self, context, volume_id, snapshot_id):