Revision e015b554 Ganeti/HTools/Rapi.hs

b/Ganeti/HTools/Rapi.hs
13 13
import Network.Curl.Code
14 14
import Data.Either ()
15 15
import Data.Maybe
16
import Data.List
16 17
import Control.Monad
17 18
import Text.JSON (JSObject, JSValue)
18 19
import Text.Printf (printf)
......
28 29
            _ -> fail $ printf "Curl error for '%s', error %s"
29 30
                 url (show code))
30 31

  
32
-- | Append the default port if not passed in
33
formatHost :: String -> String
34
formatHost master =
35
    if elem ':' master then  master
36
    else "https://" ++ master ++ ":5080"
37

  
31 38
getInstances :: String -> IO (Result String)
32 39
getInstances master = do
33
  let url2 = printf "https://%s:5080/2/instances?bulk=1" master
40
  let url2 = printf "%s/2/instances?bulk=1" (formatHost master)
34 41
  body <- getUrl url2
35 42
  return $ (body >>= \x -> do
36 43
              arr <- loadJSArray x
......
39 46

  
40 47
getNodes :: String -> IO (Result String)
41 48
getNodes master = do
42
  let url2 = printf "https://%s:5080/2/nodes?bulk=1" master
49
  let url2 = printf "%s/2/nodes?bulk=1" (formatHost master)
43 50
  body <- getUrl url2
44 51
  return $ (body >>= \x -> do
45 52
             arr <- loadJSArray x

Also available in: Unified diff