Commit eea48fa9 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Series of fixes regarding networks & ips

* Do not delete the network from the DB if it has associated floating
  IPs. This should never be the case because a check is made before
  deleting the network, however this check is added for safety.
* Do not allow deleting a network if there are still ports configured on
  on that network. Until now this check was for machines, but there may
  be ports that are not connected to any machine.
* Delete subnet IP pools when network is deleted.
* Get network in locked mode in network-remove cmd.
* Log error if trying to release an IPv4 address that does not belong to
  any of the IP pools of the associated subnet.
* Excluded deleted IPv4 addresses when reconciling IP pools.
* Do not set the network action to destroy when removing network from
  some backend.
parent bd74e9f2
......@@ -176,8 +176,6 @@ class Command(BaseCommand):
msg = "Can not remove. There are still connected VMs to this"\
" network"
raise CommandError(msg)
network.action = "DESTROY"
backend_mod.delete_network(network, backend, disconnect=True)
msg = "Sent job to delete network '%s' from backend '%s'\n"
self.stdout.write(msg % (network, backend))
......@@ -42,7 +42,7 @@ class Command(BaseCommand):
if len(args) < 1:
raise CommandError("Please provide a network ID")
network = get_network(args[0])
network = get_network(args[0], for_update=True)
self.stdout.write('Removing network: %s\n' % network.backend_id)
......@@ -754,6 +754,10 @@ class IPAddress(models.Model):
if ip_pool.contains(self.address):
log.error("Can not release address %s of NIC %s. Address does not"
" belong to any of the IP pools of the subnet %s !",
self.address, self.nic, self.subnet_id)
class IPAddressLog(models.Model):
......@@ -388,6 +388,7 @@ def process_network_status(back_network, etime, jobid, opcode, status, logmsg):
back_network.backendopcode = opcode
back_network.backendlogmsg = logmsg
# Note: Network is already locked!
network =
# Notifications of success change the operating state
......@@ -449,6 +450,10 @@ def update_network_state(network):
# Release the resources on the deletion of the Network
if deleted:
if network.ips.filter(deleted=False, floating_ip=True).exists():
msg = "Can not delete network %s! Floating IPs still in use!"
log.error(msg % network)
raise Exception(msg % network)"Network %r deleted. Releasing link %r mac_prefix %r",, network.mac_prefix,
network.deleted = True
......@@ -461,6 +466,13 @@ def update_network_state(network):
if network.FLAVORS[network.flavor]["link"] == "pool":
# Set all subnets as deleted
# And delete the IP pools
for subnet in network.subnets.all():
if subnet.ipversion == 4:
# Issue commission
if network.userid:
quotas.issue_and_accept_commission(network, delete=True)
......@@ -470,12 +482,6 @@ def update_network_state(network):
elif not network.public:
log.warning("Network %s does not have an owner!",
# TODO!!!!!
# Set all subnets as deleted
# And delete the IP pools
......@@ -152,9 +152,9 @@ def rename(network, name):
def delete(network):
if network.machines.exists():
raise faults.Conflict("Can not delete network. Servers connected"
" to this network exists.")
if network.nics.exists():
raise faults.Conflict("Can not delete network. There are ports still"
" configured on network network %s" %
if network.ips.filter(deleted=False, floating_ip=True).exists():
msg = "Can not delete netowrk. Network has allocated floating IPs."
raise faults.Conflict(msg)
......@@ -715,6 +715,7 @@ class PoolReconciler(object):
for ip_pool in network.get_ip_pools():
used_ips = ip_pool.pool_table.subnet\
.values_list("address", flat=True)
used_ips = filter(lambda x: ip_pool.contains(x), used_ips)
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