diff --git a/releasenotes/notes/add-restart-instance-to-osc-760c292b5b5c95de.yaml b/releasenotes/notes/add-restart-instance-to-osc-760c292b5b5c95de.yaml new file mode 100644 index 00000000..b589e4b2 --- /dev/null +++ b/releasenotes/notes/add-restart-instance-to-osc-760c292b5b5c95de.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The command ``trove restart`` is now available to use in + the python-openstackclient CLI as ``openstack database instance restart`` diff --git a/setup.cfg b/setup.cfg index dbb06cd9..e8d58365 100644 --- a/setup.cfg +++ b/setup.cfg @@ -63,6 +63,7 @@ openstack.database.v1 = database_instance_reset_status = troveclient.osc.v1.database_instances:ResetDatabaseInstanceStatus database_instance_resize_flavor = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceFlavor database_instance_resize_volume = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceVolume + database_instance_restart = troveclient.osc.v1.database_instances:RestartDatabaseInstance database_instance_show = troveclient.osc.v1.database_instances:ShowDatabaseInstance database_instance_upgrade = troveclient.osc.v1.database_instances:UpgradeDatabaseInstance database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits diff --git a/troveclient/osc/v1/database_instances.py b/troveclient/osc/v1/database_instances.py index 98f527c8..76fcb3e7 100644 --- a/troveclient/osc/v1/database_instances.py +++ b/troveclient/osc/v1/database_instances.py @@ -529,3 +529,26 @@ class ForceDeleteDatabaseInstance(command.Command): msg = (_("Failed to delete instance %(instance)s: %(e)s") % {'instance': parsed_args.instance, 'e': e}) raise exceptions.CommandError(msg) + + +class RestartDatabaseInstance(command.Command): + + _description = _("Restarts an instance.") + + def get_parser(self, prog_name): + parser = super(RestartDatabaseInstance, self).get_parser( + prog_name + ) + parser.add_argument( + 'instance', + metavar='', + type=str, + help=_('ID or name of the instance.') + ) + 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) + db_instances.restart(instance) diff --git a/troveclient/tests/osc/v1/test_database_instances.py b/troveclient/tests/osc/v1/test_database_instances.py index d73795b6..1d8b67a8 100644 --- a/troveclient/tests/osc/v1/test_database_instances.py +++ b/troveclient/tests/osc/v1/test_database_instances.py @@ -283,3 +283,20 @@ class TestDatabaseInstanceEnableLog(TestInstances): self.instance_client.log_enable.assert_called_with('instance1', 'log_name') self.assertIsNone(result) + + +class TestDatabaseInstanceRestart(TestInstances): + + def setUp(self): + super(TestDatabaseInstanceRestart, self).setUp() + self.cmd = database_instances.RestartDatabaseInstance(self.app, + None) + + @mock.patch.object(utils, 'find_resource') + def test_instance_restart(self, mock_find): + args = ['instance1'] + mock_find.return_value = args[0] + parsed_args = self.check_parser(self.cmd, args, []) + result = self.cmd.take_action(parsed_args) + self.instance_client.restart.assert_called_with('instance1') + self.assertIsNone(result)