diff --git a/Ganeti/HTools/Rapi.hs b/Ganeti/HTools/Rapi.hs index 88b5fe35c8173d942d776881cd670d6b2ce7c875..aade23a6f0f0b9f696cb070a8c1c621ca8bbc128 100644 --- a/Ganeti/HTools/Rapi.hs +++ b/Ganeti/HTools/Rapi.hs @@ -13,6 +13,7 @@ import Network.Curl.Types () import Network.Curl.Code import Data.Either () import Data.Maybe +import Data.List import Control.Monad import Text.JSON (JSObject, JSValue) import Text.Printf (printf) @@ -28,9 +29,15 @@ getUrl url = do _ -> fail $ printf "Curl error for '%s', error %s" url (show code)) +-- | Append the default port if not passed in +formatHost :: String -> String +formatHost master = + if elem ':' master then master + else "https://" ++ master ++ ":5080" + getInstances :: String -> IO (Result String) getInstances master = do - let url2 = printf "https://%s:5080/2/instances?bulk=1" master + let url2 = printf "%s/2/instances?bulk=1" (formatHost master) body <- getUrl url2 return $ (body >>= \x -> do arr <- loadJSArray x @@ -39,7 +46,7 @@ getInstances master = do getNodes :: String -> IO (Result String) getNodes master = do - let url2 = printf "https://%s:5080/2/nodes?bulk=1" master + let url2 = printf "%s/2/nodes?bulk=1" (formatHost master) body <- getUrl url2 return $ (body >>= \x -> do arr <- loadJSArray x diff --git a/hbal.1 b/hbal.1 index cfa401cf9e684ef3a164a7eea2b47162e164b610..c7a8e794fec7886a246b45aa7163b781d9d54bd8 100644 --- a/hbal.1 +++ b/hbal.1 @@ -287,8 +287,10 @@ how to customize the default value via the environment). .BI "-m" cluster Collect data not from files but directly from the .I cluster -given as an argument via RAPI. This work for both Ganeti 1.2 and -Ganeti 2.0. +given as an argument via RAPI. If the argument doesn't contain a colon +(:), then it is converted into a fully-built URL via prepending +https:// and appending the default RAPI port, otherwise it's +considered a fully-specified URL and is used unchanged. .TP .BI "-l" N ", --max-length=" N diff --git a/hn1.1 b/hn1.1 index e683e2fbb7e504c780f1ddd6e1ecf699a044a791..08621d207024f8e87a8fcedb6b00d32d4f3e7405 100644 --- a/hn1.1 +++ b/hn1.1 @@ -232,8 +232,10 @@ how to customize the default value via the environment). .BI "-m" cluster Collect data not from files but directly from the .I cluster -given as an argument via RAPI. This work for both Ganeti 1.2 and -Ganeti 2.0. +given as an argument via RAPI. If the argument doesn't contain a colon +(:), then it is converted into a fully-built URL via prepending +https:// and appending the default RAPI port, otherwise it's +considered a fully-specified URL and is used unchanged. .TP .BI "-d" DEPTH ", --depth=" DEPTH