Merge "Support backup filtering"
This commit is contained in:
commit
c247e4842e
@ -182,22 +182,22 @@ class Backup(object):
|
|||||||
return query.all(), marker
|
return query.all(), marker
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def list(cls, context, datastore=None):
|
def list(cls, context, datastore=None, instance_id=None,
|
||||||
"""
|
all_projects=False):
|
||||||
list all live Backups belong to given tenant
|
|
||||||
:param cls:
|
|
||||||
:param context: tenant_id included
|
|
||||||
:param datastore: datastore to filter by
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
query = DBBackup.query()
|
query = DBBackup.query()
|
||||||
filters = [DBBackup.tenant_id == context.tenant,
|
filters = [DBBackup.deleted == 0]
|
||||||
DBBackup.deleted == 0]
|
|
||||||
|
if not all_projects:
|
||||||
|
filters.append(DBBackup.tenant_id == context.tenant)
|
||||||
|
if instance_id:
|
||||||
|
filters.append(DBBackup.instance_id == instance_id)
|
||||||
|
|
||||||
if datastore:
|
if datastore:
|
||||||
ds = datastore_models.Datastore.load(datastore)
|
ds = datastore_models.Datastore.load(datastore)
|
||||||
filters.append(datastore_models.DBDatastoreVersion.
|
filters.append(datastore_models.DBDatastoreVersion.
|
||||||
datastore_id == ds.id)
|
datastore_id == ds.id)
|
||||||
query = query.join(datastore_models.DBDatastoreVersion)
|
query = query.join(datastore_models.DBDatastoreVersion)
|
||||||
|
|
||||||
query = query.filter(*filters)
|
query = query.filter(*filters)
|
||||||
return cls._paginate(context, query)
|
return cls._paginate(context, query)
|
||||||
|
|
||||||
|
@ -39,9 +39,21 @@ class BackupController(wsgi.Controller):
|
|||||||
"""
|
"""
|
||||||
LOG.debug("Listing backups for tenant %s", tenant_id)
|
LOG.debug("Listing backups for tenant %s", tenant_id)
|
||||||
datastore = req.GET.get('datastore')
|
datastore = req.GET.get('datastore')
|
||||||
|
instance_id = req.GET.get('instance_id')
|
||||||
|
all_projects = req.GET.get('all_projects', False)
|
||||||
context = req.environ[wsgi.CONTEXT_KEY]
|
context = req.environ[wsgi.CONTEXT_KEY]
|
||||||
|
|
||||||
|
if all_projects:
|
||||||
|
policy.authorize_on_tenant(context, 'backup:index:all_projects')
|
||||||
|
else:
|
||||||
policy.authorize_on_tenant(context, 'backup:index')
|
policy.authorize_on_tenant(context, 'backup:index')
|
||||||
backups, marker = Backup.list(context, datastore)
|
|
||||||
|
backups, marker = Backup.list(
|
||||||
|
context,
|
||||||
|
datastore=datastore,
|
||||||
|
instance_id=instance_id,
|
||||||
|
all_projects=all_projects
|
||||||
|
)
|
||||||
view = views.BackupViews(backups)
|
view = views.BackupViews(backups)
|
||||||
paged = pagination.SimplePaginatedDataView(req.url, 'backups', view,
|
paged = pagination.SimplePaginatedDataView(req.url, 'backups', view,
|
||||||
marker)
|
marker)
|
||||||
|
@ -45,6 +45,16 @@ rules = [
|
|||||||
'method': 'GET'
|
'method': 'GET'
|
||||||
}
|
}
|
||||||
]),
|
]),
|
||||||
|
policy.DocumentedRuleDefault(
|
||||||
|
name='backup:index:all_projects',
|
||||||
|
check_str='role:admin',
|
||||||
|
description='List backups for all the projects.',
|
||||||
|
operations=[
|
||||||
|
{
|
||||||
|
'path': PATH_BACKUPS,
|
||||||
|
'method': 'GET'
|
||||||
|
}
|
||||||
|
]),
|
||||||
policy.DocumentedRuleDefault(
|
policy.DocumentedRuleDefault(
|
||||||
name='backup:show',
|
name='backup:show',
|
||||||
check_str='rule:admin_or_owner',
|
check_str='rule:admin_or_owner',
|
||||||
|
Loading…
Reference in New Issue
Block a user