Support log actions in osc plugin
- openstack database log show <instance_id> <log_name> - openstack database log set <instance_id> <log_name> [OPTIONS] Change-Id: I86f414a53e6f6416f96e0040635bb010aa49cf41
This commit is contained in:
parent
5f0271a735
commit
f5a57732a9
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Support following instance log actions:
|
||||||
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
openstack database log show <instance_id> <log_name>
|
||||||
|
openstack database log set <instance_id> <log_name> [OPTIONS]
|
|
@ -79,9 +79,10 @@ openstack.database.v1 =
|
||||||
database_instance_upgrade = troveclient.osc.v1.database_instances:UpgradeDatabaseInstance
|
database_instance_upgrade = troveclient.osc.v1.database_instances:UpgradeDatabaseInstance
|
||||||
database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits
|
database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits
|
||||||
database_log_list = troveclient.osc.v1.database_logs:ListDatabaseLogs
|
database_log_list = troveclient.osc.v1.database_logs:ListDatabaseLogs
|
||||||
|
database_log_set = troveclient.osc.v1.database_logs:SetDatabaseInstanceLog
|
||||||
|
database_log_show = troveclient.osc.v1.database_logs:ShowDatabaseInstanceLog
|
||||||
database_quota_show = troveclient.osc.v1.database_quota:ShowDatabaseQuota
|
database_quota_show = troveclient.osc.v1.database_quota:ShowDatabaseQuota
|
||||||
database_quota_update = troveclient.osc.v1.database_quota:UpdateDatabaseQuota
|
database_quota_update = troveclient.osc.v1.database_quota:UpdateDatabaseQuota
|
||||||
database_log_enable = troveclient.osc.v1.database_instances:EnableDatabaseInstanceLog
|
|
||||||
database_root_disable = troveclient.osc.v1.database_root:DisableDatabaseRoot
|
database_root_disable = troveclient.osc.v1.database_root:DisableDatabaseRoot
|
||||||
database_root_enable = troveclient.osc.v1.database_root:EnableDatabaseRoot
|
database_root_enable = troveclient.osc.v1.database_root:EnableDatabaseRoot
|
||||||
database_root_show = troveclient.osc.v1.database_root:ShowDatabaseRoot
|
database_root_show = troveclient.osc.v1.database_root:ShowDatabaseRoot
|
||||||
|
|
|
@ -492,35 +492,6 @@ class UpgradeDatabaseInstance(command.Command):
|
||||||
db_instances.upgrade(instance, parsed_args.datastore_version)
|
db_instances.upgrade(instance, parsed_args.datastore_version)
|
||||||
|
|
||||||
|
|
||||||
class EnableDatabaseInstanceLog(command.ShowOne):
|
|
||||||
|
|
||||||
_description = _("Instructs Trove guest to start collecting log details.")
|
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
|
||||||
parser = super(EnableDatabaseInstanceLog, self).get_parser(prog_name)
|
|
||||||
parser.add_argument(
|
|
||||||
'instance',
|
|
||||||
metavar='<instance>',
|
|
||||||
type=str,
|
|
||||||
help=_('Id or Name of the instance.')
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
'log_name',
|
|
||||||
metavar='<log_name>',
|
|
||||||
type=str,
|
|
||||||
help=_('Name of log to publish.')
|
|
||||||
)
|
|
||||||
return parser
|
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
|
||||||
db_instances = self.app.client_manager.database.instances
|
|
||||||
instance = osc_utils.find_resource(db_instances,
|
|
||||||
parsed_args.instance)
|
|
||||||
log_info = db_instances.log_enable(instance, parsed_args.log_name)
|
|
||||||
result = log_info._info
|
|
||||||
return zip(*sorted(six.iteritems(result)))
|
|
||||||
|
|
||||||
|
|
||||||
class ResizeDatabaseInstanceVolume(command.Command):
|
class ResizeDatabaseInstanceVolume(command.Command):
|
||||||
|
|
||||||
_description = _("Resizes the volume size of an instance.")
|
_description = _("Resizes the volume size of an instance.")
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
from osc_lib import utils as osc_utils
|
from osc_lib import utils as osc_utils
|
||||||
|
import six
|
||||||
|
|
||||||
from troveclient.i18n import _
|
from troveclient.i18n import _
|
||||||
|
|
||||||
|
@ -41,3 +42,95 @@ class ListDatabaseLogs(command.Lister):
|
||||||
logs = [osc_utils.get_item_properties(l, self.columns)
|
logs = [osc_utils.get_item_properties(l, self.columns)
|
||||||
for l in log_list]
|
for l in log_list]
|
||||||
return self.columns, logs
|
return self.columns, logs
|
||||||
|
|
||||||
|
|
||||||
|
class SetDatabaseInstanceLog(command.ShowOne):
|
||||||
|
_description = _("Instructs Trove guest to operate logs.")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(SetDatabaseInstanceLog, self).get_parser(prog_name)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'instance',
|
||||||
|
metavar='<instance>',
|
||||||
|
type=str,
|
||||||
|
help=_('Id or Name of the instance.')
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'log_name',
|
||||||
|
metavar='<log_name>',
|
||||||
|
type=str,
|
||||||
|
help=_('Name of log to operate.')
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--enable',
|
||||||
|
action='store_true',
|
||||||
|
help="Whether or not to enable log collection.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--disable',
|
||||||
|
action='store_true',
|
||||||
|
help="Whether or not to disable log collection.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--publish',
|
||||||
|
action='store_true',
|
||||||
|
help="Whether or not to publish log files to the backend storage "
|
||||||
|
"for logs(Swift by default).",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--discard',
|
||||||
|
action='store_true',
|
||||||
|
help="Whether or not to discard the existing logs before publish.",
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
db_instances = self.app.client_manager.database.instances
|
||||||
|
instance = osc_utils.find_resource(db_instances,
|
||||||
|
parsed_args.instance)
|
||||||
|
|
||||||
|
log_info = db_instances.log_action(
|
||||||
|
instance, parsed_args.log_name,
|
||||||
|
enable=parsed_args.enable,
|
||||||
|
disable=parsed_args.disable,
|
||||||
|
discard=parsed_args.discard,
|
||||||
|
publish=parsed_args.publish
|
||||||
|
)
|
||||||
|
result = log_info._info
|
||||||
|
|
||||||
|
return zip(*sorted(six.iteritems(result)))
|
||||||
|
|
||||||
|
|
||||||
|
class ShowDatabaseInstanceLog(command.ShowOne):
|
||||||
|
_description = _("Show information of given log name for the database "
|
||||||
|
"instance.")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ShowDatabaseInstanceLog, self).get_parser(prog_name)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'instance',
|
||||||
|
metavar='<instance>',
|
||||||
|
type=str,
|
||||||
|
help=_('Id or Name of the instance.')
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'log_name',
|
||||||
|
metavar='<log_name>',
|
||||||
|
type=str,
|
||||||
|
help=_('Name of log to operate.')
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
db_instances = self.app.client_manager.database.instances
|
||||||
|
instance = osc_utils.find_resource(db_instances,
|
||||||
|
parsed_args.instance)
|
||||||
|
|
||||||
|
log_info = db_instances.log_show(instance, parsed_args.log_name)
|
||||||
|
result = log_info._info
|
||||||
|
|
||||||
|
return zip(*sorted(six.iteritems(result)))
|
||||||
|
|
|
@ -320,23 +320,6 @@ class TestDatabaseInstanceForceDelete(TestInstances):
|
||||||
parsed_args)
|
parsed_args)
|
||||||
|
|
||||||
|
|
||||||
class TestDatabaseInstanceEnableLog(TestInstances):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(TestDatabaseInstanceEnableLog, self).setUp()
|
|
||||||
self.cmd = database_instances.EnableDatabaseInstanceLog(self.app,
|
|
||||||
None)
|
|
||||||
|
|
||||||
@mock.patch.object(utils, 'find_resource')
|
|
||||||
def test_instance_enable_log(self, mock_find):
|
|
||||||
args = ['instance1', 'log_name']
|
|
||||||
mock_find.side_effect = ['instance1']
|
|
||||||
parsed_args = self.check_parser(self.cmd, args, [])
|
|
||||||
self.cmd.take_action(parsed_args)
|
|
||||||
self.instance_client.log_enable.assert_called_with('instance1',
|
|
||||||
'log_name')
|
|
||||||
|
|
||||||
|
|
||||||
class TestDatabaseInstancePromoteToReplicaSource(TestInstances):
|
class TestDatabaseInstancePromoteToReplicaSource(TestInstances):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -47,3 +47,58 @@ class TestLogList(TestLogs):
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.values, data)
|
self.assertEqual(self.values, data)
|
||||||
|
|
||||||
|
|
||||||
|
class TestShowDatabaseInstanceLog(TestLogs):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestShowDatabaseInstanceLog, self).setUp()
|
||||||
|
self.cmd = database_logs.ShowDatabaseInstanceLog(self.app, None)
|
||||||
|
self.columns = (
|
||||||
|
'container',
|
||||||
|
'metafile',
|
||||||
|
'name',
|
||||||
|
'pending',
|
||||||
|
'prefix',
|
||||||
|
'published',
|
||||||
|
'status',
|
||||||
|
'type',
|
||||||
|
)
|
||||||
|
|
||||||
|
@mock.patch.object(utils, 'find_resource')
|
||||||
|
def test_show_instance_log(self, mock_find):
|
||||||
|
mock_find.return_value = 'fake_instance_id'
|
||||||
|
data = self.fake_logs.get_logs()[0]
|
||||||
|
self.instance_client.log_show.return_value = data
|
||||||
|
|
||||||
|
args = ['instance', 'logname']
|
||||||
|
parsed_args = self.check_parser(self.cmd, args, [])
|
||||||
|
columns, values = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertItemsEqual(data.to_dict().values(), values)
|
||||||
|
|
||||||
|
|
||||||
|
class TestSetDatabaseInstanceLog(TestLogs):
|
||||||
|
def setUp(self):
|
||||||
|
super(TestSetDatabaseInstanceLog, self).setUp()
|
||||||
|
self.cmd = database_logs.SetDatabaseInstanceLog(self.app, None)
|
||||||
|
|
||||||
|
@mock.patch.object(utils, 'find_resource')
|
||||||
|
def test_set_instance_log(self, mock_find):
|
||||||
|
mock_find.return_value = 'fake_instance_id'
|
||||||
|
data = self.fake_logs.get_logs()[0]
|
||||||
|
data.status = 'Ready'
|
||||||
|
self.instance_client.log_action.return_value = data
|
||||||
|
|
||||||
|
args = ['instance1', 'log_name', '--enable']
|
||||||
|
parsed_args = self.check_parser(self.cmd, args, [])
|
||||||
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.instance_client.log_action.assert_called_once_with(
|
||||||
|
'fake_instance_id', 'log_name',
|
||||||
|
enable=True,
|
||||||
|
disable=False,
|
||||||
|
discard=False,
|
||||||
|
publish=False
|
||||||
|
)
|
||||||
|
|
|
@ -382,24 +382,10 @@ class Instances(base.ManagerWithFind):
|
||||||
return [DatastoreLog(self, log, loaded=True) for log in body['logs']]
|
return [DatastoreLog(self, log, loaded=True) for log in body['logs']]
|
||||||
|
|
||||||
def log_show(self, instance, log_name):
|
def log_show(self, instance, log_name):
|
||||||
return self._log_action(instance, log_name)
|
return self.log_action(instance, log_name)
|
||||||
|
|
||||||
def log_enable(self, instance, log_name):
|
def log_action(self, instance, log_name, enable=None, disable=None,
|
||||||
return self._log_action(instance, log_name, enable=True)
|
publish=None, discard=None):
|
||||||
|
|
||||||
def log_disable(self, instance, log_name, discard=None):
|
|
||||||
return self._log_action(instance, log_name,
|
|
||||||
disable=True, discard=discard)
|
|
||||||
|
|
||||||
def log_publish(self, instance, log_name, disable=None, discard=None):
|
|
||||||
return self._log_action(instance, log_name, disable=disable,
|
|
||||||
publish=True, discard=discard)
|
|
||||||
|
|
||||||
def log_discard(self, instance, log_name):
|
|
||||||
return self._log_action(instance, log_name, discard=True)
|
|
||||||
|
|
||||||
def _log_action(self, instance, log_name, enable=None, disable=None,
|
|
||||||
publish=None, discard=None):
|
|
||||||
"""Perform action on guest log.
|
"""Perform action on guest log.
|
||||||
|
|
||||||
:param instance: The :class:`Instance` (or its ID) of the database
|
:param instance: The :class:`Instance` (or its ID) of the database
|
||||||
|
@ -420,6 +406,7 @@ class Instances(base.ManagerWithFind):
|
||||||
body.update({'publish': int(publish)})
|
body.update({'publish': int(publish)})
|
||||||
if discard:
|
if discard:
|
||||||
body.update({'discard': int(discard)})
|
body.update({'discard': int(discard)})
|
||||||
|
|
||||||
url = "/instances/%s/log" % base.getid(instance)
|
url = "/instances/%s/log" % base.getid(instance)
|
||||||
resp, body = self.api.client.post(url, body=body)
|
resp, body = self.api.client.post(url, body=body)
|
||||||
common.check_for_exceptions(resp, body, url)
|
common.check_for_exceptions(resp, body, url)
|
||||||
|
@ -427,7 +414,7 @@ class Instances(base.ManagerWithFind):
|
||||||
|
|
||||||
def _get_container_info(self, instance, log_name, publish):
|
def _get_container_info(self, instance, log_name, publish):
|
||||||
try:
|
try:
|
||||||
log_info = self._log_action(instance, log_name, publish=publish)
|
log_info = self.log_action(instance, log_name, publish=publish)
|
||||||
container = log_info.container
|
container = log_info.container
|
||||||
prefix = log_info.prefix
|
prefix = log_info.prefix
|
||||||
metadata_file = log_info.metafile
|
metadata_file = log_info.metafile
|
||||||
|
|
|
@ -2214,7 +2214,8 @@ def do_log_enable(cs, args):
|
||||||
"""Instructs Trove guest to start collecting log details."""
|
"""Instructs Trove guest to start collecting log details."""
|
||||||
try:
|
try:
|
||||||
instance = _find_instance(cs, args.instance)
|
instance = _find_instance(cs, args.instance)
|
||||||
log_info = cs.instances.log_enable(instance, args.log_name)
|
log_info = cs.instances.log_action(instance, args.log_name,
|
||||||
|
enable=True)
|
||||||
_print_object(log_info)
|
_print_object(log_info)
|
||||||
except exceptions.GuestLogNotFoundError:
|
except exceptions.GuestLogNotFoundError:
|
||||||
print(NO_LOG_FOUND_ERROR % {'log_name': args.log_name,
|
print(NO_LOG_FOUND_ERROR % {'log_name': args.log_name,
|
||||||
|
@ -2227,15 +2228,15 @@ def do_log_enable(cs, args):
|
||||||
@utils.arg('instance', metavar='<instance>',
|
@utils.arg('instance', metavar='<instance>',
|
||||||
help=_('Id or Name of the instance.'))
|
help=_('Id or Name of the instance.'))
|
||||||
@utils.arg('log_name', metavar='<log_name>', help=_('Name of log to publish.'))
|
@utils.arg('log_name', metavar='<log_name>', help=_('Name of log to publish.'))
|
||||||
@utils.arg('--discard', action='store_true', default=False,
|
@utils.arg('--disable', action='store_true', default=False,
|
||||||
help=_('Discard published contents of specified log.'))
|
help=_('Disable the collection of the specified log.'))
|
||||||
@utils.service_type('database')
|
@utils.service_type('database')
|
||||||
def do_log_disable(cs, args):
|
def do_log_disable(cs, args):
|
||||||
"""Instructs Trove guest to stop collecting log details."""
|
"""Instructs Trove guest to stop collecting log details."""
|
||||||
try:
|
try:
|
||||||
instance = _find_instance(cs, args.instance)
|
instance = _find_instance(cs, args.instance)
|
||||||
log_info = cs.instances.log_disable(instance, args.log_name,
|
log_info = cs.instances.log_action(instance, args.log_name,
|
||||||
discard=args.discard)
|
disable=args.discard)
|
||||||
_print_object(log_info)
|
_print_object(log_info)
|
||||||
except exceptions.GuestLogNotFoundError:
|
except exceptions.GuestLogNotFoundError:
|
||||||
print(NO_LOG_FOUND_ERROR % {'log_name': args.log_name,
|
print(NO_LOG_FOUND_ERROR % {'log_name': args.log_name,
|
||||||
|
@ -2257,8 +2258,8 @@ def do_log_publish(cs, args):
|
||||||
"""Instructs Trove guest to publish latest log entries on instance."""
|
"""Instructs Trove guest to publish latest log entries on instance."""
|
||||||
try:
|
try:
|
||||||
instance = _find_instance(cs, args.instance)
|
instance = _find_instance(cs, args.instance)
|
||||||
log_info = cs.instances.log_publish(
|
log_info = cs.instances.log_action(
|
||||||
instance, args.log_name, disable=args.disable,
|
instance, args.log_name, publish=True, disable=args.disable,
|
||||||
discard=args.discard)
|
discard=args.discard)
|
||||||
_print_object(log_info)
|
_print_object(log_info)
|
||||||
except exceptions.GuestLogNotFoundError:
|
except exceptions.GuestLogNotFoundError:
|
||||||
|
@ -2277,7 +2278,8 @@ def do_log_discard(cs, args):
|
||||||
"""Instructs Trove guest to discard the container of the published log."""
|
"""Instructs Trove guest to discard the container of the published log."""
|
||||||
try:
|
try:
|
||||||
instance = _find_instance(cs, args.instance)
|
instance = _find_instance(cs, args.instance)
|
||||||
log_info = cs.instances.log_discard(instance, args.log_name)
|
log_info = cs.instances.log_action(instance, args.log_name,
|
||||||
|
discard=True)
|
||||||
_print_object(log_info)
|
_print_object(log_info)
|
||||||
except exceptions.GuestLogNotFoundError:
|
except exceptions.GuestLogNotFoundError:
|
||||||
print(NO_LOG_FOUND_ERROR % {'log_name': args.log_name,
|
print(NO_LOG_FOUND_ERROR % {'log_name': args.log_name,
|
||||||
|
|
Loading…
Reference in New Issue