add name into port and subnet.
f-3-cli-usability-improvments The name is optional to create network/port/subnet and is up to user to decide its uniqueness. Change-Id: I40c834ed66e2da14a414232c86c9fd4f5c1d9154
This commit is contained in:
parent
7095639552
commit
2157d21923
@ -144,7 +144,7 @@ RESOURCE_ATTRIBUTE_MAP = {
|
|||||||
'validate': {'type:regex': UUID_PATTERN},
|
'validate': {'type:regex': UUID_PATTERN},
|
||||||
'is_visible': True},
|
'is_visible': True},
|
||||||
'name': {'allow_post': True, 'allow_put': True,
|
'name': {'allow_post': True, 'allow_put': True,
|
||||||
'is_visible': True},
|
'default': '', 'is_visible': True},
|
||||||
'subnets': {'allow_post': True, 'allow_put': True,
|
'subnets': {'allow_post': True, 'allow_put': True,
|
||||||
'default': [],
|
'default': [],
|
||||||
'is_visible': True},
|
'is_visible': True},
|
||||||
@ -165,6 +165,8 @@ RESOURCE_ATTRIBUTE_MAP = {
|
|||||||
'id': {'allow_post': False, 'allow_put': False,
|
'id': {'allow_post': False, 'allow_put': False,
|
||||||
'validate': {'type:regex': UUID_PATTERN},
|
'validate': {'type:regex': UUID_PATTERN},
|
||||||
'is_visible': True},
|
'is_visible': True},
|
||||||
|
'name': {'allow_post': True, 'allow_put': True, 'default': '',
|
||||||
|
'is_visible': True},
|
||||||
'network_id': {'allow_post': True, 'allow_put': False,
|
'network_id': {'allow_post': True, 'allow_put': False,
|
||||||
'validate': {'type:regex': UUID_PATTERN},
|
'validate': {'type:regex': UUID_PATTERN},
|
||||||
'is_visible': True},
|
'is_visible': True},
|
||||||
@ -196,6 +198,8 @@ RESOURCE_ATTRIBUTE_MAP = {
|
|||||||
'id': {'allow_post': False, 'allow_put': False,
|
'id': {'allow_post': False, 'allow_put': False,
|
||||||
'validate': {'type:regex': UUID_PATTERN},
|
'validate': {'type:regex': UUID_PATTERN},
|
||||||
'is_visible': True},
|
'is_visible': True},
|
||||||
|
'name': {'allow_post': True, 'allow_put': True, 'default': '',
|
||||||
|
'is_visible': True},
|
||||||
'ip_version': {'allow_post': True, 'allow_put': False,
|
'ip_version': {'allow_post': True, 'allow_put': False,
|
||||||
'convert_to': int,
|
'convert_to': int,
|
||||||
'validate': {'type:values': [4, 6]},
|
'validate': {'type:values': [4, 6]},
|
||||||
|
@ -615,6 +615,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
|||||||
|
|
||||||
def _make_subnet_dict(self, subnet, fields=None):
|
def _make_subnet_dict(self, subnet, fields=None):
|
||||||
res = {'id': subnet['id'],
|
res = {'id': subnet['id'],
|
||||||
|
'name': subnet['name'],
|
||||||
'tenant_id': subnet['tenant_id'],
|
'tenant_id': subnet['tenant_id'],
|
||||||
'network_id': subnet['network_id'],
|
'network_id': subnet['network_id'],
|
||||||
'ip_version': subnet['ip_version'],
|
'ip_version': subnet['ip_version'],
|
||||||
@ -627,6 +628,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
|||||||
|
|
||||||
def _make_port_dict(self, port, fields=None):
|
def _make_port_dict(self, port, fields=None):
|
||||||
res = {"id": port["id"],
|
res = {"id": port["id"],
|
||||||
|
'name': port['name'],
|
||||||
"network_id": port["network_id"],
|
"network_id": port["network_id"],
|
||||||
'tenant_id': port['tenant_id'],
|
'tenant_id': port['tenant_id'],
|
||||||
"mac_address": port["mac_address"],
|
"mac_address": port["mac_address"],
|
||||||
@ -694,6 +696,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
|||||||
self._validate_subnet_cidr(network, s['cidr'])
|
self._validate_subnet_cidr(network, s['cidr'])
|
||||||
subnet = models_v2.Subnet(tenant_id=tenant_id,
|
subnet = models_v2.Subnet(tenant_id=tenant_id,
|
||||||
id=s.get('id') or utils.str_uuid(),
|
id=s.get('id') or utils.str_uuid(),
|
||||||
|
name=s['name'],
|
||||||
network_id=s['network_id'],
|
network_id=s['network_id'],
|
||||||
ip_version=s['ip_version'],
|
ip_version=s['ip_version'],
|
||||||
cidr=s['cidr'],
|
cidr=s['cidr'],
|
||||||
@ -765,6 +768,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
|||||||
ips = self._allocate_ips_for_port(context, network, port)
|
ips = self._allocate_ips_for_port(context, network, port)
|
||||||
|
|
||||||
port = models_v2.Port(tenant_id=tenant_id,
|
port = models_v2.Port(tenant_id=tenant_id,
|
||||||
|
name=p['name'],
|
||||||
id=p.get('id') or utils.str_uuid(),
|
id=p.get('id') or utils.str_uuid(),
|
||||||
network_id=p['network_id'],
|
network_id=p['network_id'],
|
||||||
mac_address=p['mac_address'],
|
mac_address=p['mac_address'],
|
||||||
|
@ -88,6 +88,7 @@ class IPAllocation(model_base.BASEV2):
|
|||||||
|
|
||||||
class Port(model_base.BASEV2, HasId, HasTenant):
|
class Port(model_base.BASEV2, HasId, HasTenant):
|
||||||
"""Represents a port on a quantum v2 network."""
|
"""Represents a port on a quantum v2 network."""
|
||||||
|
name = sa.Column(sa.String(255))
|
||||||
network_id = sa.Column(sa.String(36), sa.ForeignKey("networks.id"),
|
network_id = sa.Column(sa.String(36), sa.ForeignKey("networks.id"),
|
||||||
nullable=False)
|
nullable=False)
|
||||||
fixed_ips = orm.relationship(IPAllocation, backref='ports', lazy="dynamic")
|
fixed_ips = orm.relationship(IPAllocation, backref='ports', lazy="dynamic")
|
||||||
@ -103,6 +104,7 @@ class Subnet(model_base.BASEV2, HasId, HasTenant):
|
|||||||
When a subnet is created the first and last entries will be created. These
|
When a subnet is created the first and last entries will be created. These
|
||||||
are used for the IP allocation.
|
are used for the IP allocation.
|
||||||
"""
|
"""
|
||||||
|
name = sa.Column(sa.String(255))
|
||||||
network_id = sa.Column(sa.String(36), sa.ForeignKey('networks.id'))
|
network_id = sa.Column(sa.String(36), sa.ForeignKey('networks.id'))
|
||||||
ip_version = sa.Column(sa.Integer, nullable=False)
|
ip_version = sa.Column(sa.Integer, nullable=False)
|
||||||
cidr = sa.Column(sa.String(64), nullable=False)
|
cidr = sa.Column(sa.String(64), nullable=False)
|
||||||
|
@ -525,8 +525,8 @@ class JSONV2TestCase(APIv2TestBase):
|
|||||||
self.assertEqual(res.status_int, exc.HTTPBadRequest.code)
|
self.assertEqual(res.status_int, exc.HTTPBadRequest.code)
|
||||||
|
|
||||||
def test_create_missing_attr(self):
|
def test_create_missing_attr(self):
|
||||||
data = {'network': {'what': 'who', 'tenant_id': _uuid()}}
|
data = {'port': {'what': 'who', 'tenant_id': _uuid()}}
|
||||||
res = self.api.post_json(_get_path('networks'), data,
|
res = self.api.post_json(_get_path('ports'), data,
|
||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
self.assertEqual(res.status_int, 422)
|
self.assertEqual(res.status_int, 422)
|
||||||
|
|
||||||
@ -562,16 +562,16 @@ class JSONV2TestCase(APIv2TestBase):
|
|||||||
self.assertEqual(res.status_int, exc.HTTPBadRequest.code)
|
self.assertEqual(res.status_int, exc.HTTPBadRequest.code)
|
||||||
|
|
||||||
def test_create_bulk_missing_attr(self):
|
def test_create_bulk_missing_attr(self):
|
||||||
data = {'networks': [{'what': 'who', 'tenant_id': _uuid()}]}
|
data = {'ports': [{'what': 'who', 'tenant_id': _uuid()}]}
|
||||||
res = self.api.post_json(_get_path('networks'), data,
|
res = self.api.post_json(_get_path('ports'), data,
|
||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
self.assertEqual(res.status_int, 422)
|
self.assertEqual(res.status_int, 422)
|
||||||
|
|
||||||
def test_create_bulk_partial_body(self):
|
def test_create_bulk_partial_body(self):
|
||||||
data = {'networks': [{'name': 'net1', 'admin_state_up': True,
|
data = {'ports': [{'device_id': 'device_1',
|
||||||
'tenant_id': _uuid()},
|
'tenant_id': _uuid()},
|
||||||
{'tenant_id': _uuid()}]}
|
{'tenant_id': _uuid()}]}
|
||||||
res = self.api.post_json(_get_path('networks'), data,
|
res = self.api.post_json(_get_path('ports'), data,
|
||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
self.assertEqual(res.status_int, 422)
|
self.assertEqual(res.status_int, 422)
|
||||||
|
|
||||||
@ -579,9 +579,10 @@ class JSONV2TestCase(APIv2TestBase):
|
|||||||
net_id = _uuid()
|
net_id = _uuid()
|
||||||
tenant_id = _uuid()
|
tenant_id = _uuid()
|
||||||
device_id = _uuid()
|
device_id = _uuid()
|
||||||
initial_input = {'port': {'network_id': net_id, 'tenant_id': tenant_id,
|
initial_input = {'port': {'name': '', 'network_id': net_id,
|
||||||
'device_id': device_id,
|
'tenant_id': tenant_id,
|
||||||
'admin_state_up': True}}
|
'device_id': device_id,
|
||||||
|
'admin_state_up': True}}
|
||||||
full_input = {'port': {'admin_state_up': True,
|
full_input = {'port': {'admin_state_up': True,
|
||||||
'mac_address': attributes.ATTR_NOT_SPECIFIED,
|
'mac_address': attributes.ATTR_NOT_SPECIFIED,
|
||||||
'fixed_ips': attributes.ATTR_NOT_SPECIFIED,
|
'fixed_ips': attributes.ATTR_NOT_SPECIFIED,
|
||||||
|
@ -151,7 +151,8 @@ class QuantumDbPluginV2TestCase(unittest2.TestCase):
|
|||||||
content_type = 'application/' + fmt
|
content_type = 'application/' + fmt
|
||||||
data = {'port': {'network_id': net_id,
|
data = {'port': {'network_id': net_id,
|
||||||
'tenant_id': self._tenant_id}}
|
'tenant_id': self._tenant_id}}
|
||||||
for arg in ('admin_state_up', 'device_id', 'mac_address', 'fixed_ips'):
|
for arg in ('admin_state_up', 'device_id', 'mac_address',
|
||||||
|
'name', 'fixed_ips'):
|
||||||
# Arg must be present and not empty
|
# Arg must be present and not empty
|
||||||
if arg in kwargs and kwargs[arg]:
|
if arg in kwargs and kwargs[arg]:
|
||||||
data['port'][arg] = kwargs[arg]
|
data['port'][arg] = kwargs[arg]
|
||||||
@ -220,16 +221,18 @@ class QuantumDbPluginV2TestCase(unittest2.TestCase):
|
|||||||
self._delete('subnets', subnet['subnet']['id'])
|
self._delete('subnets', subnet['subnet']['id'])
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def port(self, subnet=None, fixed_ips=None, fmt='json'):
|
def port(self, subnet=None, fixed_ips=None, fmt='json', **kwargs):
|
||||||
if not subnet:
|
if not subnet:
|
||||||
with self.subnet() as subnet:
|
with self.subnet() as subnet:
|
||||||
net_id = subnet['subnet']['network_id']
|
net_id = subnet['subnet']['network_id']
|
||||||
port = self._make_port(fmt, net_id, fixed_ips=fixed_ips)
|
port = self._make_port(fmt, net_id, fixed_ips=fixed_ips,
|
||||||
|
**kwargs)
|
||||||
yield port
|
yield port
|
||||||
self._delete('ports', port['port']['id'])
|
self._delete('ports', port['port']['id'])
|
||||||
else:
|
else:
|
||||||
net_id = subnet['subnet']['network_id']
|
net_id = subnet['subnet']['network_id']
|
||||||
port = self._make_port(fmt, net_id, fixed_ips=fixed_ips)
|
port = self._make_port(fmt, net_id, fixed_ips=fixed_ips,
|
||||||
|
**kwargs)
|
||||||
yield port
|
yield port
|
||||||
self._delete('ports', port['port']['id'])
|
self._delete('ports', port['port']['id'])
|
||||||
|
|
||||||
@ -340,13 +343,14 @@ class TestV2HTTPResponse(QuantumDbPluginV2TestCase):
|
|||||||
class TestPortsV2(QuantumDbPluginV2TestCase):
|
class TestPortsV2(QuantumDbPluginV2TestCase):
|
||||||
def test_create_port_json(self):
|
def test_create_port_json(self):
|
||||||
keys = [('admin_state_up', True), ('status', 'ACTIVE')]
|
keys = [('admin_state_up', True), ('status', 'ACTIVE')]
|
||||||
with self.port() as port:
|
with self.port(name='myname') as port:
|
||||||
for k, v in keys:
|
for k, v in keys:
|
||||||
self.assertEquals(port['port'][k], v)
|
self.assertEquals(port['port'][k], v)
|
||||||
self.assertTrue('mac_address' in port['port'])
|
self.assertTrue('mac_address' in port['port'])
|
||||||
ips = port['port']['fixed_ips']
|
ips = port['port']['fixed_ips']
|
||||||
self.assertEquals(len(ips), 1)
|
self.assertEquals(len(ips), 1)
|
||||||
self.assertEquals(ips[0]['ip_address'], '10.0.0.2')
|
self.assertEquals(ips[0]['ip_address'], '10.0.0.2')
|
||||||
|
self.assertEquals('myname', port['port']['name'])
|
||||||
|
|
||||||
def test_create_port_bad_tenant(self):
|
def test_create_port_bad_tenant(self):
|
||||||
with self.network() as network:
|
with self.network() as network:
|
||||||
@ -854,8 +858,9 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
|
|||||||
def test_create_subnet(self):
|
def test_create_subnet(self):
|
||||||
gateway_ip = '10.0.0.1'
|
gateway_ip = '10.0.0.1'
|
||||||
cidr = '10.0.0.0/24'
|
cidr = '10.0.0.0/24'
|
||||||
self._test_create_subnet(gateway_ip=gateway_ip,
|
subnet = self._test_create_subnet(gateway_ip=gateway_ip,
|
||||||
cidr=cidr)
|
cidr=cidr)
|
||||||
|
self.assertTrue('name' in subnet['subnet'])
|
||||||
|
|
||||||
def test_create_two_subnets(self):
|
def test_create_two_subnets(self):
|
||||||
gateway_ips = ['10.0.0.1', '10.0.1.1']
|
gateway_ips = ['10.0.0.1', '10.0.1.1']
|
||||||
|
Loading…
Reference in New Issue
Block a user