From 87e439883e8d2542596e71ec7d2fa5faafbc3dd2 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 8 Sep 2009 14:29:26 +0200
Subject: [PATCH] Add check for duplicate MACs in instance add

Currently LUAddInstance doesn't check for duplicate MACs, and it fails
during the Exec() phase when trying to add the instance to the config
(ConfigWriter checks for this). This patch copies the code from
LUModifyInstance (which already does it).

This fixed issue #70.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Olivier Tharan <olive@google.com>
---
 lib/cmdlib.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index e65aef896..65aada0d8 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -4592,6 +4592,12 @@ class LUCreateInstance(LogicalUnit):
         if not utils.IsValidMac(mac.lower()):
           raise errors.OpPrereqError("Invalid MAC address specified: %s" %
                                      mac)
+        else:
+          # or validate/reserve the current one
+          if self.cfg.IsMacInUse(mac):
+            raise errors.OpPrereqError("MAC address %s already in use"
+                                       " in cluster" % mac)
+
       # bridge verification
       bridge = nic.get("bridge", None)
       if bridge is None:
-- 
GitLab