Support getting backups of a specific project

Change-Id: Ia590fa6aae23b7323963181d79c9b0097fd2e4d1
This commit is contained in:
Lingxian Kong
2020-09-13 23:59:23 +12:00
parent 0c6ec392ae
commit e4d79c2cbc
4 changed files with 38 additions and 6 deletions

View File

@@ -0,0 +1,4 @@
---
features:
- Support to get backups of a specific project by
``--project-id PROJECT_ID``.

View File

@@ -71,6 +71,11 @@ class ListDatabaseBackups(command.Lister):
action='store_true', action='store_true',
help=_('Get all the backups of all the projects(Admin only).') 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 return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
@@ -79,14 +84,16 @@ class ListDatabaseBackups(command.Lister):
datastore=parsed_args.datastore, datastore=parsed_args.datastore,
marker=parsed_args.marker, marker=parsed_args.marker,
instance_id=parsed_args.instance_id, 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 backups = items
while items.next and not parsed_args.limit: while items.next and not parsed_args.limit:
items = database_backups.list( items = database_backups.list(
marker=items.next, marker=items.next,
datastore=parsed_args.datastore, datastore=parsed_args.datastore,
instance_id=parsed_args.instance_id, 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 backups += items

View File

@@ -51,7 +51,8 @@ class TestBackupList(TestBackups):
'limit': None, 'limit': None,
'marker': None, 'marker': None,
'instance_id': None, 'instance_id': None,
'all_projects': False 'all_projects': False,
'project_id': None
} }
self.backup_client.list.assert_called_once_with(**params) self.backup_client.list.assert_called_once_with(**params)
@@ -68,7 +69,8 @@ class TestBackupList(TestBackups):
'limit': None, 'limit': None,
'marker': None, 'marker': None,
'instance_id': 'fake_id', 'instance_id': 'fake_id',
'all_projects': False 'all_projects': False,
'project_id': None
} }
self.backup_client.list.assert_called_once_with(**params) self.backup_client.list.assert_called_once_with(**params)
@@ -82,7 +84,24 @@ class TestBackupList(TestBackups):
'limit': None, 'limit': None,
'marker': None, 'marker': None,
'instance_id': 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) self.backup_client.list.assert_called_once_with(**params)

View File

@@ -60,7 +60,7 @@ class Backups(base.ManagerWithFind):
"backup") "backup")
def list(self, limit=None, marker=None, datastore=None, instance_id=None, 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.""" """Get a list of all backups."""
query_strings = {} query_strings = {}
if datastore: if datastore:
@@ -69,6 +69,8 @@ class Backups(base.ManagerWithFind):
query_strings["instance_id"] = instance_id query_strings["instance_id"] = instance_id
if all_projects: if all_projects:
query_strings["all_projects"] = True query_strings["all_projects"] = True
if project_id:
query_strings["project_id"] = project_id
return self._paginated("/backups", "backups", limit, marker, return self._paginated("/backups", "backups", limit, marker,
query_strings) query_strings)