def create_snapshot(self, snapshot): volume_name = VOLUME_PREFIX + snapshot['volume_name'][-12:] snapshot_name = VOLUME_PREFIX + snapshot['name'][-12:] ret = self._cmd.create_snapshot(volume_name, snapshot_name) if ret['key'] == 303: raise exception.VolumeNotFound(volume_id=volume_name) elif ret['key'] == 503: raise exception.SnapshotLimitExceeded(allowed=4096) elif ret['key'] == 504: raise exception.SnapshotLimitExceeded(allowed=64)
def process_reserve_over_quota(context, overs, usages, quotas, size): def _consumed(name): return (usages[name]['reserved'] + usages[name]['in_use']) for over in overs: if 'gigabytes' in over: msg = _LW("Quota exceeded for %(s_pid)s, tried to create " "%(s_size)sG snapshot (%(d_consumed)dG of " "%(d_quota)dG already consumed).") LOG.warning( msg, { 's_pid': context.project_id, 's_size': size, 'd_consumed': _consumed(over), 'd_quota': quotas[over] }) raise exception.VolumeSizeExceedsAvailableQuota( requested=size, consumed=_consumed('gigabytes'), quota=quotas['gigabytes']) elif 'snapshots' in over: msg = _LW("Quota exceeded for %(s_pid)s, tried to create " "snapshot (%(d_consumed)d snapshots " "already consumed).") LOG.warning(msg, { 's_pid': context.project_id, 'd_consumed': _consumed(over) }) raise exception.SnapshotLimitExceeded(allowed=quotas[over])
def create_snapshot(self, snapshot): volume_name = self._convert_name(snapshot.volume_name) snapshot_name = self._convert_name(snapshot.name) ret = self._cmd.create_snapshot(volume_name, snapshot_name) if ret['key'] == 303: raise exception.VolumeNotFound(volume_id=volume_name) elif ret['key'] == 503: raise exception.SnapshotLimitExceeded(allowed=4096) elif ret['key'] == 504: raise exception.SnapshotLimitExceeded(allowed=64) elif ret['key'] != 0: msg = (_('Failed to create_snapshot %(snap)s on volume %(vol)s ' 'code=%(ret)s, error=%(msg)s.') % { 'vol': volume_name, 'snap': snapshot_name, 'ret': ret['key'], 'msg': ret['msg'] }) raise exception.VolumeBackendAPIException(data=msg)
def _create_snapshot(self, context, volume, name, description, force=False, metadata=None): check_policy(context, 'create_snapshot', volume) if volume['migration_status'] is not None: # Volume is migrating, wait until done msg = _("Snapshot cannot be created while volume is migrating") raise exception.InvalidVolume(reason=msg) if ((not force) and (volume['status'] != "available")): msg = _("must be available") raise exception.InvalidVolume(reason=msg) try: if CONF.no_snapshot_gb_quota: reserve_opts = {'snapshots': 1} else: reserve_opts = {'snapshots': 1, 'gigabytes': volume['size']} QUOTAS.add_volume_type_opts(context, reserve_opts, volume.get('volume_type_id')) reservations = QUOTAS.reserve(context, **reserve_opts) except exception.OverQuota as e: overs = e.kwargs['overs'] usages = e.kwargs['usages'] quotas = e.kwargs['quotas'] def _consumed(name): return (usages[name]['reserved'] + usages[name]['in_use']) for over in overs: if 'gigabytes' in over: msg = _("Quota exceeded for %(s_pid)s, tried to create " "%(s_size)sG snapshot (%(d_consumed)dG of " "%(d_quota)dG already consumed)") LOG.warn( msg % { 's_pid': context.project_id, 's_size': volume['size'], 'd_consumed': _consumed(over), 'd_quota': quotas[over] }) raise exception.VolumeSizeExceedsAvailableQuota( requested=volume['size'], consumed=_consumed('gigabytes'), quota=quotas['gigabytes']) elif 'snapshots' in over: msg = _("Quota exceeded for %(s_pid)s, tried to create " "snapshot (%(d_consumed)d snapshots " "already consumed)") LOG.warn(msg % { 's_pid': context.project_id, 'd_consumed': _consumed(over) }) raise exception.SnapshotLimitExceeded(allowed=quotas[over]) self._check_metadata_properties(metadata) options = { 'volume_id': volume['id'], 'user_id': context.user_id, 'project_id': context.project_id, 'status': "creating", 'progress': '0%', 'volume_size': volume['size'], 'display_name': name, 'display_description': description, 'volume_type_id': volume['volume_type_id'], 'encryption_key_id': volume['encryption_key_id'], 'metadata': metadata } try: snapshot = self.db.snapshot_create(context, options) QUOTAS.commit(context, reservations) except Exception: with excutils.save_and_reraise_exception(): try: self.db.snapshot_destroy(context, volume['id']) finally: QUOTAS.rollback(context, reservations) self.volume_rpcapi.create_snapshot(context, volume, snapshot) return snapshot