Revision c478f837 htools/Ganeti/HTools/Rapi.hs
b/htools/Ganeti/HTools/Rapi.hs | ||
---|---|---|
23 | 23 |
|
24 | 24 |
-} |
25 | 25 |
|
26 |
{-# LANGUAGE BangPatterns #-} |
|
26 |
{-# LANGUAGE BangPatterns, CPP #-}
|
|
27 | 27 |
|
28 | 28 |
module Ganeti.HTools.Rapi |
29 | 29 |
( |
... | ... | |
32 | 32 |
) where |
33 | 33 |
|
34 | 34 |
import Data.Maybe (fromMaybe) |
35 |
#ifndef NO_CURL |
|
35 | 36 |
import Network.Curl |
36 | 37 |
import Network.Curl.Types () |
38 |
#endif |
|
37 | 39 |
import Control.Monad |
38 | 40 |
import Text.JSON (JSObject, JSValue, fromJSObject, decodeStrict) |
39 | 41 |
import Text.JSON.Types (JSValue(..)) |
... | ... | |
46 | 48 |
import qualified Ganeti.HTools.Node as Node |
47 | 49 |
import qualified Ganeti.HTools.Instance as Instance |
48 | 50 |
|
51 |
-- | Read an URL via curl and return the body if successful. |
|
52 |
getUrl :: (Monad m) => String -> IO (m String) |
|
53 |
|
|
54 |
#ifdef NO_CURL |
|
55 |
getUrl _ = return $ fail "RAPI/curl backend disabled at compile time" |
|
56 |
|
|
57 |
#else |
|
58 |
|
|
49 | 59 |
-- | The curl options we use |
50 | 60 |
curlOpts :: [CurlOption] |
51 | 61 |
curlOpts = [ CurlSSLVerifyPeer False |
... | ... | |
54 | 64 |
, CurlConnectTimeout (fromIntegral connTimeout) |
55 | 65 |
] |
56 | 66 |
|
57 |
-- | Read an URL via curl and return the body if successful. |
|
58 |
getUrl :: (Monad m) => String -> IO (m String) |
|
59 | 67 |
getUrl url = do |
60 | 68 |
(code, !body) <- curlGetString url curlOpts |
61 | 69 |
return (case code of |
62 | 70 |
CurlOK -> return body |
63 | 71 |
_ -> fail $ printf "Curl error for '%s', error %s" |
64 | 72 |
url (show code)) |
73 |
#endif |
|
65 | 74 |
|
66 | 75 |
-- | Append the default port if not passed in. |
67 | 76 |
formatHost :: String -> String |
Also available in: Unified diff