Commit e015b554 authored by Iustin Pop's avatar Iustin Pop
Browse files

Allow overriding the RAPI port/scheme

This patch adds a very dumb way to override the port and scheme for
RAPI: if the master string doesn't contain a colon, we consider it a
simple hostname specification, and thus prepend ‘https://’ and append
‘:5080’, (the default RAPI port); otherwise, we consider it a fully
specified URL, and don't do any mangling to it.

This allows to use saved RAPI responses in testing, with the “file://”
scheme, or to use another port or non https mode with an actual RAPI
instance.
parent ba00ad4d
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment