Revision 15a53b1e

b/src/Ganeti/Locking/Locks.hs
28 28
  , GanetiLockAllocation
29 29
  ) where
30 30

  
31
import Control.Monad (liftM)
32
import qualified Text.JSON as J
33

  
34
import Ganeti.JSON (asJSObject, fromObj)
31 35
import Ganeti.Locking.Allocation
32 36
import Ganeti.Locking.Types
33 37
import Ganeti.Types
......
37 41
data GanetiLocks = BGL deriving (Ord, Eq, Show)
38 42
-- TODO: add the remaining locks
39 43

  
44
-- | Describe the parts the pieces of information that are needed to
45
-- describe the lock.
46
lockData :: GanetiLocks -> [(String, J.JSValue)]
47
lockData BGL = [("type", J.showJSON "BGL")]
48

  
49
-- | Read a lock form its JSON representation.
50
readLock :: J.JSValue -> J.Result GanetiLocks
51
readLock v =  do
52
  fields <- liftM J.fromJSObject $ asJSObject v
53
  tp <- fromObj fields "type"
54
  case tp of
55
    "BGL" -> return BGL
56
    _ -> fail $ "Unknown lock type " ++ tp
57

  
58
instance J.JSON GanetiLocks where
59
  showJSON = J.JSObject . J.toJSObject . lockData
60
  readJSON = readLock
61

  
62

  
40 63
instance Lock GanetiLocks where
41 64
  lockImplications BGL = []
42 65

  

Also available in: Unified diff