Load exclusive_storage in htools
authorBernardo Dal Seno <bdalseno@google.com>
Sun, 26 May 2013 19:23:18 +0000 (21:23 +0200)
committerBernardo Dal Seno <bdalseno@google.com>
Mon, 3 Jun 2013 13:15:19 +0000 (15:15 +0200)
The node parameter is loaded into the data structures. No behavior is yet
modified.

Signed-off-by: Bernardo Dal Seno <bdalseno@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

16 files changed:
src/Ganeti/HTools/Backend/IAlloc.hs
src/Ganeti/HTools/Backend/Luxi.hs
src/Ganeti/HTools/Backend/Rapi.hs
src/Ganeti/HTools/Backend/Simu.hs
src/Ganeti/HTools/Backend/Text.hs
src/Ganeti/HTools/Node.hs
test/data/htools/hail-alloc-drbd.json
test/data/htools/hail-alloc-invalid-network.json
test/data/htools/hail-alloc-invalid-twodisks.json
test/data/htools/hail-alloc-restricted-network.json
test/data/htools/hail-alloc-twodisks.json
test/data/htools/hail-change-group.json
test/data/htools/hail-node-evac.json
test/data/htools/hail-reloc-drbd.json
test/data/htools/rapi/nodes.json
test/hs/Test/Ganeti/HTools/Node.hs

index 22dad86..4e7493b 100644 (file)
@@ -131,7 +131,7 @@ parseNode ktg n a = do
   let vm_capable' = fromMaybe True vm_capable
   gidx <- lookupGroup ktg n guuid
   node <- if offline || drained || not vm_capable'
-            then return $ Node.create n 0 0 0 0 0 0 True 0 gidx
+            then return $ Node.create n 0 0 0 0 0 0 True 0 gidx False
             else do
               mtotal <- extract "total_memory"
               mnode  <- extract "reserved_memory"
@@ -142,8 +142,10 @@ parseNode ktg n a = do
               ndparams <- extract "ndparams" >>= asJSObject
               spindles <- tryFromObj desc (fromJSObject ndparams)
                           "spindle_count"
+              excl_stor <- tryFromObj desc (fromJSObject ndparams)
+                           "exclusive_storage"
               return $ Node.create n mtotal mnode mfree
-                     dtotal dfree ctotal False spindles gidx
+                     dtotal dfree ctotal False spindles gidx excl_stor
   return (n, node)
 
 -- | Parses a group as found in the cluster group list.
index d8d9dcb..fea6dc9 100644 (file)
@@ -104,7 +104,8 @@ queryNodesMsg =
   L.Query (Qlang.ItemTypeOpCode Qlang.QRNode)
      ["name", "mtotal", "mnode", "mfree", "dtotal", "dfree",
       "ctotal", "offline", "drained", "vm_capable",
-      "ndp/spindle_count", "group.uuid", "tags"] Qlang.EmptyFilter
+      "ndp/spindle_count", "group.uuid", "tags",
+      "ndp/exclusive_storage"] Qlang.EmptyFilter
 
 -- | The input data for instance query.
 queryInstancesMsg :: L.LuxiOp
@@ -185,8 +186,8 @@ getNodes ktg arr = extractArray arr >>= mapM (parseNode ktg)
 -- | Construct a node from a JSON object.
 parseNode :: NameAssoc -> [(JSValue, JSValue)] -> Result (String, Node.Node)
 parseNode ktg [ name, mtotal, mnode, mfree, dtotal, dfree
-              , ctotal, offline, drained, vm_capable, spindles, g_uuid 
-              , tags ]
+              , ctotal, offline, drained, vm_capable, spindles, g_uuid
+              , tags, excl_stor ]
     = do
   xname <- annotateResult "Parsing new node" (fromJValWithStatus name)
   let convert a = genericConvert "Node" xname a
@@ -196,8 +197,10 @@ parseNode ktg [ name, mtotal, mnode, mfree, dtotal, dfree
   xspindles <- convert "spindles" spindles
   xgdx   <- convert "group.uuid" g_uuid >>= lookupGroup ktg xname
   xtags <- convert "tags" tags
+  xexcl_stor <- convert "exclusive_storage" excl_stor
   node <- if xoffline || xdrained || not xvm_capable
-            then return $ Node.create xname 0 0 0 0 0 0 True xspindles xgdx
+            then return $
+              Node.create xname 0 0 0 0 0 0 True xspindles xgdx False
             else do
               xmtotal  <- convert "mtotal" mtotal
               xmnode   <- convert "mnode" mnode
@@ -207,7 +210,7 @@ parseNode ktg [ name, mtotal, mnode, mfree, dtotal, dfree
               xctotal  <- convert "ctotal" ctotal
               return . flip Node.setNodeTags xtags $
                 Node.create xname xmtotal xmnode xmfree xdtotal xdfree
-                            xctotal False xspindles xgdx
+                            xctotal False xspindles xgdx xexcl_stor
   return (xname, node)
 
 parseNode _ v = fail ("Invalid node query result: " ++ show v)
index f7f0bb0..58cc845 100644 (file)
@@ -155,10 +155,11 @@ parseNode ktg a = do
   let vm_cap' = fromMaybe True vm_cap
   ndparams <- extract "ndparams" >>= asJSObject
   spindles <- tryFromObj desc (fromJSObject ndparams) "spindle_count"
+  excl_stor <- tryFromObj desc (fromJSObject ndparams) "exclusive_storage"
   guuid   <- annotateResult desc $ maybeFromObj a "group.uuid"
   guuid' <-  lookupGroup ktg name (fromMaybe defaultGroupID guuid)
   node <- if offline || drained || not vm_cap'
-            then return $ Node.create name 0 0 0 0 0 0 True 0 guuid'
+            then return $ Node.create name 0 0 0 0 0 0 True 0 guuid' False
             else do
               mtotal  <- extract "mtotal"
               mnode   <- extract "mnode"
@@ -169,7 +170,7 @@ parseNode ktg a = do
               tags    <- extract "tags"
               return . flip Node.setNodeTags tags $
                 Node.create name mtotal mnode mfree dtotal dfree ctotal False
-                            spindles guuid'
+                            spindles guuid' excl_stor
   return (name, node)
 
 -- | Construct a group from a JSON object.
index a9b31d4..1c6c041 100644 (file)
@@ -6,7 +6,7 @@ This module holds the code for parsing a cluster description.
 
 {-
 
-Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
+Copyright (C) 2009, 2010, 2011, 2012, 2013 Google Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -51,18 +51,21 @@ apolAbbrev c | c == "p"  = return AllocPreferred
 
 -- | Parse the string description into nodes.
 parseDesc :: String -> [String]
-          -> Result (AllocPolicy, Int, Int, Int, Int, Int)
-parseDesc _ [a, n, d, m, c, s] = do
+          -> Result (AllocPolicy, Int, Int, Int, Int, Int, Bool)
+parseDesc _ [a, n, d, m, c, s, exstor] = do
   apol <- allocPolicyFromRaw a `mplus` apolAbbrev a
   ncount <- tryRead "node count" n
   disk <- annotateResult "disk size" (parseUnit d)
   mem <- annotateResult "memory size" (parseUnit m)
   cpu <- tryRead "cpu count" c
   spindles <- tryRead "spindles" s
-  return (apol, ncount, disk, mem, cpu, spindles)
+  excl_stor <- tryRead "exclusive storage" exstor
+  return (apol, ncount, disk, mem, cpu, spindles, excl_stor)
 
 parseDesc desc [a, n, d, m, c] = parseDesc desc [a, n, d, m, c, "1"]
 
+parseDesc desc [a, n, d, m, c, s] = parseDesc desc [a, n, d, m, c, s, "False"]
+
 parseDesc desc es =
   fail $ printf
          "Invalid cluster specification, expected 6 comma-separated\
@@ -75,14 +78,14 @@ createGroup :: Int    -- ^ The group index
             -> String -- ^ The group specification
             -> Result (Group.Group, [Node.Node])
 createGroup grpIndex spec = do
-  (apol, ncount, disk, mem, cpu, spindles) <- parseDesc spec $
-                                              sepSplit ',' spec
+  (apol, ncount, disk, mem, cpu, spindles, excl_stor) <- parseDesc spec $
+                                                         sepSplit ',' spec
   let nodes = map (\idx ->
                     flip Node.setMaster (grpIndex == 1 && idx == 1) $
                     Node.create (printf "node-%02d-%03d" grpIndex idx)
                       (fromIntegral mem) 0 mem
                       (fromIntegral disk) disk
-                      (fromIntegral cpu) False spindles grpIndex
+                      (fromIntegral cpu) False spindles grpIndex excl_stor
                   ) [1..ncount]
       -- TODO: parse networks to which this group is connected
       grp = Group.create (printf "group-%02d" grpIndex)
index f3a2c2e..0d3991a 100644 (file)
@@ -84,7 +84,7 @@ serializeNode :: Group.List -- ^ The list of groups (needed for group uuid)
               -> Node.Node  -- ^ The node to be serialised
               -> String
 serializeNode gl node =
-  printf "%s|%.0f|%d|%d|%.0f|%d|%.0f|%c|%s|%d|%s" (Node.name node)
+  printf "%s|%.0f|%d|%d|%.0f|%d|%.0f|%c|%s|%d|%s|%s" (Node.name node)
            (Node.tMem node) (Node.nMem node) (Node.fMem node)
            (Node.tDsk node) (Node.fDsk node) (Node.tCpu node)
            (if Node.offline node then 'Y' else
@@ -92,6 +92,7 @@ serializeNode gl node =
            (Group.uuid grp)
            (Node.spindleCount node)
            (intercalate "," (Node.nTags node))
+           (if Node.exclStorage node then "Y" else "N")
     where grp = Container.find (Node.group node) gl
 
 -- | Generate node file data from node objects.
@@ -199,11 +200,12 @@ loadNode :: (Monad m) =>
          -> [String]              -- ^ Input data as a list of fields
          -> m (String, Node.Node) -- ^ The result, a tuple o node name
                                   -- and node object
-loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles, tags] = do
+loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles, tags,
+              excl_stor] = do
   gdx <- lookupGroup ktg name gu
   new_node <-
       if "?" `elem` [tm,nm,fm,td,fd,tc] || fo == "Y" then
-          return $ Node.create name 0 0 0 0 0 0 True 0 gdx
+          return $ Node.create name 0 0 0 0 0 0 True 0 gdx False
       else do
         let vtags = commaSplit tags
         vtm <- tryRead name tm
@@ -213,8 +215,15 @@ loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles, tags] = do
         vfd <- tryRead name fd
         vtc <- tryRead name tc
         vspindles <- tryRead name spindles
+        vexcl_stor <- case excl_stor of
+                        "Y" -> return True
+                        "N" -> return False
+                        _ -> fail $
+                             "Invalid exclusive_storage value for node '" ++
+                             name ++ "': " ++ excl_stor
         return . flip Node.setMaster (fo == "M") . flip Node.setNodeTags vtags $
           Node.create name vtm vnm vfm vtd vfd vtc False vspindles gdx
+          vexcl_stor
   return (name, new_node)
 
 loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu] =
@@ -223,6 +232,9 @@ loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu] =
 loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles] =
   loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles, ""]
 
+loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles, tags] =
+  loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles, tags, "N"]
+
 loadNode _ s = fail $ "Invalid/incomplete node data: '" ++ show s ++ "'"
 
 -- | Load an instance from a field list.
index 03ec3bb..0e96f19 100644 (file)
@@ -141,6 +141,7 @@ data Node = Node
   , pTags    :: TagMap    -- ^ Primary instance exclusion tags and their count
   , group    :: T.Gdx     -- ^ The node's group (index)
   , iPolicy  :: T.IPolicy -- ^ The instance policy (of the node's group)
+  , exclStorage :: Bool   -- ^ Effective value of exclusive_storage
   } deriving (Show, Eq)
 
 instance T.Element Node where
@@ -216,10 +217,10 @@ decIf False base _     = base
 -- The index and the peers maps are empty, and will be need to be
 -- update later via the 'setIdx' and 'buildPeers' functions.
 create :: String -> Double -> Int -> Int -> Double
-       -> Int -> Double -> Bool -> Int -> T.Gdx -> Node
+       -> Int -> Double -> Bool -> Int -> T.Gdx -> Bool -> Node
 create name_init mem_t_init mem_n_init mem_f_init
        dsk_t_init dsk_f_init cpu_t_init offline_init spindles_init
-       group_init =
+       group_init excl_stor =
   Node { name = name_init
        , alias = name_init
        , tMem = mem_t_init
@@ -255,6 +256,7 @@ create name_init mem_t_init mem_n_init mem_f_init
        , pTags = Map.empty
        , group = group_init
        , iPolicy = T.defIPolicy
+       , exclStorage = excl_stor
        }
 
 -- | Conversion formula from mDsk\/tDsk to loDsk.
index 868933e..e9e395b 100644 (file)
       "free_memory": 31389,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
       "free_memory": 31746,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
       "free_memory": 31234,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
       "free_memory": 22914,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
index 72d5cbb..a75a42d 100644 (file)
       "free_memory": 4096,
       "group": "uuid-group-1",
       "ndparams": {
-        "spindle_count": 1
+        "spindle_count": 1,
+        "exclusive_storage": false
       },
       "offline": false,
       "reserved_memory": 1017,
       "free_memory": 4096,
       "group": "uuid-group-2",
       "ndparams": {
-        "spindle_count": 1
+        "spindle_count": 1,
+        "exclusive_storage": false
       },
       "offline": false,
       "reserved_memory": 1017,
index 4a15e64..722a082 100644 (file)
@@ -59,7 +59,8 @@
       "free_memory": 31389,
       "group": "uuid-group-1",
       "ndparams": {
-        "spindle_count": 1
+        "spindle_count": 1,
+        "exclusive_storage": false
       },
       "offline": false,
       "reserved_memory": 1017,
index 988d0fc..54d3a53 100644 (file)
       "free_memory": 3840,
       "group": "uuid-group-1",
       "ndparams": {
-        "spindle_count": 1
+        "spindle_count": 1,
+        "exclusive_storage": false
       },
       "offline": false,
       "reserved_memory": 1017,
       "free_memory": 3968,
       "group": "uuid-group-1",
       "ndparams": {
-        "spindle_count": 1
+        "spindle_count": 1,
+        "exclusive_storage": false
       },
       "offline": false,
       "reserved_memory": 1017,
       "free_memory": 4096,
       "group": "uuid-group-2",
       "ndparams": {
-        "spindle_count": 1
+        "spindle_count": 1,
+        "exclusive_storage": false
       },
       "offline": false,
       "reserved_memory": 1017,
       "free_memory": 4096,
       "group": "uuid-group-2",
       "ndparams": {
-        "spindle_count": 1
+        "spindle_count": 1,
+        "exclusive_storage": false
       },
       "offline": false,
       "reserved_memory": 1017,
index 5e9e196..1f23e88 100644 (file)
@@ -59,7 +59,8 @@
       "free_memory": 31389,
       "group": "uuid-group-1",
       "ndparams": {
-        "spindle_count": 1
+        "spindle_count": 1,
+        "exclusive_storage": false
       },
       "offline": false,
       "reserved_memory": 1017,
index 84aa631..478302a 100644 (file)
       "free_memory": 31389,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
       "free_memory": 31234,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
       "free_memory": 22914,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
       "free_memory": 31746,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
       "free_memory": 31746,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
index 31c7928..5c9de73 100644 (file)
       "free_memory": 31389,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
       "free_memory": 31746,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
       "free_memory": 31234,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
       "free_memory": 22914,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
index b745660..1a2ad7f 100644 (file)
       "free_memory": 31389,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
       "free_memory": 31746,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
       "free_memory": 31234,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
       "free_memory": 22914,
       "ndparams": {
         "spindle_count": 1,
-        "oob_program": null
+        "oob_program": null,
+        "exclusive_storage": false
       },
       "reserved_memory": 1017,
       "master_capable": true,
index c788728..c8d1733 100644 (file)
@@ -29,7 +29,8 @@
     "vm_capable": true,
     "ndparams": {
       "spindle_count": 1,
-      "oob_program": null
+      "oob_program": null,
+      "exclusive_storage": false
     }
   },
   {
@@ -62,7 +63,8 @@
     "vm_capable": true,
     "ndparams": {
       "spindle_count": 1,
-      "oob_program": null
+      "oob_program": null,
+      "exclusive_storage": false
     }
   },
   {
     ],
     "ndparams": {
       "spindle_count": 1,
-      "oob_program": null
+      "oob_program": null,
+      "exclusive_storage": false
     }
   },
   {
     ],
     "ndparams": {
       "spindle_count": 1,
-      "oob_program": null
+      "oob_program": null,
+      "exclusive_storage": false
     }
   }
 ]
index ec69da3..e2a9c17 100644 (file)
@@ -7,7 +7,7 @@
 
 {-
 
-Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
+Copyright (C) 2009, 2010, 2011, 2012, 2013 Google Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -90,7 +90,7 @@ genNode min_multiplier max_multiplier = do
   cpu_t <- choose (base_cpu, top_cpu)
   offl  <- arbitrary
   let n = Node.create name (fromIntegral mem_t) mem_n mem_f
-          (fromIntegral dsk_t) dsk_f (fromIntegral cpu_t) offl 1 0
+          (fromIntegral dsk_t) dsk_f (fromIntegral cpu_t) offl 1 0 False
       n' = Node.setPolicy nullIPolicy n
   return $ Node.buildPeers n' Container.empty