summaryrefslogtreecommitdiff
path: root/troveclient/osc/v1/database_logs.py
diff options
context:
space:
mode:
authorLingxian Kong <anlin.kong@gmail.com>2019-12-16 11:34:53 +1300
committerLingxian Kong <anlin.kong@gmail.com>2019-12-16 13:41:30 +1300
commitf5a57732a95e130689f6c5a16794e42266b206b0 (patch)
tree1366e69bb23d1e99415fa5ff1666cc2d2d9138dd /troveclient/osc/v1/database_logs.py
parent5f0271a735516d9c9b30a730fecf4738bafa6cde (diff)
downloadpython-troveclient-f5a57732a95e130689f6c5a16794e42266b206b0.tar.gz
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
Diffstat (limited to 'troveclient/osc/v1/database_logs.py')
-rw-r--r--troveclient/osc/v1/database_logs.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/troveclient/osc/v1/database_logs.py b/troveclient/osc/v1/database_logs.py
index aaba81e..eb342c3 100644
--- a/troveclient/osc/v1/database_logs.py
+++ b/troveclient/osc/v1/database_logs.py
@@ -14,6 +14,7 @@
from osc_lib.command import command
from osc_lib import utils as osc_utils
+import six
from troveclient.i18n import _
@@ -41,3 +42,95 @@ class ListDatabaseLogs(command.Lister):
logs = [osc_utils.get_item_properties(l, self.columns)
for l in log_list]
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)))