Checks for MAC usage, and UUID config
being present/unique.
Signed-off-by: BSRK Aditya <[email protected]>
---
src/Ganeti/WConfd/ConfigModifications.hs | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/src/Ganeti/WConfd/ConfigModifications.hs
b/src/Ganeti/WConfd/ConfigModifications.hs
index f489732..9bb46d8 100644
--- a/src/Ganeti/WConfd/ConfigModifications.hs
+++ b/src/Ganeti/WConfd/ConfigModifications.hs
@@ -42,7 +42,8 @@ module Ganeti.WConfd.ConfigModifications where
import Control.Applicative ((<$>))
import Control.Lens.Setter ((.~))
import Control.Lens.Traversal (mapMOf)
-import Data.List (nub)
+import Control.Monad (unless)
+import Data.List (nub, intersect)
import Data.Maybe (isJust)
import Language.Haskell.TH (Name)
import Text.Printf (printf)
@@ -157,6 +158,31 @@ checkUniqueUUID :: UuidObject a
-> a
-> GenericResult GanetiException Bool
checkUniqueUUID cs a = not <$> checkUUIDpresent cs a
+
+-- * RPC checks
+
+addInstanceChecks :: Instance
+ -> Bool
+ -> ConfigState
+ -> GenericResult GanetiException ()
+addInstanceChecks inst replace cs = do
+ let macsInUse = map nicMac (instNics inst) `intersect` getAllMACs cs
+ if null macsInUse
+ then Ok ()
+ else Bad . ConfigurationError $ printf
+ "Cannot add instance %s; MAC addresses %s already in use"
+ (show $ instName inst) (show macsInUse)
+ if replace
+ then do
+ check <- checkUUIDpresent cs inst
+ unless check . Bad . ConfigurationError $ printf
+ "Cannot add %s: UUID %s already in use"
+ (show $ instName inst) (instUuid inst)
+ else do
+ check <- checkUniqueUUID cs inst
+ unless check . Bad . ConfigurationError $ printf
+ "Cannot replace %s: UUID %s not present"
+ (show $ instName inst) (instUuid inst)
-- | Add a new instance to the configuration, release DRBD minors,
-- and commit temporary IPs, all while temporarily holding the config
-- lock. Return True upon success and False if the config lock was not
--
1.7.10.4