From aed18902d07eb091e444b8d4b20bf90ea66a13ca Mon Sep 17 00:00:00 2001 From: Morgan Jones Date: Wed, 5 Oct 2016 11:08:18 -0400 Subject: [PATCH] Multi-Region Support This is an initial attempt at supporting multiple regions. It should handle the mechanics of deploying an instance/volume to a remote region. Additional changes may be required to allow the guest agent on the instance to connect back to the originating region. Co-Authored-By: Doug Shelley Depends-On: I386efb2d5c147417af7ea25704405977c9b6bbcd Change-Id: Ib0b35100c0780dc07c60d20622554ba77c4bc850 --- .../notes/multi-region-ec516da866def1ed.yaml | 4 +++ troveclient/tests/fakes.py | 2 ++ troveclient/v1/instances.py | 4 ++- troveclient/v1/shell.py | 25 +++++++++++++++---- 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/multi-region-ec516da866def1ed.yaml diff --git a/releasenotes/notes/multi-region-ec516da866def1ed.yaml b/releasenotes/notes/multi-region-ec516da866def1ed.yaml new file mode 100644 index 00000000..ea4fec4f --- /dev/null +++ b/releasenotes/notes/multi-region-ec516da866def1ed.yaml @@ -0,0 +1,4 @@ +features: + - Adds --region option to create and cluster-create APIs. For now, these + options are excluded from CLI help strings. This is the first step in + multiregion support. diff --git a/troveclient/tests/fakes.py b/troveclient/tests/fakes.py index 750619cb..eaab7c80 100644 --- a/troveclient/tests/fakes.py +++ b/troveclient/tests/fakes.py @@ -166,6 +166,7 @@ class FakeHTTPClient(base_client.HTTPClient): "ip": ["10.0.0.13"], "volume": {"size": 2}, "flavor": {"id": "02"}, + "region": "regionOne", "datastore": {"version": "5.6", "type": "mysql"}}, { "id": "5678", @@ -174,6 +175,7 @@ class FakeHTTPClient(base_client.HTTPClient): "ip": ["10.0.0.14"], "volume": {"size": 2}, "flavor": {"id": "2"}, + "region": "regionOne", "datastore": {"version": "5.6", "type": "mysql"}}]}) def get_instances_1234(self, **kw): diff --git a/troveclient/v1/instances.py b/troveclient/v1/instances.py index 65413617..a25b1924 100644 --- a/troveclient/v1/instances.py +++ b/troveclient/v1/instances.py @@ -92,7 +92,7 @@ class Instances(base.ManagerWithFind): restorePoint=None, availability_zone=None, datastore=None, datastore_version=None, nics=None, configuration=None, replica_of=None, slave_of=None, replica_count=None, - modules=None, locality=None): + modules=None, locality=None, region_name=None): """Create (boot) a new instance.""" body = {"instance": { @@ -134,6 +134,8 @@ class Instances(base.ManagerWithFind): body["instance"]["modules"] = self._get_module_list(modules) if locality: body["instance"]["locality"] = locality + if region_name: + body["instance"]["region_name"] = region_name return self._create("/instances", body, "instance") diff --git a/troveclient/v1/shell.py b/troveclient/v1/shell.py index 32a33bb1..a2c5f484 100644 --- a/troveclient/v1/shell.py +++ b/troveclient/v1/shell.py @@ -274,7 +274,7 @@ def _print_instances(instances): setattr(instance, 'datastore', instance.datastore['type']) utils.print_list(instances, ['id', 'name', 'datastore', 'datastore_version', 'status', - 'flavor_id', 'size']) + 'flavor_id', 'size', 'region']) @utils.arg('--limit', metavar='', type=int, default=None, @@ -526,6 +526,11 @@ def do_update(cs, args): choices=LOCALITY_DOMAIN, help=_('Locality policy to use when creating replicas. Choose ' 'one of %(choices)s.')) +@utils.arg('--region', metavar='', + type=str, + default=None, + help=argparse.SUPPRESS) +# help=_('Name of region in which to create the instance.')) @utils.service_type('database') def do_create(cs, args): """Creates a new instance.""" @@ -579,7 +584,9 @@ def do_create(cs, args): configuration=args.configuration, replica_of=replica_of, replica_count=replica_count, - modules=modules, locality=locality) + modules=modules, + locality=locality, + region_name=args.region) _print_instance(instance) @@ -647,6 +654,10 @@ def _get_availability_zone(opts_str): return _strip_option(opts_str, 'availability_zone', is_required=False) +def _get_region(cs, opts_str): + return _strip_option(opts_str, 'region', is_required=False) + + def _get_modules(cs, opts_str): modules, opts_str = _strip_option( opts_str, 'module', is_required=False, allow_multiple=True) @@ -756,6 +767,10 @@ def _parse_instance_options(cs, instance_options, for_grow=False): if name: instance_info["name"] = name + region, instance_opts = _get_region(cs, instance_opts) + if region: + instance_info["region"] = region + if instance_opts: raise exceptions.ValidationError( _("Unknown option(s) '%s' specified for instance") @@ -981,9 +996,9 @@ def do_backup_create(cs, args): @utils.arg('backup', metavar='', help=_('Backup ID of the source backup.'), default=None) -@utils.arg('--region', metavar='', help=_('Region where the source ' - 'backup resides.'), - default=None) +@utils.arg('--region', metavar='', default=None, + # help=_('Region where the source backup resides.')) + help=argparse.SUPPRESS) @utils.arg('--description', metavar='', default=None, help=_('An optional description for the backup.'))