# of number of items.
# pagination_max_limit = -1
+# Maximum number of DNS nameservers per subnet
+# max_dns_nameservers = 5
+
+# Maximum number of host routes per subnet
+# max_subnet_host_routes = 20
+
+# Maximum number of fixed ips per port
+# max_fixed_ips_per_port = 5
+
[QUOTAS]
# resource name(s) that are supported in quota features
# quota_items = network,subnet,port
help=_("Maximum number of DNS nameservers")),
cfg.IntOpt('max_subnet_host_routes', default=20,
help=_("Maximum number of host routes per subnet")),
+ cfg.IntOpt('max_fixed_ips_per_port', default=5,
+ help=_("Maximum number of fixed ips per port")),
cfg.IntOpt('dhcp_lease_duration', default=120,
help=_("DHCP lease duration")),
cfg.BoolOpt('dhcp_agent_notification', default=True,
'ip_address': fixed['ip_address']})
else:
fixed_ip_set.append({'subnet_id': subnet_id})
+ if len(fixed_ip_set) > cfg.CONF.max_fixed_ips_per_port:
+ msg = _('Exceeded maximim amount of fixed ips per port')
+ raise q_exc.InvalidInput(error_message=msg)
return fixed_ip_set
def _allocate_fixed_ips(self, context, network, fixed_ips):
"""Add or remove IPs from the port."""
ips = []
+ # the new_ips contain all of the fixed_ips that are to be updated
+ if len(new_ips) > cfg.CONF.max_fixed_ips_per_port:
+ msg = _('Exceeded maximim amount of fixed ips per port')
+ raise q_exc.InvalidInput(error_message=msg)
+
# Remove all of the intersecting elements
for original_ip in original_ips[:]:
for new_ip in new_ips[:]:
self.assertEqual(update_context._recycled_networks,
set([subnet['subnet']['network_id']]))
+ def test_max_fixed_ips_exceeded(self):
+ with self.subnet(gateway_ip='10.0.0.3',
+ cidr='10.0.0.0/24') as subnet:
+ kwargs = {"fixed_ips":
+ [{'subnet_id': subnet['subnet']['id']},
+ {'subnet_id': subnet['subnet']['id']},
+ {'subnet_id': subnet['subnet']['id']},
+ {'subnet_id': subnet['subnet']['id']},
+ {'subnet_id': subnet['subnet']['id']},
+ {'subnet_id': subnet['subnet']['id']}]}
+ net_id = subnet['subnet']['network_id']
+ res = self._create_port(self.fmt, net_id=net_id, **kwargs)
+ self.assertEqual(res.status_int, 400)
+
+ def test_update_max_fixed_ips_exceeded(self):
+ with self.subnet(gateway_ip='10.0.0.3',
+ cidr='10.0.0.0/24') as subnet:
+ with self.port(subnet) as port:
+ data = {'port': {'fixed_ips':
+ [{'subnet_id': subnet['subnet']['id'],
+ 'ip_address': '10.0.0.2'},
+ {'subnet_id': subnet['subnet']['id'],
+ 'ip_address': '10.0.0.4'},
+ {'subnet_id': subnet['subnet']['id']},
+ {'subnet_id': subnet['subnet']['id']},
+ {'subnet_id': subnet['subnet']['id']},
+ {'subnet_id': subnet['subnet']['id']}]}}
+ req = self.new_update_request('ports', data,
+ port['port']['id'])
+ res = req.get_response(self.api)
+ self.assertEqual(res.status_int, 400)
+
class TestNetworksV2(QuantumDbPluginV2TestCase):
# NOTE(cerberus): successful network update and delete are