Add backup-show to OSC

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

The trove command backup-show is now:
    openstack database backup show

Change-Id: I2f8a4c9c9df1ca68c5746acd272e80d7d9eda364
Partially-Implements: trove-support-in-python-openstackclient
This commit is contained in:
wangyao 2017-11-30 16:48:03 +08:00
parent 7e14c4f2b0
commit d7e5252d8c
4 changed files with 72 additions and 0 deletions

View File

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

View File

@ -31,6 +31,7 @@ openstack.cli.extension =
openstack.database.v1 =
database_backup_list = troveclient.osc.v1.database_backups:ListDatabaseBackups
database_backup_show = troveclient.osc.v1.database_backups:ShowDatabaseBackup
database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters
database_configuration_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurations
database_flavor_list = troveclient.osc.v1.database_flavors:ListDatabaseFlavors

View File

@ -14,10 +14,20 @@
from osc_lib.command import command
from osc_lib import utils as osc_utils
import six
from troveclient.i18n import _
def set_attributes_for_print_detail(backup):
info = backup._info.copy()
if hasattr(backup, 'datastore'):
info['datastore'] = backup.datastore['type']
info['datastore_version'] = backup.datastore['version']
info['datastore_version_id'] = backup.datastore['version_id']
return info
class ListDatabaseBackups(command.Lister):
_description = _("List database backups")
@ -64,3 +74,23 @@ class ListDatabaseBackups(command.Lister):
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")
def get_parser(self, prog_name):
parser = super(ShowDatabaseBackup, self).get_parser(prog_name)
parser.add_argument(
'backup',
metavar='<backup>',
help=_('ID or name of the backup'),
)
return parser
def take_action(self, parsed_args):
database_backups = self.app.client_manager.database.backups
backup = osc_utils.find_resource(database_backups, parsed_args.backup)
backup = set_attributes_for_print_detail(backup)
return zip(*sorted(six.iteritems(backup)))

View File

@ -48,3 +48,39 @@ class TestBackupList(TestBackups):
self.backup_client.list.assert_called_once_with(**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',
'1234',
'http://backup_srvr/database_backups/bk-1234.xbstream.gz.enc',
'bkp_1', None, 0.11, 'COMPLETED', '2015-05-16T14:23:08')
def setUp(self):
super(TestBackupShow, self).setUp()
self.cmd = database_backups.ShowDatabaseBackup(self.app, None)
self.data = self.fake_backups.get_backup_bk_1234()
self.backup_client.get.return_value = self.data
self.columns = (
'created',
'datastore',
'datastore_version',
'datastore_version_id',
'description',
'id',
'instance_id',
'locationRef',
'name',
'parent_id',
'size',
'status',
'updated',
)
def test_show(self):
args = ['bkp_1']
parsed_args = self.check_parser(self.cmd, args, [])
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.columns, columns)
self.assertEqual(self.values, data)