1 {-| Implementation of the RAPI client interface.
5 module Ganeti.HTools.Rapi
12 import Network.Curl.Types ()
13 import Network.Curl.Code
18 import Text.Printf (printf)
19 import Ganeti.HTools.Utils
24 -- | The fixed drbd overhead per disk (only used with 1.2's sdx_size)
27 getUrl :: String -> IO (Either String String)
29 (code, body) <- curlGetString url [CurlSSLVerifyPeer False,
33 _ -> Left $ printf "Curl error for '%s', error %s"
36 getInstances :: String -> IO (Either String String)
37 getInstances master = do
38 let url2 = printf "https://%s:5080/2/instances?bulk=1" master
40 let inst = body `combineEithers`
41 loadJSArray `combineEithers`
42 (parseEitherList parseInstance)
45 getNodes :: String -> IO (Either String String)
47 let url2 = printf "https://%s:5080/2/nodes?bulk=1" master
49 let inst = body `combineEithers`
50 loadJSArray `combineEithers`
51 (parseEitherList parseNode)
54 parseInstance :: JSObject JSValue -> Either String String
56 let name = getStringElement "name" a
57 disk = case getIntElement "disk_usage" a of
58 Left _ -> let log_sz = applyEither2 (+)
59 (getIntElement "sda_size" a)
60 (getIntElement "sdb_size" a)
61 in applyEither2 (+) log_sz
62 (Right $ drbdOverhead * 2)
64 bep = fromObj "beparams" a
65 pnode = getStringElement "pnode" a
66 snode = (eitherListHead $ getListElement "snodes" a)
67 `combineEithers` readEitherString
69 Left _ -> getIntElement "admin_ram" a
70 Right o -> getIntElement "memory" o
71 running = getStringElement "status" a
73 concatEitherElems name $
74 concatEitherElems (show `applyEither1` mem) $
75 concatEitherElems (show `applyEither1` disk) $
76 concatEitherElems running $
77 concatEitherElems pnode snode
79 boolToYN :: Bool -> Either String String
80 boolToYN True = Right "Y"
81 boolToYN _ = Right "N"
83 parseNode :: JSObject JSValue -> Either String String
85 let name = getStringElement "name" a
86 offline = getBoolElement "offline" a
87 drained = getBoolElement "drained" a
88 mtotal = getIntElement "mtotal" a
89 mnode = getIntElement "mnode" a
90 mfree = getIntElement "mfree" a
91 dtotal = getIntElement "dtotal" a
92 dfree = getIntElement "dfree" a
93 in concatEitherElems name $
95 Right True -> Right "0|0|0|0|0|Y"
97 concatEitherElems (show `applyEither1` mtotal) $
98 concatEitherElems (show `applyEither1` mnode) $
99 concatEitherElems (show `applyEither1` mfree) $
100 concatEitherElems (show `applyEither1` dtotal) $
101 concatEitherElems (show `applyEither1` dfree)
102 ((applyEither2 (||) offline drained) `combineEithers` boolToYN)