Add support of subnet-id and ip-address for creating instance
Change-Id: Id88e8100a397b1512c73a0b28f14ab8edb221689
This commit is contained in:
parent
2279d2f170
commit
e0e9be4602
|
@ -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 = []
|
||||
|
|
|
@ -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):
|
||||
|
||||
|
|
Loading…
Reference in New Issue