The RPC now does all possible operations
on the haskell end.

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

diff --git a/src/Ganeti/WConfd/ConfigModifications.hs 
b/src/Ganeti/WConfd/ConfigModifications.hs
index 9bb46d8..3167392 100644
--- a/src/Ganeti/WConfd/ConfigModifications.hs
+++ b/src/Ganeti/WConfd/ConfigModifications.hs
@@ -43,13 +43,15 @@ import Control.Applicative ((<$>))
 import Control.Lens.Setter ((.~))
 import Control.Lens.Traversal (mapMOf)
 import Control.Monad (unless)
+import Control.Monad.IO.Class (liftIO)
 import Data.List (nub, intersect)
 import Data.Maybe (isJust)
 import Language.Haskell.TH (Name)
+import System.Time (getClockTime)
 import Text.Printf (printf)
 import qualified Data.Map as M
 
-import Ganeti.BasicTypes (GenericResult(..))
+import Ganeti.BasicTypes (GenericResult(..), toError)
 import Ganeti.Errors (GanetiException(..))
 import Ganeti.JSON (GenericContainer(..), Container
                    , alterContainerL, lookupContainer)
@@ -183,24 +185,28 @@ addInstanceChecks inst replace cs = do
       unless check . Bad . ConfigurationError $ printf
              "Cannot replace %s: UUID %s not present"
              (show $ instName inst) (instUuid inst)
+
+-- * RPCs
+
 -- | 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
 -- available and the client should retry.
---
--- TODO: add verifications to this call; the client should have a lock
--- on the name of the instance, and no instance with the given uuid should
--- exist.
-addInstance :: Instance -> ClientId -> WConfdMonad Bool
-addInstance inst cid = do
+addInstance :: Instance -> ClientId -> Bool -> WConfdMonad Bool
+addInstance inst cid replace = do
+  ct <- liftIO getClockTime
   logDebug $ "AddInstance: client " ++ show (ciIdentifier cid)
              ++ " adding instance " ++ uuidOf inst
              ++ " with name " ++ show (instName inst)
-  let addInst = csConfigDataL . configInstancesL . alterContainerL (uuidOf 
inst)
-                  .~ Just inst
+  let setCtime = instCtimeL .~ ct
+      setMtime = instMtimeL .~ ct
+      addInst i = csConfigDataL . configInstancesL . alterContainerL (uuidOf i)
+                  .~ Just i
       commitRes tr = mapMOf csConfigDataL $ T.commitReservedIps cid tr
   r <- modifyConfigWithLock
-         (\tr cs -> commitRes tr $ addInst  cs)
+         (\tr cs -> do
+           toError $ addInstanceChecks inst replace cs
+           commitRes tr $ addInst (setMtime . setCtime $ inst) cs)
          . T.releaseDRBDMinors $ uuidOf inst
   logDebug $ "AddInstance: result of config modification is " ++ show r
   return $ isJust r
-- 
1.7.10.4

Reply via email to