diff --git a/troveclient/v1/instances.py b/troveclient/v1/instances.py index 8b01dbee..c0aa2cfe 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 d945c9fe..5737f050 100644 --- a/troveclient/v1/shell.py +++ b/troveclient/v1/shell.py @@ -354,6 +354,11 @@ def do_update(cs, args): metavar='', default=None, help='ID or name of an existing instance to replicate from.') +@utils.arg('--replica_count', + metavar='', + 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='', @@ -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='', + 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='', + 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