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>
This commit is contained in:
zhanggang 2018-07-17 14:16:47 +08:00
parent 77f9647644
commit 4d58f2e019
5 changed files with 66 additions and 3 deletions

View File

@ -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.

View File

@ -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()

View File

@ -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\','

View File

@ -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")

View File

@ -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)