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
This commit is contained in:
Greg Lucas 2014-06-22 13:09:25 -04:00
parent 722aeff806
commit 837569d96b
3 changed files with 33 additions and 3 deletions

View File

@ -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')

View File

@ -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)

View File

@ -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):