Hs2Py constants: add RPC timeout constants
authorJose A. Lopes <jabolopes@google.com>
Wed, 2 Oct 2013 15:18:14 +0000 (17:18 +0200)
committerJose A. Lopes <jabolopes@google.com>
Tue, 8 Oct 2013 12:57:26 +0000 (14:57 +0200)
Add RPC timeout related constants to the Haskell to Python constant
generation.  The Haskell data type 'RpcTimeout' is moved from
'Ganeti.Rpc' to 'Ganeti.Types' so it can be used by
'Ganeti.HsConstants' without causing circularity problems with
'Ganeti.Rpc'.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>

lib/constants.py
src/Ganeti/HsConstants.hs
src/Ganeti/Rpc.hs
src/Ganeti/Types.hs

index f8bc699..8319124 100644 (file)
@@ -629,6 +629,14 @@ DISK_TRANSFER_CONNECT_TIMEOUT = 60
 DISK_SEPARATOR = _constants.DISK_SEPARATOR
 IP_COMMAND_PATH = _constants.IP_COMMAND_PATH
 
+RPC_TMO_URGENT = _constants.RPC_TMO_URGENT
+RPC_TMO_FAST = _constants.RPC_TMO_FAST
+RPC_TMO_NORMAL = _constants.RPC_TMO_NORMAL
+RPC_TMO_SLOW = _constants.RPC_TMO_SLOW
+RPC_TMO_4HRS = _constants.RPC_TMO_4HRS
+RPC_TMO_1DAY = _constants.RPC_TMO_1DAY
+RPC_CONNECT_TIMEOUT = _constants.RPC_CONNECT_TIMEOUT
+
 #: Key for job IDs in opcode result
 JOB_IDS_KEY = "jobs"
 
@@ -647,17 +655,6 @@ RUNPARTS_STATUS = compat.UniqueFrozenset([
 (RPC_ENCODING_NONE,
  RPC_ENCODING_ZLIB_BASE64) = range(2)
 
-# Various time constants for the timeout table
-RPC_TMO_URGENT = 60 # one minute
-RPC_TMO_FAST = 5 * 60 # five minutes
-RPC_TMO_NORMAL = 15 * 60 # 15 minutes
-RPC_TMO_SLOW = 3600 # one hour
-RPC_TMO_4HRS = 4 * 3600
-RPC_TMO_1DAY = 86400
-
-# Timeout for connecting to nodes (seconds)
-RPC_CONNECT_TIMEOUT = 5
-
 # os related constants
 OS_SCRIPT_CREATE = "create"
 OS_SCRIPT_IMPORT = "import"
index 440d2e0..195bc2f 100644 (file)
@@ -55,6 +55,8 @@ import Ganeti.Confd.Types (ConfdRequestType(..), ConfdReqField(..),
                            ConfdErrorType(..))
 import qualified Ganeti.Confd.Types as Types
 
+{-# ANN module "HLint: ignore Use camelCase" #-}
+
 -- * 'autoconf' constants for Python only ('autotools/build-bash-completion')
 
 htoolsProgs :: [String]
@@ -630,6 +632,38 @@ nodeMaxClockSkew = 150
 diskSeparator :: String
 diskSeparator = AutoConf.diskSeparator
 
+-- * Timeout table
+--
+-- Various time constants for the timeout table
+
+rpcTmoUrgent :: Int
+rpcTmoUrgent = Types.rpcTimeoutToRaw Urgent
+
+rpcTmoFast :: Int
+rpcTmoFast = Types.rpcTimeoutToRaw Fast
+
+rpcTmoNormal :: Int
+rpcTmoNormal = Types.rpcTimeoutToRaw Normal
+
+rpcTmoSlow :: Int
+rpcTmoSlow = Types.rpcTimeoutToRaw Slow
+
+-- | 'rpcTmo_4hrs' contains an underscore to circumvent a limitation
+-- in the 'Ganeti.THH.deCamelCase' function and generate the correct
+-- Python name.
+rpcTmo_4hrs :: Int
+rpcTmo_4hrs = Types.rpcTimeoutToRaw FourHours
+
+-- | 'rpcTmo_1day' contains an underscore to circumvent a limitation
+-- in the 'Ganeti.THH.deCamelCase' function and generate the correct
+-- Python name.
+rpcTmo_1day :: Int
+rpcTmo_1day = Types.rpcTimeoutToRaw OneDay
+
+-- | Timeout for connecting to nodes (seconds)
+rpcConnectTimeout :: Int
+rpcConnectTimeout = 5
+
 ipCommandPath :: String
 ipCommandPath = AutoConf.ipPath
 
index a311b21..d69c9b7 100644 (file)
@@ -68,8 +68,6 @@ module Ganeti.Rpc
 
   , RpcCallExportList(..)
   , RpcResultExportList(..)
-
-  , rpcTimeoutFromRaw -- FIXME: Not used anywhere
   ) where
 
 import Control.Arrow (second)
@@ -123,16 +121,6 @@ explainRpcError OfflineNodeError =
 
 type ERpcError = Either RpcError
 
--- | Basic timeouts for RPC calls.
-$(declareIADT "RpcTimeout"
-  [ ( "Urgent",    'C.rpcTmoUrgent )
-  , ( "Fast",      'C.rpcTmoFast )
-  , ( "Normal",    'C.rpcTmoNormal )
-  , ( "Slow",      'C.rpcTmoSlow )
-  , ( "FourHours", 'C.rpcTmo4hrs )
-  , ( "OneDay",    'C.rpcTmo1day )
-  ])
-
 -- | A generic class for RPC calls.
 class (J.JSON a) => RpcCall a where
   -- | Give the (Python) name of the procedure.
index 5a788be..e737065 100644 (file)
@@ -145,6 +145,9 @@ module Ganeti.Types
   , diskAccessModeToRaw
   , ReplaceDisksMode(..)
   , replaceDisksModeToRaw
+  , RpcTimeout(..)
+  , rpcTimeoutFromRaw -- FIXME: no used anywhere
+  , rpcTimeoutToRaw
   ) where
 
 import Control.Monad (liftM)
@@ -793,3 +796,13 @@ $(THH.declareLADT ''String "ReplaceDisksMode"
   , ("ReplaceAuto",         "replace_auto")
   ])
 $(THH.makeJSONInstance ''ReplaceDisksMode)
+
+-- | Basic timeouts for RPC calls.
+$(THH.declareILADT "RpcTimeout"
+  [ ("Urgent",    60)       -- 1 minute
+  , ("Fast",      5 * 60)   -- 5 minutes
+  , ("Normal",    15 * 60)  -- 15 minutes
+  , ("Slow",      3600)     -- 1 hour
+  , ("FourHours", 4 * 3600) -- 4 hours
+  , ("OneDay",    86400)    -- 1 day
+  ])