summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--releasenotes/notes/add-promote-to-replica-source-to-osc-6eca8c5507344205.yaml5
-rw-r--r--setup.cfg1
-rw-r--r--troveclient/osc/v1/database_instances.py23
-rw-r--r--troveclient/tests/osc/v1/test_database_instances.py18
4 files changed, 47 insertions, 0 deletions
diff --git a/releasenotes/notes/add-promote-to-replica-source-to-osc-6eca8c5507344205.yaml b/releasenotes/notes/add-promote-to-replica-source-to-osc-6eca8c5507344205.yaml
new file mode 100644
index 0000000..2eb1b5a
--- /dev/null
+++ b/releasenotes/notes/add-promote-to-replica-source-to-osc-6eca8c5507344205.yaml
@@ -0,0 +1,5 @@
1---
2features:
3 - The command ``trove promote-to-replica-source`` is now available to
4 use in the python-openstackclient CLI as
5 ``openstack database instance promote to replica source``
diff --git a/setup.cfg b/setup.cfg
index 99beee6..96816ec 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -68,6 +68,7 @@ openstack.database.v1 =
68 database_instance_eject_replica_source = troveclient.osc.v1.database_instances:EjectDatabaseInstanceReplicaSource 68 database_instance_eject_replica_source = troveclient.osc.v1.database_instances:EjectDatabaseInstanceReplicaSource
69 database_instance_force_delete = troveclient.osc.v1.database_instances:ForceDeleteDatabaseInstance 69 database_instance_force_delete = troveclient.osc.v1.database_instances:ForceDeleteDatabaseInstance
70 database_instance_list = troveclient.osc.v1.database_instances:ListDatabaseInstances 70 database_instance_list = troveclient.osc.v1.database_instances:ListDatabaseInstances
71 database_instance_promote_to_replica_source = troveclient.osc.v1.database_instances:PromoteDatabaseInstanceToReplicaSource
71 database_instance_reset_status = troveclient.osc.v1.database_instances:ResetDatabaseInstanceStatus 72 database_instance_reset_status = troveclient.osc.v1.database_instances:ResetDatabaseInstanceStatus
72 database_instance_resize_flavor = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceFlavor 73 database_instance_resize_flavor = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceFlavor
73 database_instance_resize_volume = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceVolume 74 database_instance_resize_volume = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceVolume
diff --git a/troveclient/osc/v1/database_instances.py b/troveclient/osc/v1/database_instances.py
index 96ec7c7..3bb6a74 100644
--- a/troveclient/osc/v1/database_instances.py
+++ b/troveclient/osc/v1/database_instances.py
@@ -533,6 +533,29 @@ class ForceDeleteDatabaseInstance(command.Command):
533 raise exceptions.CommandError(msg) 533 raise exceptions.CommandError(msg)
534 534
535 535
536class PromoteDatabaseInstanceToReplicaSource(command.Command):
537
538 _description = _(
539 "Promotes a replica to be the new replica source of its set.")
540
541 def get_parser(self, prog_name):
542 parser = super(PromoteDatabaseInstanceToReplicaSource,
543 self).get_parser(prog_name)
544 parser.add_argument(
545 'instance',
546 metavar='<instance>',
547 type=str,
548 help=_('ID or name of the instance.'),
549 )
550 return parser
551
552 def take_action(self, parsed_args):
553 db_instances = self.app.client_manager.database.instances
554 instance = osc_utils.find_resource(db_instances,
555 parsed_args.instance)
556 db_instances.promote_to_replica_source(instance)
557
558
536class RestartDatabaseInstance(command.Command): 559class RestartDatabaseInstance(command.Command):
537 560
538 _description = _("Restarts an instance.") 561 _description = _("Restarts an instance.")
diff --git a/troveclient/tests/osc/v1/test_database_instances.py b/troveclient/tests/osc/v1/test_database_instances.py
index 524e30c..488a835 100644
--- a/troveclient/tests/osc/v1/test_database_instances.py
+++ b/troveclient/tests/osc/v1/test_database_instances.py
@@ -284,6 +284,24 @@ class TestDatabaseInstanceEnableLog(TestInstances):
284 'log_name') 284 'log_name')
285 285
286 286
287class TestDatabaseInstancePromoteToReplicaSource(TestInstances):
288
289 def setUp(self):
290 super(TestDatabaseInstancePromoteToReplicaSource, self).setUp()
291 self.cmd = database_instances.PromoteDatabaseInstanceToReplicaSource(
292 self.app, None)
293
294 @mock.patch.object(utils, 'find_resource')
295 def test_instance_promote_to_replica_source(self, mock_find):
296 args = ['instance']
297 mock_find.return_value = args[0]
298 parsed_args = self.check_parser(self.cmd, args, [])
299 result = self.cmd.take_action(parsed_args)
300 self.instance_client.promote_to_replica_source.assert_called_with(
301 'instance')
302 self.assertIsNone(result)
303
304
287class TestDatabaseInstanceRestart(TestInstances): 305class TestDatabaseInstanceRestart(TestInstances):
288 306
289 def setUp(self): 307 def setUp(self):