diff --git a/releasenotes/notes/add-configuration-groups-for-clusters-6183b0b7b4fb8c9e.yaml b/releasenotes/notes/add-configuration-groups-for-clusters-6183b0b7b4fb8c9e.yaml new file mode 100644 index 00000000..0c559b36 --- /dev/null +++ b/releasenotes/notes/add-configuration-groups-for-clusters-6183b0b7b4fb8c9e.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + A --configuration flag was added to the ``trove cluster-create`` + command, in order to allow a user to attach specific configuration + for cluster. diff --git a/troveclient/tests/test_clusters.py b/troveclient/tests/test_clusters.py index 64e243ee..2545083a 100644 --- a/troveclient/tests/test_clusters.py +++ b/troveclient/tests/test_clusters.py @@ -79,10 +79,12 @@ class ClustersTest(testtools.TestCase): 'configsvr_volume_type': 'foo_type', 'mongos_volume_size': 12, 'mongos_volume_type': 'bar_type'} + configuration = 'test-config' path, body, resp_key = clusters_test.create("test-name", "datastore", "datastore-version", instances, locality, - extended_properties) + extended_properties, + configuration) self.assertEqual("/clusters", path) self.assertEqual("cluster", resp_key) self.assertEqual("test-name", body["cluster"]["name"]) @@ -93,6 +95,7 @@ class ClustersTest(testtools.TestCase): self.assertEqual(locality, body["cluster"]["locality"]) self.assertEqual(extended_properties, body["cluster"]["extended_properties"]) + self.assertEqual(configuration, body["cluster"]["configuration"]) def test_list(self): page_mock = mock.Mock() diff --git a/troveclient/tests/test_v1_shell.py b/troveclient/tests/test_v1_shell.py index 03cb7252..eb18e482 100644 --- a/troveclient/tests/test_v1_shell.py +++ b/troveclient/tests/test_v1_shell.py @@ -516,6 +516,28 @@ class ShellTest(utils.TestCase): 'name': 'test-clstr2', 'locality': 'affinity'}}) + def test_cluster_create_with_configuration(self): + cmd = ('cluster-create test-clstr2 redis 3.0 ' + '--configuration=config01 ' + '--instance flavor=2,volume=1 ' + '--instance flavor=02,volume=1 ' + '--instance flavor=2,volume=1 ') + self.run_command(cmd) + self.assert_called_anytime( + 'POST', '/clusters', + {'cluster': { + 'instances': [ + {'flavorRef': '2', + 'volume': {'size': '1'}}, + {'flavorRef': '02', + 'volume': {'size': '1'}}, + {'flavorRef': '2', + 'volume': {'size': '1'}}, + ], + 'datastore': {'version': '3.0', 'type': 'redis'}, + 'name': 'test-clstr2', + 'configuration': 'config01'}}) + def test_cluster_create_with_extended_properties(self): cmd = ('cluster-create test-clstr3 mongodb 4.0 ' '--instance flavor=2,volume=1 ' diff --git a/troveclient/v1/clusters.py b/troveclient/v1/clusters.py index ae0380e2..caa9d323 100644 --- a/troveclient/v1/clusters.py +++ b/troveclient/v1/clusters.py @@ -37,7 +37,7 @@ class Clusters(base.ManagerWithFind): resource_class = Cluster def create(self, name, datastore, datastore_version, instances=None, - locality=None, extended_properties=None): + locality=None, extended_properties=None, configuration=None): """Create (boot) a new cluster.""" body = {"cluster": { "name": name @@ -53,6 +53,8 @@ class Clusters(base.ManagerWithFind): body["cluster"]["locality"] = locality if extended_properties: body["cluster"]["extended_properties"] = extended_properties + if configuration: + body["cluster"]["configuration"] = configuration return self._create("/clusters", body, "cluster") diff --git a/troveclient/v1/shell.py b/troveclient/v1/shell.py index d5cc9276..aef2529b 100644 --- a/troveclient/v1/shell.py +++ b/troveclient/v1/shell.py @@ -894,6 +894,11 @@ def _parse_instance_options(cs, instance_options, for_grow=False): metavar=EXT_PROPS_METAVAR, default=None, help=EXT_PROPS_HELP) +@utils.arg('--configuration', + metavar='', + type=str, + default=None, + help=_('ID of the configuration group to attach to the cluster.')) @utils.service_type('database') def do_cluster_create(cs, args): """Creates a new cluster.""" @@ -908,7 +913,8 @@ def do_cluster_create(cs, args): args.datastore_version, instances=instances, locality=args.locality, - extended_properties=extended_properties) + extended_properties=extended_properties, + configuration=args.configuration) _print_cluster(cluster)