Revision 56c094b4

b/htools/Ganeti/Jobs.hs
4 4

  
5 5
{-
6 6

  
7
Copyright (C) 2009, 2010 Google Inc.
7
Copyright (C) 2009, 2010, 2011 Google Inc.
8 8

  
9 9
This program is free software; you can redistribute it and/or modify
10 10
it under the terms of the GNU General Public License as published by
......
31 31
import Text.JSON (readJSON, showJSON, JSON)
32 32
import qualified Text.JSON as J
33 33

  
34
import qualified Ganeti.Constants as C
35

  
34 36
data OpStatus = OP_STATUS_QUEUED
35 37
              | OP_STATUS_WAITLOCK
36 38
              | OP_STATUS_CANCELING
......
43 45
instance JSON OpStatus where
44 46
    showJSON os = showJSON w
45 47
      where w = case os of
46
              OP_STATUS_QUEUED -> "queued"
47
              OP_STATUS_WAITLOCK -> "waiting"
48
              OP_STATUS_CANCELING -> "canceling"
49
              OP_STATUS_RUNNING -> "running"
50
              OP_STATUS_CANCELED -> "canceled"
51
              OP_STATUS_SUCCESS -> "success"
52
              OP_STATUS_ERROR -> "error"
48
              OP_STATUS_QUEUED -> C.jobStatusQueued
49
              OP_STATUS_WAITLOCK -> C.jobStatusWaitlock
50
              OP_STATUS_CANCELING -> C.jobStatusCanceling
51
              OP_STATUS_RUNNING -> C.jobStatusRunning
52
              OP_STATUS_CANCELED -> C.jobStatusCanceled
53
              OP_STATUS_SUCCESS -> C.jobStatusSuccess
54
              OP_STATUS_ERROR -> C.jobStatusError
53 55
    readJSON s = case readJSON s of
54
      J.Ok "queued" -> J.Ok OP_STATUS_QUEUED
55
      J.Ok "waiting" -> J.Ok OP_STATUS_WAITLOCK
56
      J.Ok "canceling" -> J.Ok OP_STATUS_CANCELING
57
      J.Ok "running" -> J.Ok OP_STATUS_RUNNING
58
      J.Ok "canceled" -> J.Ok OP_STATUS_CANCELED
59
      J.Ok "success" -> J.Ok OP_STATUS_SUCCESS
60
      J.Ok "error" -> J.Ok OP_STATUS_ERROR
61
      _ -> J.Error ("Unknown opcode status " ++ show s)
56
      J.Ok v | v == C.jobStatusQueued -> J.Ok OP_STATUS_QUEUED
57
             | v == C.jobStatusWaitlock -> J.Ok OP_STATUS_WAITLOCK
58
             | v == C.jobStatusCanceling -> J.Ok OP_STATUS_CANCELING
59
             | v == C.jobStatusRunning -> J.Ok OP_STATUS_RUNNING
60
             | v == C.jobStatusCanceled -> J.Ok OP_STATUS_CANCELED
61
             | v == C.jobStatusSuccess -> J.Ok OP_STATUS_SUCCESS
62
             | v == C.jobStatusError -> J.Ok OP_STATUS_ERROR
63
             | otherwise -> J.Error ("Unknown opcode status " ++ v)
64
      _ -> J.Error ("Cannot parse opcode status " ++ show s)
62 65

  
63 66
-- | The JobStatus data type. Note that this is ordered especially
64 67
-- such that greater\/lesser comparison on values of this type makes

Also available in: Unified diff