summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhanggang <zhanggang@cmss.chinamobile.com>2018-07-17 14:16:47 +0800
committerzhanggang <zhanggang@cmss.chinamobile.com>2018-07-31 14:48:02 +0800
commit4d58f2e01970b6ebf6e3a774c80e2283c2cfc167 (patch)
tree84a86f30af6b0a342dcc8d5029496caec4283643
parent77f96476449e2418a64cbb508be68ccd77b38e79 (diff)
downloadpython-troveclient-4d58f2e01970b6ebf6e3a774c80e2283c2cfc167.tar.gz
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 <zhanggang@cmss.chinamobile.com>
-rw-r--r--releasenotes/notes/mongo-cluster-create-use-extended-perperties-be7c075585dc709a.yaml8
-rw-r--r--troveclient/tests/test_clusters.py12
-rw-r--r--troveclient/tests/test_v1_shell.py22
-rw-r--r--troveclient/v1/clusters.py4
-rw-r--r--troveclient/v1/shell.py23
5 files changed, 66 insertions, 3 deletions
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 0000000..e8606be
--- /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 710b3c1..64e243e 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 59b0ab1..03cb725 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 b7e5ddd..ae0380e 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 c0275b9..d5cc927 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=<number_of_configsvr>, "
+ " num_mongos=<number_of_mongos>, "
+ " configsvr_volume_size=<disk_size_in_GB>, "
+ " configsvr_volume_type=<volume_type>, "
+ " mongos_volume_size=<disk_size_in_GB>, "
+ " mongos_volume_type=<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)