Support getting backups of a specific project
Change-Id: Ia590fa6aae23b7323963181d79c9b0097fd2e4d1
This commit is contained in:
4
releasenotes/notes/wallaby-project-backups.yaml
Normal file
4
releasenotes/notes/wallaby-project-backups.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- Support to get backups of a specific project by
|
||||
``--project-id PROJECT_ID``.
|
@@ -71,6 +71,11 @@ class ListDatabaseBackups(command.Lister):
|
||||
action='store_true',
|
||||
help=_('Get all the backups of all the projects(Admin only).')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--project-id',
|
||||
default=None,
|
||||
help=_('Filter backups by project ID.')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@@ -79,14 +84,16 @@ class ListDatabaseBackups(command.Lister):
|
||||
datastore=parsed_args.datastore,
|
||||
marker=parsed_args.marker,
|
||||
instance_id=parsed_args.instance_id,
|
||||
all_projects=parsed_args.all_projects)
|
||||
all_projects=parsed_args.all_projects,
|
||||
project_id=parsed_args.project_id)
|
||||
backups = items
|
||||
while items.next and not parsed_args.limit:
|
||||
items = database_backups.list(
|
||||
marker=items.next,
|
||||
datastore=parsed_args.datastore,
|
||||
instance_id=parsed_args.instance_id,
|
||||
all_projects=parsed_args.all_projects
|
||||
all_projects=parsed_args.all_projects,
|
||||
project_id=parsed_args.project_id
|
||||
)
|
||||
backups += items
|
||||
|
||||
|
@@ -51,7 +51,8 @@ class TestBackupList(TestBackups):
|
||||
'limit': None,
|
||||
'marker': None,
|
||||
'instance_id': None,
|
||||
'all_projects': False
|
||||
'all_projects': False,
|
||||
'project_id': None
|
||||
}
|
||||
|
||||
self.backup_client.list.assert_called_once_with(**params)
|
||||
@@ -68,7 +69,8 @@ class TestBackupList(TestBackups):
|
||||
'limit': None,
|
||||
'marker': None,
|
||||
'instance_id': 'fake_id',
|
||||
'all_projects': False
|
||||
'all_projects': False,
|
||||
'project_id': None
|
||||
}
|
||||
|
||||
self.backup_client.list.assert_called_once_with(**params)
|
||||
@@ -82,7 +84,24 @@ class TestBackupList(TestBackups):
|
||||
'limit': None,
|
||||
'marker': None,
|
||||
'instance_id': None,
|
||||
'all_projects': True
|
||||
'all_projects': True,
|
||||
'project_id': None
|
||||
}
|
||||
|
||||
self.backup_client.list.assert_called_once_with(**params)
|
||||
|
||||
def test_backup_list_by_project(self):
|
||||
parsed_args = self.check_parser(self.cmd, ["--project-id", "fake_id"],
|
||||
[])
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
params = {
|
||||
'datastore': None,
|
||||
'limit': None,
|
||||
'marker': None,
|
||||
'instance_id': None,
|
||||
'all_projects': False,
|
||||
'project_id': 'fake_id'
|
||||
}
|
||||
|
||||
self.backup_client.list.assert_called_once_with(**params)
|
||||
|
@@ -60,7 +60,7 @@ class Backups(base.ManagerWithFind):
|
||||
"backup")
|
||||
|
||||
def list(self, limit=None, marker=None, datastore=None, instance_id=None,
|
||||
all_projects=False):
|
||||
all_projects=False, project_id=None):
|
||||
"""Get a list of all backups."""
|
||||
query_strings = {}
|
||||
if datastore:
|
||||
@@ -69,6 +69,8 @@ class Backups(base.ManagerWithFind):
|
||||
query_strings["instance_id"] = instance_id
|
||||
if all_projects:
|
||||
query_strings["all_projects"] = True
|
||||
if project_id:
|
||||
query_strings["project_id"] = project_id
|
||||
|
||||
return self._paginated("/backups", "backups", limit, marker,
|
||||
query_strings)
|
||||
|
Reference in New Issue
Block a user