Revision 144f190b

b/Ganeti/HTools/IAlloc.hs
15 15
import Text.Printf (printf)
16 16
import Ganeti.HTools.Utils
17 17

  
18
data RqType
19
    = Allocate
20
    | Relocate
21
    deriving (Show)
22

  
18 23
parseInstance :: String -> JSObject JSValue -> Either String String
19 24
parseInstance n a =
20 25
    let name = Right n
......
57 62
       concatEitherElems (show `applyEither1` dtotal)
58 63
                             (show `applyEither1` dfree)
59 64

  
65
validateRequest :: String -> Either String RqType
66
validateRequest rq =
67
    case rq of
68
      "allocate" -> Right Allocate
69
      "relocate" -> Right Relocate
70
      _ -> Left ("Invalid request type '" ++ rq ++ "'")
71

  
60 72
parseData :: String -> Either String (String, String)
61 73
parseData body =
62 74
    let
63 75
        decoded = resultToEither $ decodeStrict body
64 76
        obj = decoded -- decoded `combineEithers` fromJSObject
77
        -- request parser
65 78
        request = obj `combineEithers` getObjectElement "request"
66 79
        rname = request `combineEithers` getStringElement "name"
80
        rtype = request `combineEithers` getStringElement "type"
81
                `combineEithers` validateRequest
82
        -- existing intstance parsing
67 83
        ilist = obj `combineEithers` getObjectElement "instances"
68
        nlist = obj `combineEithers` getObjectElement "nodes"
69 84
        idata = applyEither1 fromJSObject ilist
70
        ndata = applyEither1 fromJSObject nlist
71 85
        iobj = idata `combineEithers` (ensureEitherList .
72 86
                                       map (\(x,y) ->
73 87
                                           asJSObject y `combineEithers`
74 88
                                                      parseInstance x))
75 89
        ilines = iobj `combineEithers` (Right . unlines)
90
        -- existing node parsing
91
        nlist = obj `combineEithers` getObjectElement "nodes"
92
        ndata = applyEither1 fromJSObject nlist
76 93
        nobj = ndata `combineEithers` (ensureEitherList .
77 94
                                       map (\(x,y) ->
78 95
                                           asJSObject y `combineEithers`

Also available in: Unified diff