From 4d58f2e01970b6ebf6e3a774c80e2283c2cfc167 Mon Sep 17 00:00:00 2001 From: zhanggang Date: Tue, 17 Jul 2018 14:16:47 +0800 Subject: [PATCH] Add extended properties support for mongo cluster. User can specify the number and volume of mongos/configserver with extended_properties argument when creating mongodb. Currently, the supported parameters are, num_configsvr, num_mongos, configsvr_volume_size, configsvr_volume_type, mongos_volume_size and mongos_volume_type. Change-Id: I35406f9967ce00a51b320eda37572e96228b209d Signed-off-by: zhanggang --- ...-extended-perperties-be7c075585dc709a.yaml | 8 +++++++ troveclient/tests/test_clusters.py | 12 +++++++++- troveclient/tests/test_v1_shell.py | 22 ++++++++++++++++++ troveclient/v1/clusters.py | 4 +++- troveclient/v1/shell.py | 23 ++++++++++++++++++- 5 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/mongo-cluster-create-use-extended-perperties-be7c075585dc709a.yaml diff --git a/releasenotes/notes/mongo-cluster-create-use-extended-perperties-be7c075585dc709a.yaml b/releasenotes/notes/mongo-cluster-create-use-extended-perperties-be7c075585dc709a.yaml new file mode 100644 index 00000000..e8606be8 --- /dev/null +++ b/releasenotes/notes/mongo-cluster-create-use-extended-perperties-be7c075585dc709a.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + User can specify the number and volume of mongos/configserver by using + the extends argument when creating mongodb cluster. Currently, + the supported parameters are, num_configsvr, num_mongos, + configsvr_volume_size, configsvr_volume_type, mongos_volume_size + and mongos_volume_type. diff --git a/troveclient/tests/test_clusters.py b/troveclient/tests/test_clusters.py index 710b3c14..64e243ee 100644 --- a/troveclient/tests/test_clusters.py +++ b/troveclient/tests/test_clusters.py @@ -72,9 +72,17 @@ class ClustersTest(testtools.TestCase): clusters_test._create = mock.Mock(side_effect=side_effect_func) instances = [{'flavor-id': 11, 'volume': 2}] locality = 'affinity' + extended_properties = { + 'num_configsvr': 5, + 'num_mongos': 7, + 'configsvr_volume_size': 11, + 'configsvr_volume_type': 'foo_type', + 'mongos_volume_size': 12, + 'mongos_volume_type': 'bar_type'} path, body, resp_key = clusters_test.create("test-name", "datastore", "datastore-version", - instances, locality) + instances, locality, + extended_properties) self.assertEqual("/clusters", path) self.assertEqual("cluster", resp_key) self.assertEqual("test-name", body["cluster"]["name"]) @@ -83,6 +91,8 @@ class ClustersTest(testtools.TestCase): body["cluster"]["datastore"]["version"]) self.assertEqual(instances, body["cluster"]["instances"]) self.assertEqual(locality, body["cluster"]["locality"]) + self.assertEqual(extended_properties, + body["cluster"]["extended_properties"]) 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 59b0ab1f..03cb7252 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_extended_properties(self): + cmd = ('cluster-create test-clstr3 mongodb 4.0 ' + '--instance flavor=2,volume=1 ' + '--instance flavor=02,volume=1 ' + '--instance flavor=2,volume=1 ' + '--extended_properties num_mongos=3') + 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': '4.0', 'type': 'mongodb'}, + 'name': 'test-clstr3', + 'extended_properties': {'num_mongos': '3'}}}) + def test_cluster_create_with_nic_az(self): cmd = ('cluster-create test-clstr1 vertica 7.1 ' '--instance flavor=2,volume=2,nic=\'net-id=some-id\',' diff --git a/troveclient/v1/clusters.py b/troveclient/v1/clusters.py index b7e5dddb..ae0380e2 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): + locality=None, extended_properties=None): """Create (boot) a new cluster.""" body = {"cluster": { "name": name @@ -51,6 +51,8 @@ class Clusters(base.ManagerWithFind): body["cluster"]["instances"] = instances if locality: body["cluster"]["locality"] = locality + if extended_properties: + body["cluster"]["extended_properties"] = extended_properties return self._create("/clusters", body, "cluster") diff --git a/troveclient/v1/shell.py b/troveclient/v1/shell.py index c0275b99..d5cc9276 100644 --- a/troveclient/v1/shell.py +++ b/troveclient/v1/shell.py @@ -41,6 +41,17 @@ NIC_ERROR = _("Invalid NIC argument: %s. Must specify either net-id or port-id" NO_LOG_FOUND_ERROR = _("ERROR: No published '%(log_name)s' log was found for " "%(instance)s.") LOCALITY_DOMAIN = ['affinity', 'anti-affinity'] +EXT_PROPS_METAVAR = INSTANCE_METAVAR +EXT_PROPS_HELP = _("Add extended properties for cluster create. " + "Currently only support MongoDB options, other databases " + "will be added in the future. " + "MongoDB: " + " num_configsvr=, " + " num_mongos=, " + " configsvr_volume_size=, " + " configsvr_volume_type=, " + " mongos_volume_size=, " + " mongos_volume_type=.") try: import simplejson as json @@ -879,15 +890,25 @@ def _parse_instance_options(cs, instance_options, for_grow=False): choices=LOCALITY_DOMAIN, help=_('Locality policy to use when creating cluster. Choose ' 'one of %(choices)s.')) +@utils.arg('--extended_properties', + metavar=EXT_PROPS_METAVAR, + default=None, + help=EXT_PROPS_HELP) @utils.service_type('database') def do_cluster_create(cs, args): """Creates a new cluster.""" instances = _parse_instance_options(cs, args.instances) + extended_properties = {} + if args.extended_properties: + extended_properties = dict([(k, v) for (k, v) in + [kv.strip().split("=") for kv in + args.extended_properties.split(",")]]) cluster = cs.clusters.create(args.name, args.datastore, args.datastore_version, instances=instances, - locality=args.locality) + locality=args.locality, + extended_properties=extended_properties) _print_cluster(cluster)