-}
-{-# LANGUAGE BangPatterns #-}
+{-# LANGUAGE BangPatterns, CPP #-}
module Ganeti.HTools.Rapi
(
) where
import Data.Maybe (fromMaybe)
+#ifndef NO_CURL
import Network.Curl
import Network.Curl.Types ()
+#endif
import Control.Monad
import Text.JSON (JSObject, JSValue, fromJSObject, decodeStrict)
import Text.JSON.Types (JSValue(..))
import qualified Ganeti.HTools.Node as Node
import qualified Ganeti.HTools.Instance as Instance
+-- | Read an URL via curl and return the body if successful.
+getUrl :: (Monad m) => String -> IO (m String)
+
+#ifdef NO_CURL
+getUrl _ = return $ fail "RAPI/curl backend disabled at compile time"
+
+#else
+
-- | The curl options we use
curlOpts :: [CurlOption]
curlOpts = [ CurlSSLVerifyPeer False
, CurlConnectTimeout (fromIntegral connTimeout)
]
--- | Read an URL via curl and return the body if successful.
-getUrl :: (Monad m) => String -> IO (m String)
getUrl url = do
(code, !body) <- curlGetString url curlOpts
return (case code of
CurlOK -> return body
_ -> fail $ printf "Curl error for '%s', error %s"
url (show code))
+#endif
-- | Append the default port if not passed in.
formatHost :: String -> String
getFakeGroups :: Result [(String, Group.Group)]
getFakeGroups =
- return $ [(defaultGroupID,
- Group.create "default" defaultGroupID AllocPreferred)]
+ return [(defaultGroupID,
+ Group.create "default" defaultGroupID AllocPreferred)]
-- | Construct an instance from a JSON object.
parseInstance :: NameAssoc
else readEitherString (head snodes) >>= lookupNode ktn name)
running <- extract "status" a
tags <- extract "tags" a
- let inst = Instance.create name mem disk vcpus running tags pnode snode
+ auto_balance <- extract "auto_balance" beparams
+ let inst = Instance.create name mem disk vcpus running tags
+ auto_balance pnode snode
return (name, inst)
-- | Construct a node from a JSON object.
-- | Top level function for data loading
loadData :: String -- ^ Cluster or URL to use as source
-> IO (Result ClusterData)
-loadData master = readData master >>= return . parseData
+loadData = fmap parseData . readData