From a11b8875919579ee8c77740bf45a982ae88cd6b2 Mon Sep 17 00:00:00 2001
From: Dimitris Aragiorgis <dimara@grnet.gr>
Date: Mon, 4 Jun 2012 22:37:12 +0300
Subject: [PATCH] Modify RemoveInstance() to support networks

Release any IPs held the instance before actually removing.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
---
 lib/config.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/config.py b/lib/config.py
index 224a9870a..1367a1aa3 100644
--- a/lib/config.py
+++ b/lib/config.py
@@ -1421,6 +1421,16 @@ class ConfigWriter:
     if network_port is not None:
       self._config_data.cluster.tcpudp_port_pool.add(network_port)
 
+    instance = self._UnlockedGetInstanceInfo(instance_name)
+
+    for nic in instance.nics:
+      if nic.network is not None and nic.ip is not None:
+        net_uuid = self._UnlockedLookupNetwork(nic.network)
+        if net_uuid:
+          # Return all IP addresses to the respective address pools
+          self._UnlockedCommitIp('release', net_uuid, nic.ip)
+
+
     del self._config_data.instances[instance_name]
     self._config_data.cluster.serial_no += 1
     self._WriteConfig()
-- 
GitLab