diff options
author | Greg Lucas <glucas@tesora.com> | 2014-06-22 13:09:25 -0400 |
---|---|---|
committer | Greg Lucas <glucas@tesora.com> | 2014-08-26 15:17:09 -0400 |
commit | 837569d96b3dfb692c63c4770c366175440a7854 (patch) | |
tree | bf292c876ea4ced22b81f7c690852e492950309a | |
parent | 722aeff8069d40e2dcc2a1f54a74b509ca0d00bf (diff) | |
download | python-troveclient-837569d96b3dfb692c63c4770c366175440a7854.tar.gz |
Add new command: detach-replica
Add new command to detach a replica from its replication
source.
Partially Implements: blueprint replication-v1
Co-Authored-By: Nikhil Manchanda <SlickNik@gmail.com>
Change-Id: Ieca67f042c6bcb33f2a4de1acbb330d3eefc0600
-rw-r--r-- | troveclient/tests/test_instances.py | 8 | ||||
-rw-r--r-- | troveclient/v1/instances.py | 9 | ||||
-rw-r--r-- | troveclient/v1/shell.py | 19 |
3 files changed, 33 insertions, 3 deletions
diff --git a/troveclient/tests/test_instances.py b/troveclient/tests/test_instances.py index 9c5a44f..15c2912 100644 --- a/troveclient/tests/test_instances.py +++ b/troveclient/tests/test_instances.py @@ -62,6 +62,13 @@ class InstanceTest(testtools.TestCase): self.instance.restart() self.assertEqual(1, db_restart_mock.call_count) + def test_detach_replica(self): + db_detach_mock = mock.Mock(return_value=None) + self.instance.manager.edit = db_detach_mock + self.instance.id = 1 + self.instance.detach_replica() + self.assertEqual(1, db_detach_mock.call_count) + class InstancesTest(testtools.TestCase): @@ -185,6 +192,7 @@ class InstancesTest(testtools.TestCase): self.instances.edit(123) self.instances.edit(123, 321) self.instances.edit(123, 321, 'name-1234') + self.instances.edit(123, 321, 'name-1234', True) resp.status_code = 500 self.assertRaises(Exception, self.instances.edit, 'instance1') diff --git a/troveclient/v1/instances.py b/troveclient/v1/instances.py index aef6da4..ab33686 100644 --- a/troveclient/v1/instances.py +++ b/troveclient/v1/instances.py @@ -38,6 +38,10 @@ class Instance(base.Resource): """Restart the database instance.""" self.manager.restart(self.id) + def detach_replica(self): + """Stops the replica database from being replicated to.""" + self.manager.edit(self.id, detach_replica_source=True) + class Instances(base.ManagerWithFind): """Manage :class:`Instance` resources.""" @@ -89,7 +93,8 @@ class Instances(base.ManagerWithFind): resp, body = self.api.client.put(url, body=body) common.check_for_exceptions(resp, body, url) - def edit(self, instance_id, configuration=None, name=None): + def edit(self, instance_id, configuration=None, name=None, + detach_replica_source=False): body = { "instance": { } @@ -98,6 +103,8 @@ class Instances(base.ManagerWithFind): body["instance"]["configuration"] = configuration if name is not None: body["instance"]["name"] = name + if detach_replica_source: + body["instance"]["slave_of"] = None url = "/instances/%s" % instance_id resp, body = self.api.client.patch(url, body=body) diff --git a/troveclient/v1/shell.py b/troveclient/v1/shell.py index 3c64969..9d49e81 100644 --- a/troveclient/v1/shell.py +++ b/troveclient/v1/shell.py @@ -169,10 +169,16 @@ def do_delete(cs, args): type=str, default=None, help='ID of the configuration reference to attach.') +@utils.arg('--detach-replica-source', + dest='detach_replica_source', + action="store_true", + default=False, + help='Detach the replica instance from its replication source .') @utils.service_type('database') def do_update(cs, args): - """Updates an instance name or configuration.""" - cs.instances.edit(args.instance, args.configuration, args.name) + """Updates an instance: Edits name, configuration, or replica source.""" + cs.instances.edit(args.instance, args.configuration, args.name, + args.detach_replica_source) @utils.arg('name', @@ -328,8 +334,17 @@ def do_restart(cs, args): cs.instances.restart(args.instance) +@utils.arg('instance', + metavar='<instance>', + type=str, + help='ID of the instance.') +def do_detach_replica(cs, args): + """Detaches a replica instance from its replication source.""" + cs.instances.edit(args.instance, detach_replica_source=True) + # Backup related commands + @utils.arg('backup', metavar='<backup>', help='ID of the backup.') @utils.service_type('database') def do_backup_show(cs, args): |