Commit 395f0023 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Forbid new ports no deleting network

Do not allow creation of new ports and reservation of floating IPs on
network that are being deleted. Currently the state of the network
changes only when the network gets deleted from all backends. So we
check if a network is being deleted by checking if the action of the
network is 'DESTROY'.
parent 8a21b588
......@@ -157,9 +157,12 @@ def allocate_floating_ip(request):
network = util.get_network(network_id, userid, for_update=True,
non_deleted=True)
if not network.floating_ip_pool:
msg = ("Can not allocate floating IP from network %s. Network is"
" not a floating IP pool." % network)
raise faults.Conflict(msg)
msg = ("Can not allocate floating IP. Network %s is"
" not a floating IP pool.")
raise faults.Conflict(msg % network.id)
if network.action == "DESTROY":
msg = "Can not allocate floating IP. Network %s is being deleted."
raise faults.Conflict(msg % network.id)
address = api.utils.get_attribute(floating_ip_dict,
"floating_ip_address",
......
......@@ -307,6 +307,9 @@ def allocate_ip_from_pools(pool_rows, userid, address=None, floating_ip=False):
def allocate_ip(network, userid, address=None, floating_ip=False):
"""Try to allocate an IP from networks IP pools."""
if network.action == "DESTROY":
raise faults.Conflict("Can not allocate IP. Network %s is being"
" deleted" % network.id)
ip_pools = IPPoolTable.objects.select_for_update()\
.filter(subnet__network=network)
try:
......@@ -336,6 +339,7 @@ def allocate_public_ip(userid, floating_ip=False, backend=None):
ip_pool_rows = IPPoolTable.objects.select_for_update()\
.prefetch_related("subnet__network")\
.filter(subnet__deleted=False)\
.filter(subnet__network__deleted=False)\
.filter(subnet__network__public=True)\
.filter(subnet__network__drained=False)
if floating_ip:
......
......@@ -160,6 +160,9 @@ def delete(network):
raise faults.Conflict(msg)
network.action = "DESTROY"
# Mark network as drained to prevent automatic allocation of
# public/floating IPs while the network is being deleted
network.drained = True
network.save()
# Delete network to all backends that exists
......
......@@ -456,6 +456,9 @@ def _create_port(userid, network, machine=None, use_ipaddress=None,
if network.state != "ACTIVE":
raise faults.BuildInProgress("Can not create port while network is in"
" state %s" % network.state)
if network.action == "DESTROY":
msg = "Can not create port. Network %s is being deleted."
raise faults.Conflict(msg % network.id)
ipaddress = None
if use_ipaddress is not None:
# Use an existing IPAddress object.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment