From 168c514d692044f8ccadba8ba5340efaa3160be7 Mon Sep 17 00:00:00 2001
From: Florian Schaal <florian@schaal-24.de>
Date: Tue, 18 Aug 2015 17:17:33 +0200
Subject: [PATCH] when changing the ip_address for a vm set the old ip to
 "unused"

---
 interface/lib/plugins/vm_openvz_plugin.inc.php | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/interface/lib/plugins/vm_openvz_plugin.inc.php b/interface/lib/plugins/vm_openvz_plugin.inc.php
index 73cc9cda86..9d54b6b1a9 100644
--- a/interface/lib/plugins/vm_openvz_plugin.inc.php
+++ b/interface/lib/plugins/vm_openvz_plugin.inc.php
@@ -94,7 +94,10 @@ class vm_openvz_plugin {
 		}
 
 		// Set the IP address
-		if(isset($this->dataRecord['ip_address'])) $app->db->query("UPDATE openvz_ip SET vm_id = ? WHERE ip_address = ?", $this->id, $this->dataRecord['ip_address']);
+		if(isset($this->dataRecord['ip_address'])) {
+			$app->db->query("UPDATE openvz_ip SET vm_id = 0 WHERE vm_id = ?", $this->id);
+			$app->db->query("UPDATE openvz_ip SET vm_id = ? WHERE ip_address = ?", $this->id, $this->dataRecord['ip_address']);
+		}
 
 		// Create the OpenVZ config file and store it in config field
 		$this->makeOpenVZConfig();
-- 
GitLab