Quotas fix
This commit is contained in:
parent
01ee3a3279
commit
a41117df05
manila/share
@ -26,7 +26,7 @@ from manila.db import base
|
||||
from manila import exception
|
||||
from manila import flags
|
||||
from manila.image import glance
|
||||
from manila.openstack.common import log as logging
|
||||
from manila.openstack.common import log as logging, excutils
|
||||
from manila.openstack.common import rpc
|
||||
from manila.openstack.common import timeutils
|
||||
import manila.policy
|
||||
@ -153,7 +153,15 @@ class API(base.Base):
|
||||
'share_proto': share_proto,
|
||||
}
|
||||
|
||||
share = self.db.share_create(context, options)
|
||||
try:
|
||||
share = self.db.share_create(context, options)
|
||||
QUOTAS.commit(context, reservations)
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
try:
|
||||
self.db.share_delete(context, share['id'])
|
||||
finally:
|
||||
QUOTAS.rollback(context, reservations)
|
||||
|
||||
request_spec = {'share_properties': options,
|
||||
'share_proto': share_proto,
|
||||
@ -175,10 +183,25 @@ class API(base.Base):
|
||||
|
||||
def delete(self, context, share):
|
||||
"""Delete share."""
|
||||
if context.is_admin and context.project_id != share['project_id']:
|
||||
project_id = share['project_id']
|
||||
else:
|
||||
project_id = context.project_id
|
||||
|
||||
share_id = share['id']
|
||||
if not share['host']:
|
||||
# NOTE(rushiagr): scheduling failed, delete
|
||||
self.db.share_delete(context, share_id)
|
||||
try:
|
||||
reservations = QUOTAS.reserve(context,
|
||||
project_id=project_id,
|
||||
volumes=-1,
|
||||
gigabytes=-share['size'])
|
||||
except Exception:
|
||||
reservations = None
|
||||
LOG.exception(_("Failed to update quota for deleting volume"))
|
||||
self.db.share_delete(context.elevated(), share_id)
|
||||
|
||||
if reservations:
|
||||
QUOTAS.commit(context, reservations, project_id=project_id)
|
||||
return
|
||||
|
||||
if share['status'] not in ["available", "error"]:
|
||||
|
@ -31,6 +31,7 @@ from manila.openstack.common import importutils
|
||||
from manila.openstack.common import log as logging
|
||||
from manila.openstack.common import timeutils
|
||||
from manila.share.configuration import Configuration
|
||||
from manila import quota
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
@ -45,6 +46,8 @@ share_manager_opts = [
|
||||
FLAGS = flags.FLAGS
|
||||
FLAGS.register_opts(share_manager_opts)
|
||||
|
||||
QUOTAS = quota.QUOTAS
|
||||
|
||||
|
||||
class ShareManager(manager.SchedulerDependentManager):
|
||||
"""Manages NAS storages."""
|
||||
@ -124,7 +127,13 @@ class ShareManager(manager.SchedulerDependentManager):
|
||||
|
||||
def delete_share(self, context, share_id):
|
||||
"""Delete a share."""
|
||||
context = context.elevated()
|
||||
share_ref = self.db.share_get(context, share_id)
|
||||
|
||||
if context.project_id != share_ref['project_id']:
|
||||
project_id = share_ref['project_id']
|
||||
else:
|
||||
project_id = context.project_id
|
||||
rules = self.db.share_access_get_all_for_share(context, share_id)
|
||||
try:
|
||||
for access_ref in rules:
|
||||
@ -136,8 +145,20 @@ class ShareManager(manager.SchedulerDependentManager):
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.db.share_update(context, share_id,
|
||||
{'status': 'error_deleting'})
|
||||
else:
|
||||
self.db.share_delete(context, share_id)
|
||||
try:
|
||||
reservations = QUOTAS.reserve(context,
|
||||
project_id=project_id,
|
||||
shares=-1,
|
||||
gigabytes=-share_ref['size'])
|
||||
except Exception:
|
||||
reservations = None
|
||||
LOG.exception(_("Failed to update usages deleting share"))
|
||||
|
||||
self.db.share_delete(context, share_id)
|
||||
LOG.info(_("share %s: deleted successfully"), share_ref['name'])
|
||||
|
||||
if reservations:
|
||||
QUOTAS.commit(context, reservations, project_id=project_id)
|
||||
|
||||
def create_snapshot(self, context, share_id, snapshot_id):
|
||||
"""Create snapshot for share."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user