Replication V2
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>
This commit is contained in:
@@ -51,7 +51,7 @@ class Instances(base.ManagerWithFind):
|
|||||||
def create(self, name, flavor_id, volume=None, databases=None, users=None,
|
def create(self, name, flavor_id, volume=None, databases=None, users=None,
|
||||||
restorePoint=None, availability_zone=None, datastore=None,
|
restorePoint=None, availability_zone=None, datastore=None,
|
||||||
datastore_version=None, nics=None, configuration=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."""
|
"""Create (boot) a new instance."""
|
||||||
|
|
||||||
body = {"instance": {
|
body = {"instance": {
|
||||||
@@ -81,6 +81,8 @@ class Instances(base.ManagerWithFind):
|
|||||||
body["instance"]["configuration"] = configuration
|
body["instance"]["configuration"] = configuration
|
||||||
if replica_of or slave_of:
|
if replica_of or slave_of:
|
||||||
body["instance"]["replica_of"] = base.getid(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")
|
return self._create("/instances", body, "instance")
|
||||||
|
|
||||||
@@ -189,6 +191,24 @@ class Instances(base.ManagerWithFind):
|
|||||||
return self._get("/instances/%s/configuration" % base.getid(instance),
|
return self._get("/instances/%s/configuration" % base.getid(instance),
|
||||||
"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):
|
class InstanceStatus(object):
|
||||||
|
|
||||||
@@ -200,3 +220,5 @@ class InstanceStatus(object):
|
|||||||
RESIZE = "RESIZE"
|
RESIZE = "RESIZE"
|
||||||
SHUTDOWN = "SHUTDOWN"
|
SHUTDOWN = "SHUTDOWN"
|
||||||
RESTART_REQUIRED = "RESTART_REQUIRED"
|
RESTART_REQUIRED = "RESTART_REQUIRED"
|
||||||
|
PROMOTING = "PROMOTING"
|
||||||
|
EJECTING = "EJECTING"
|
||||||
|
@@ -354,6 +354,11 @@ def do_update(cs, args):
|
|||||||
metavar='<source_instance>',
|
metavar='<source_instance>',
|
||||||
default=None,
|
default=None,
|
||||||
help='ID or name of an existing instance to replicate from.')
|
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')
|
@utils.service_type('database')
|
||||||
def do_create(cs, args):
|
def do_create(cs, args):
|
||||||
"""Creates a new instance."""
|
"""Creates a new instance."""
|
||||||
@@ -380,6 +385,7 @@ def do_create(cs, args):
|
|||||||
"(but not both) specified." % nic_str)
|
"(but not both) specified." % nic_str)
|
||||||
raise exceptions.CommandError(err_msg)
|
raise exceptions.CommandError(err_msg)
|
||||||
nics.append(nic_info)
|
nics.append(nic_info)
|
||||||
|
|
||||||
instance = cs.instances.create(args.name,
|
instance = cs.instances.create(args.name,
|
||||||
args.flavor_id,
|
args.flavor_id,
|
||||||
volume=volume,
|
volume=volume,
|
||||||
@@ -391,7 +397,8 @@ def do_create(cs, args):
|
|||||||
datastore_version=args.datastore_version,
|
datastore_version=args.datastore_version,
|
||||||
nics=nics,
|
nics=nics,
|
||||||
configuration=args.configuration,
|
configuration=args.configuration,
|
||||||
replica_of=replica_of_instance)
|
replica_of=replica_of_instance,
|
||||||
|
replica_count=args.replica_count)
|
||||||
_print_instance(instance)
|
_print_instance(instance)
|
||||||
|
|
||||||
|
|
||||||
@@ -498,6 +505,8 @@ def do_restart(cs, args):
|
|||||||
instance = _find_instance(cs, args.instance)
|
instance = _find_instance(cs, args.instance)
|
||||||
cs.instances.restart(instance)
|
cs.instances.restart(instance)
|
||||||
|
|
||||||
|
# Replication related commands
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('instance',
|
@utils.arg('instance',
|
||||||
metavar='<instance>',
|
metavar='<instance>',
|
||||||
@@ -508,6 +517,26 @@ def do_detach_replica(cs, args):
|
|||||||
instance = _find_instance(cs, args.instance)
|
instance = _find_instance(cs, args.instance)
|
||||||
cs.instances.edit(instance, detach_replica_source=True)
|
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
|
# Backup related commands
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user