Allow overriding the RAPI port/scheme
authorIustin Pop <iustin@google.com>
Wed, 20 May 2009 22:02:45 +0000 (23:02 +0100)
committerIustin Pop <iustin@google.com>
Wed, 20 May 2009 22:24:29 +0000 (23:24 +0100)
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.

Ganeti/HTools/Rapi.hs
hbal.1
hn1.1

index 88b5fe3..aade23a 100644 (file)
@@ -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 cfa401c..c7a8e79 100644 (file)
--- 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 e683e2f..08621d2 100644 (file)
--- 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