summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLingxian Kong <anlin.kong@gmail.com>2020-08-23 13:32:33 +1200
committerLingxian Kong <anlin.kong@gmail.com>2020-08-23 14:37:04 +1200
commite0e9be460271bf1f632c86ae637422023a5318b7 (patch)
tree5c31de6fc1a588af9f2ddf757c48ec5142e3bc27
parent2279d2f170332c92a0c67e98cc7449bacc3b4c27 (diff)
downloadpython-troveclient-e0e9be460271bf1f632c86ae637422023a5318b7.tar.gz
Add support of subnet-id and ip-address for creating instance5.1.0
Change-Id: Id88e8100a397b1512c73a0b28f14ab8edb221689
-rw-r--r--troveclient/osc/v1/database_instances.py33
-rw-r--r--troveclient/tests/osc/v1/test_database_instances.py35
2 files changed, 59 insertions, 9 deletions
diff --git a/troveclient/osc/v1/database_instances.py b/troveclient/osc/v1/database_instances.py
index 7f831a9..748c448 100644
--- a/troveclient/osc/v1/database_instances.py
+++ b/troveclient/osc/v1/database_instances.py
@@ -293,9 +293,13 @@ class CreateDatabaseInstance(command.ShowOne):
)
parser.add_argument(
'--nic',
- metavar='<net-id=<net-uuid>>',
+ metavar=('<net-id=<net-uuid>,subnet-id=<subnet-uuid>,'
+ 'ip-address=<ip-address>>'),
dest='nics',
- help=_("Create instance in the given Neutron network."),
+ help=_("Create instance in the given Neutron network. This "
+ "information is used for creating user-facing port for the "
+ "instance. Either network ID or subnet ID (or both) should "
+ "be specified, IP address is optional"),
)
parser.add_argument(
'--configuration',
@@ -392,13 +396,24 @@ class CreateDatabaseInstance(command.ShowOne):
nics = []
if parsed_args.nics:
- nic_info = dict(
- [(k, v) for (k, v) in [parsed_args.nics.split("=", 1)[:2]]]
- )
- if not nic_info.get('net-id'):
- raise exceptions.ValidationError(
- "net-id is not set in %s" % parsed_args.nics
- )
+ nic_info = {}
+ allowed_keys = {
+ 'net-id': 'network_id',
+ 'subnet-id': 'subnet_id',
+ 'ip-address': 'ip_address'
+ }
+ fields = parsed_args.nics.split(',')
+ for field in fields:
+ field = field.strip()
+ k, v = field.split('=', 1)
+ k = k.strip()
+ v = v.strip()
+ if k not in allowed_keys.keys():
+ raise exceptions.ValidationError(
+ f"{k} is not allowed."
+ )
+ if v:
+ nic_info[allowed_keys[k]] = v
nics.append(nic_info)
modules = []
diff --git a/troveclient/tests/osc/v1/test_database_instances.py b/troveclient/tests/osc/v1/test_database_instances.py
index 19ef30e..e93bcd8 100644
--- a/troveclient/tests/osc/v1/test_database_instances.py
+++ b/troveclient/tests/osc/v1/test_database_instances.py
@@ -322,6 +322,41 @@ class TestDatabaseInstanceCreate(TestInstances):
self.assertEqual(expected_columns, columns)
self.assertEqual(expected_values, data)
+ def test_instance_create_nic_param(self):
+ args = [
+ 'test-mysql',
+ '--flavor', 'a48ea749-7ee3-4003-8aae-eb4e79773e2d',
+ '--size', '1',
+ '--datastore', "mysql",
+ '--datastore-version', "5.7.29",
+ '--nic', 'net-id=net1,subnet-id=subnet_id,ip-address=192.168.1.11',
+ ]
+ parsed_args = self.check_parser(self.cmd, args, [])
+ self.cmd.take_action(parsed_args)
+
+ self.instance_client.create.assert_called_once_with(
+ 'test-mysql',
+ flavor_id='a48ea749-7ee3-4003-8aae-eb4e79773e2d',
+ volume={"size": 1, "type": None},
+ databases=[],
+ users=[],
+ restorePoint=None,
+ availability_zone=None,
+ datastore='mysql',
+ datastore_version='5.7.29',
+ nics=[
+ {'network_id': 'net1', 'subnet_id': 'subnet_id',
+ 'ip_address': '192.168.1.11'}
+ ],
+ configuration=None,
+ replica_of=None,
+ replica_count=None,
+ modules=[],
+ locality=None,
+ region_name=None,
+ access={'is_public': False}
+ )
+
class TestDatabaseInstanceResetStatus(TestInstances):