ビジネスコードで割当を管理する方法
1690 ワード
バックアップを作成するときに、割当使用量を変更します.
cinder.backup.api.API#create
: from cinder import quota
from cinder import quota_utils
def create(self, context, name, description, volume_id,
container, incremental=False, availability_zone=None,
force=False, snapshot_id=None):
"""Make the RPC call to create a volume backup."""
# Reserve a quota before setting volume status and backup status
try:
#
reserve_opts = {'backups': 1,
'backup_gigabytes': volume['size']}
reservations = QUOTAS.reserve(context, **reserve_opts)
except exception.OverQuota as e:
quota_utils.process_reserve_over_quota(
context, e,
resource='backups',
size=volume.size)
try:
# , quota_usage
QUOTAS.commit(context, reservations)
except Exception:
# , backup , ,
with excutils.save_and_reraise_exception():
try:
if backup and 'id' in backup:
backup.destroy()
finally:
#
QUOTAS.rollback(context, reservations)
# TODO(DuncanT): In future, when we have a generic local attach,
# this can go via the scheduler, which enables
# better load balancing and isolation of services
self.backup_rpcapi.create_backup(context, backup)
return backup