Two functions, checking for UUID to be present,
or uniqueness.

Signed-off-by: BSRK Aditya <[email protected]>
---
 src/Ganeti/WConfd/ConfigModifications.hs |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/Ganeti/WConfd/ConfigModifications.hs 
b/src/Ganeti/WConfd/ConfigModifications.hs
index 9940050..f489732 100644
--- a/src/Ganeti/WConfd/ConfigModifications.hs
+++ b/src/Ganeti/WConfd/ConfigModifications.hs
@@ -39,6 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 module Ganeti.WConfd.ConfigModifications where
 
+import Control.Applicative ((<$>))
 import Control.Lens.Setter ((.~))
 import Control.Lens.Traversal (mapMOf)
 import Data.List (nub)
@@ -142,6 +143,20 @@ getAllIDs cs = do
 getAllMACs :: ConfigState -> [String]
 getAllMACs = map nicMac . concatMap instNics . M.elems
            . fromContainer . configInstances . csConfigData
+
+-- * UUID config checks
+
+checkUUIDpresent :: UuidObject a
+                 => ConfigState
+                 -> a
+                 -> GenericResult GanetiException Bool
+checkUUIDpresent cs a = getAllIDs cs >>= \ids -> return $ elem (uuidOf a) ids
+
+checkUniqueUUID :: UuidObject a
+                => ConfigState
+                -> a
+                -> GenericResult GanetiException Bool
+checkUniqueUUID cs a = not <$> checkUUIDpresent cs a
 -- | 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

Reply via email to