diff --git a/releasenotes/notes/add-update-to-osc-05eb21c5fa18a788.yaml b/releasenotes/notes/add-update-to-osc-05eb21c5fa18a788.yaml new file mode 100644 index 00000000..1ad5c25e --- /dev/null +++ b/releasenotes/notes/add-update-to-osc-05eb21c5fa18a788.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The command ``trove update`` is now available to use in the + python-openstackclient CLI as ``openstack database instance update``. diff --git a/setup.cfg b/setup.cfg index e8d58365..41a4d6ec 100644 --- a/setup.cfg +++ b/setup.cfg @@ -65,6 +65,7 @@ openstack.database.v1 = 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_update = troveclient.osc.v1.database_instances:UpdateDatabaseInstance database_instance_upgrade = troveclient.osc.v1.database_instances:UpgradeDatabaseInstance database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits database_quota_show = troveclient.osc.v1.database_quota:ShowDatabaseQuota diff --git a/troveclient/osc/v1/database_instances.py b/troveclient/osc/v1/database_instances.py index 76fcb3e7..0234de3d 100644 --- a/troveclient/osc/v1/database_instances.py +++ b/troveclient/osc/v1/database_instances.py @@ -552,3 +552,59 @@ class RestartDatabaseInstance(command.Command): instance = osc_utils.find_resource(db_instances, parsed_args.instance) db_instances.restart(instance) + + +class UpdateDatabaseInstance(command.Command): + + _description = _("Updates an instance: Edits name, " + "configuration, or replica source.") + + def get_parser(self, prog_name): + parser = super(UpdateDatabaseInstance, self).get_parser(prog_name) + parser.add_argument( + 'instance', + metavar='', + type=str, + help=_('ID or name of the instance.'), + ) + parser.add_argument( + '--name', + metavar='', + type=str, + default=None, + help=_('ID or name of the instance.'), + ) + parser.add_argument( + '--configuration', + metavar='', + type=str, + default=None, + help=_('ID of the configuration reference to attach.'), + ) + parser.add_argument( + '--detach_replica_source', + '--detach-replica-source', + dest='detach_replica_source', + action="store_true", + default=False, + help=_('Detach the replica instance from its replication source. ' + '--detach-replica-source may be deprecated in the future ' + 'in favor of just --detach_replica_source'), + ) + parser.add_argument( + '--remove_configuration', + dest='remove_configuration', + action="store_true", + default=False, + help=_('Drops the current configuration reference.'), + ) + 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.edit(instance, parsed_args.configuration, + parsed_args.name, + parsed_args.detach_replica_source, + parsed_args.remove_configuration) diff --git a/troveclient/tests/osc/v1/test_database_instances.py b/troveclient/tests/osc/v1/test_database_instances.py index 1d8b67a8..a188436a 100644 --- a/troveclient/tests/osc/v1/test_database_instances.py +++ b/troveclient/tests/osc/v1/test_database_instances.py @@ -300,3 +300,25 @@ class TestDatabaseInstanceRestart(TestInstances): result = self.cmd.take_action(parsed_args) self.instance_client.restart.assert_called_with('instance1') self.assertIsNone(result) + + +class TestDatabaseInstanceUpdate(TestInstances): + + def setUp(self): + super(TestDatabaseInstanceUpdate, self).setUp() + self.cmd = database_instances.UpdateDatabaseInstance(self.app, None) + + @mock.patch.object(utils, 'find_resource') + def test_instance_update(self, mock_find): + args = ['instance1', + '--name', 'new_instance_name', + '--detach_replica_source', + '--remove_configuration'] + mock_find.return_value = args[0] + parsed_args = self.check_parser(self.cmd, args, []) + result = self.cmd.take_action(parsed_args) + self.instance_client.edit.assert_called_with('instance1', + None, + 'new_instance_name', + True, True) + self.assertIsNone(result)