Add backup-list-instance to OSC

This change adds database support to the python-openstackclient
project for the backup-list-instance command.

The trove command backup-list-instance is now:
    openstack database backup list instance

Change-Id: I383cfe0bac54051641fe0589057c24e7d885f5c1
Partially-Implements: blueprint trove-support-in-python-openstackclient
This commit is contained in:
zhanggang 2017-12-23 04:54:54 -05:00
parent 7ab385fe15
commit 84e5873a03
4 changed files with 84 additions and 0 deletions

View File

@ -0,0 +1,6 @@
---
features:
- |
The command ``trove backup-list-instance`` is now available
to use in the python-openstackclient CLI as ``openstack
database backup list instance``

View File

@ -33,6 +33,7 @@ openstack.database.v1 =
database_backup_create= troveclient.osc.v1.database_backups:CreateDatabaseBackup
database_backup_delete = troveclient.osc.v1.database_backups:DeleteDatabaseBackup
database_backup_list = troveclient.osc.v1.database_backups:ListDatabaseBackups
database_backup_list_instance = troveclient.osc.v1.database_backups:ListDatabaseInstanceBackups
database_backup_show = troveclient.osc.v1.database_backups:ShowDatabaseBackup
database_cluster_delete = troveclient.osc.v1.database_clusters:DeleteDatabaseCluster
database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters

View File

@ -77,6 +77,53 @@ class ListDatabaseBackups(command.Lister):
return self.columns, backups
class ListDatabaseInstanceBackups(command.Lister):
_description = _("Lists available backups for an instance.")
columns = ['ID', 'Instance ID', 'Name', 'Status', 'Parent ID',
'Updated']
def get_parser(self, prog_name):
parser = super(ListDatabaseInstanceBackups, self).get_parser(prog_name)
parser.add_argument(
'instance',
metavar='<instance>',
help=_('ID or name of the instance.')
)
parser.add_argument(
'--limit',
dest='limit',
metavar='<limit>',
default=None,
help=_('Return up to N number of the most recent bcakups.')
)
parser.add_argument(
'--marker',
dest='marker',
metavar='<ID>',
type=str,
default=None,
help=_('Begin displaying the results for IDs greater than the'
'specified marker. When used with :option:`--limit,` set'
'this to the last ID displayed in the previous run.')
)
return parser
def take_action(self, parsed_args):
database_instances = self.app.client_manager.database.instances
instance = osc_utils.find_resource(database_instances,
parsed_args.instance)
items = database_instances.backups(instance, limit=parsed_args.limit,
marker=parsed_args.marker)
backups = items
while items.next and not parsed_args.limit:
items = database_instances.backups(instance, marker=items.next)
backups += items
backups = [osc_utils.get_item_properties(b, self.columns)
for b in backups]
return self.columns, backups
class ShowDatabaseBackup(command.ShowOne):
_description = _("Shows details of a database backup")

View File

@ -27,6 +27,7 @@ class TestBackups(fakes.TestDatabasev1):
super(TestBackups, self).setUp()
self.mock_client = self.app.client_manager.database
self.backup_client = self.app.client_manager.database.backups
self.instance_client = self.app.client_manager.database.instances
class TestBackupList(TestBackups):
@ -55,6 +56,35 @@ class TestBackupList(TestBackups):
self.assertEqual([self.values], data)
class TestBackupListInstance(TestBackups):
defaults = {
'limit': None,
'marker': None
}
columns = database_backups.ListDatabaseInstanceBackups.columns
values = ('bk-1234', '1234', 'bkp_1', 'COMPLETED', None,
'2015-05-16T14:23:08')
def setUp(self):
super(TestBackupListInstance, self).setUp()
self.cmd = database_backups.ListDatabaseInstanceBackups(self.app, None)
data = [self.fake_backups.get_backup_bk_1234()]
self.instance_client.backups.return_value = common.Paginated(data)
@mock.patch.object(utils, 'find_resource')
def test_backup_list_defaults(self, mock_find):
args = ['1234']
mock_find.return_value = args[0]
parsed_args = self.check_parser(self.cmd, args, [])
columns, data = self.cmd.take_action(parsed_args)
self.instance_client.backups.assert_called_once_with('1234',
**self.defaults)
self.assertEqual(self.columns, columns)
self.assertEqual([self.values], data)
class TestBackupShow(TestBackups):
values = ('2015-05-16T14:22:28', 'mysql', '5.6', 'v-56', None, 'bk-1234',