Commit 0319a41b authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Allow deletion of ports from public nets

Move check about deleting a port from a public network. This check is
only enforced in the API, but is allowed in logic layer, e.g. snf-manage
commands.
parent aa4ea79a
......@@ -218,6 +218,13 @@ def delete_port(request, port_id):
log.info('delete_port %s', port_id)
user_id = request.user_uniq
port = util.get_port(port_id, user_id, for_update=True)
# Deleting port that is connected to a public network is allowed only if
# the port has an associated floating IP address.
if port.network.public and not port.ips.filter(floating_ip=True,
deleted=False).exists():
raise faults.Forbidden("Cannot disconnect from public network.")
servers.delete_port(port)
return HttpResponse(status=204)
......
......@@ -499,16 +499,10 @@ def delete_port(port):
Send a Job to remove the NIC card from the instance. The port
will be deleted and the associated IPv4 addressess will be released
when the job completes successfully. Deleting port that is connected to
a public network is allowed only if the port has an associated floating IP
address.
when the job completes successfully.
"""
if port.network.public and not port.ips.filter(floating_ip=True,
deleted=False).exists():
raise faults.Forbidden("Cannot disconnect from public network.")
if port.machine is not None:
vm = disconnect(port.machine, port)
log.info("Removing port %s, Job: %s", port, vm.task_job_id)
......
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