Adds quotas for fixed IPs on ports

RM11643

Implements quota checking the number of fixed IP addresses allowed on a
port on create and update port, as well as create and update IP Address.
This commit is contained in:
Matt Dietz
2015-03-13 09:10:12 +00:00
parent f361b92f73
commit 256285a9d8
5 changed files with 152 additions and 4 deletions

View File

@@ -14,6 +14,7 @@
# under the License.
from neutron.common import exceptions
from neutron import quota
from oslo.config import cfg
from oslo_log import log as logging
import webob
@@ -65,6 +66,13 @@ def validate_ports_on_network_and_same_segment(ports, network_id):
msg="Segment id's do not match.")
def validate_port_ip_quotas(context, ports):
for port in ports:
addresses = port.get("ip_addresses", [])
quota.QUOTAS.limit_check(context, context.tenant_id,
fixed_ips_per_port=len(addresses) + 1)
def _shared_ip_request(ip_address):
port_ids = ip_address.get('ip_address', {}).get('port_ids', [])
return len(port_ids) > 1
@@ -117,6 +125,7 @@ def create_ip_address(context, body):
net_id=network_id)
validate_ports_on_network_and_same_segment(ports, network_id)
validate_port_ip_quotas(context, ports)
# Shared Ips are only new IPs. Two use cases: if we got device_id
# or if we got port_ids. We should check the case where we got port_ids
@@ -185,6 +194,7 @@ def update_ip_address(context, id, ip_address):
validate_ports_on_network_and_same_segment(ports,
address["network_id"])
validate_port_ip_quotas(context, ports)
LOG.info("Updating IP address, %s, to only be used by the"
"following ports: %s" % (address.address_readable,