Skip to content
Snippets Groups Projects
Commit fd3fe74d authored by Iustin Pop's avatar Iustin Pop
Browse files

RAPI: implement backwards compat with Ganeti 2.3


This is a cheap way to get back compatibility with Ganeti 2.3 (and
lower) in the RAPI backend. It is however not very safe (the /2/groups
resource could fail due to other reasons), so it is added only
temporarily.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent a083e855
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,7 @@ module Ganeti.HTools.Rapi ...@@ -29,6 +29,7 @@ module Ganeti.HTools.Rapi
, parseData , parseData
) where ) where
import Data.Maybe (isJust)
import Network.Curl import Network.Curl
import Network.Curl.Types () import Network.Curl.Types ()
import Control.Monad import Control.Monad
...@@ -80,6 +81,11 @@ getGroups :: String -> Result [(String, Group.Group)] ...@@ -80,6 +81,11 @@ getGroups :: String -> Result [(String, Group.Group)]
getGroups body = loadJSArray "Parsing group data" body >>= getGroups body = loadJSArray "Parsing group data" body >>=
mapM (parseGroup . fromJSObject) mapM (parseGroup . fromJSObject)
getFakeGroups :: Result [(String, Group.Group)]
getFakeGroups =
return $ [(defaultGroupID,
Group.create "default" defaultGroupID AllocPreferred)]
-- | Construct an instance from a JSON object. -- | Construct an instance from a JSON object.
parseInstance :: NameAssoc parseInstance :: NameAssoc
-> [(String, JSValue)] -> [(String, JSValue)]
...@@ -111,7 +117,9 @@ parseNode ktg a = do ...@@ -111,7 +117,9 @@ parseNode ktg a = do
let extract s = tryFromObj ("Node '" ++ name ++ "'") a s let extract s = tryFromObj ("Node '" ++ name ++ "'") a s
offline <- extract "offline" offline <- extract "offline"
drained <- extract "drained" drained <- extract "drained"
guuid <- extract "group.uuid" >>= lookupGroup ktg name guuid <- (if isJust $ lookup "group.uuid" a
then extract "group.uuid"
else return defaultGroupID) >>= lookupGroup ktg name
node <- (if offline || drained node <- (if offline || drained
then return $ Node.create name 0 0 0 0 0 0 True guuid then return $ Node.create name 0 0 0 0 0 0 True guuid
else do else do
...@@ -149,7 +157,12 @@ readData master = do ...@@ -149,7 +157,12 @@ readData master = do
parseData :: (Result String, Result String, Result String, Result String) parseData :: (Result String, Result String, Result String, Result String)
-> Result ClusterData -> Result ClusterData
parseData (group_body, node_body, inst_body, tags_body) = do parseData (group_body, node_body, inst_body, tags_body) = do
group_data <- group_body >>= getGroups group_data <-
-- TODO: handle different ganeti versions properly, not via "all
-- errors mean Ganeti 2.3"
case group_body of
Bad _ -> getFakeGroups
Ok v -> getGroups v
let (group_names, group_idx) = assignIndices group_data let (group_names, group_idx) = assignIndices group_data
node_data <- node_body >>= getNodes group_names node_data <- node_body >>= getNodes group_names
let (node_names, node_idx) = assignIndices node_data let (node_names, node_idx) = assignIndices node_data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment