summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMorgan Jones <morgan@parelastic.com>2015-03-06 14:03:31 -0500
committerMorgan Jones <morgan@parelastic.com>2015-03-13 15:51:53 -0400
commita36ebe539ce0affef5388b7edd7a6a230a0fde6c (patch)
treead1d294e328707fcb6a820ce9d105e2605ab92b5
parent69911687264855bed654e6107d31e60db401bcd8 (diff)
downloadpython-troveclient-1.0.9.tar.gz
Replication V21.0.9
The V2 implentation of replication, including: - promote-to-replica-source - eject-replica-source Implements: blueprint replication-v2 Change-Id: I9075365a8fae754e29d27d6e371a1d8c8980e26b Authored-By: Morgan Jones <morgan@parelastic.com> Co-Authored-By: Peter Stachowski <peter@tesora.com>
-rw-r--r--troveclient/v1/instances.py24
-rw-r--r--troveclient/v1/shell.py31
2 files changed, 53 insertions, 2 deletions
diff --git a/troveclient/v1/instances.py b/troveclient/v1/instances.py
index 8b01dbe..c0aa2cf 100644
--- a/troveclient/v1/instances.py
+++ b/troveclient/v1/instances.py
@@ -51,7 +51,7 @@ class Instances(base.ManagerWithFind):
def create(self, name, flavor_id, volume=None, databases=None, users=None,
restorePoint=None, availability_zone=None, datastore=None,
datastore_version=None, nics=None, configuration=None,
- replica_of=None, slave_of=None):
+ replica_of=None, slave_of=None, replica_count=None):
"""Create (boot) a new instance."""
body = {"instance": {
@@ -81,6 +81,8 @@ class Instances(base.ManagerWithFind):
body["instance"]["configuration"] = configuration
if replica_of or slave_of:
body["instance"]["replica_of"] = base.getid(replica_of) or slave_of
+ if replica_count:
+ body["instance"]["replica_count"] = replica_count
return self._create("/instances", body, "instance")
@@ -189,6 +191,24 @@ class Instances(base.ManagerWithFind):
return self._get("/instances/%s/configuration" % base.getid(instance),
"instance")
+ def promote_to_replica_source(self, instance):
+ """Promote a replica to be the new replica_source of its set
+
+ :param instance: The :class:`Instance` (or its ID) of the database
+ instance to promote.
+ """
+ body = {'promote_to_replica_source': {}}
+ self._action(instance, body)
+
+ def eject_replica_source(self, instance):
+ """Eject a replica source from its set
+
+ :param instance: The :class:`Instance` (or its ID) of the database
+ instance to eject.
+ """
+ body = {'eject_replica_source': {}}
+ self._action(instance, body)
+
class InstanceStatus(object):
@@ -200,3 +220,5 @@ class InstanceStatus(object):
RESIZE = "RESIZE"
SHUTDOWN = "SHUTDOWN"
RESTART_REQUIRED = "RESTART_REQUIRED"
+ PROMOTING = "PROMOTING"
+ EJECTING = "EJECTING"
diff --git a/troveclient/v1/shell.py b/troveclient/v1/shell.py
index d945c9f..5737f05 100644
--- a/troveclient/v1/shell.py
+++ b/troveclient/v1/shell.py
@@ -354,6 +354,11 @@ def do_update(cs, args):
metavar='<source_instance>',
default=None,
help='ID or name of an existing instance to replicate from.')
+@utils.arg('--replica_count',
+ metavar='<count>',
+ type=int,
+ default=1,
+ help='Number of replicas to create (defaults to 1).')
@utils.service_type('database')
def do_create(cs, args):
"""Creates a new instance."""
@@ -380,6 +385,7 @@ def do_create(cs, args):
"(but not both) specified." % nic_str)
raise exceptions.CommandError(err_msg)
nics.append(nic_info)
+
instance = cs.instances.create(args.name,
args.flavor_id,
volume=volume,
@@ -391,7 +397,8 @@ def do_create(cs, args):
datastore_version=args.datastore_version,
nics=nics,
configuration=args.configuration,
- replica_of=replica_of_instance)
+ replica_of=replica_of_instance,
+ replica_count=args.replica_count)
_print_instance(instance)
@@ -498,6 +505,8 @@ def do_restart(cs, args):
instance = _find_instance(cs, args.instance)
cs.instances.restart(instance)
+# Replication related commands
+
@utils.arg('instance',
metavar='<instance>',
@@ -508,6 +517,26 @@ def do_detach_replica(cs, args):
instance = _find_instance(cs, args.instance)
cs.instances.edit(instance, detach_replica_source=True)
+
+@utils.arg('instance',
+ metavar='<instance>',
+ type=str,
+ help='ID or name of the instance.')
+def do_promote_to_replica_source(cs, args):
+ """Promotes a replica to be the new replica source of its set."""
+ instance = _find_instance(cs, args.instance)
+ cs.instances.promote_to_replica_source(instance)
+
+
+@utils.arg('instance',
+ metavar='<instance>',
+ type=str,
+ help='ID or name of the instance.')
+def do_eject_replica_source(cs, args):
+ """Ejects a replica source from its set."""
+ instance = _find_instance(cs, args.instance)
+ cs.instances.eject_replica_source(instance)
+
# Backup related commands