commit c22d4dd497802903c1d562c66c19a4a6908eb5f2
Author: Iustin Pop <iustin@google.com>
Date:   Fri Jan 27 17:21:24 2012 +0100

    Add spindle ratio to htool's IPolicy
    
    Just the usual data/type declarations, read/save in the text backend,
    etc. Also does a bit of unit-test cleanup (the way we build
    ipolicies).
    
    Signed-off-by: Iustin Pop <iustin@google.com>
    Reviewed-by: René Nussbaumer <rn@google.com>

diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs
index bdc430d..b41f1db 100644
--- a/htools/Ganeti/HTools/QC.hs
+++ b/htools/Ganeti/HTools/QC.hs
@@ -97,6 +97,14 @@ maxDsk = 1024 * 1024 * 8
 maxCpu :: Int
 maxCpu = 1024
 
+-- | Max vcpu ratio (random value).
+maxVcpuRatio :: Double
+maxVcpuRatio = 1024.0
+
+-- | Max spindle ratio (random value).
+maxSpindleRatio :: Double
+maxSpindleRatio = 1024.0
+
 -- | All disk templates (used later)
 allDiskTemplates :: [Types.DiskTemplate]
 allDiskTemplates = [minBound..maxBound]
@@ -122,8 +130,9 @@ nullIPolicy = Types.IPolicy
                                        , Types.iSpecNicCount   = 1
                                        }
   , Types.iPolicyDiskTemplates = [Types.DTDrbd8, Types.DTPlain]
-  , Types.iPolicyVcpuRatio = 1024 -- somewhat random value, high
-                                  -- enough to not impact us
+  , Types.iPolicyVcpuRatio = maxVcpuRatio -- somewhat random value, high
+                                          -- enough to not impact us
+  , Types.iPolicySpindleRatio = maxSpindleRatio
   }
 
 
@@ -441,12 +450,14 @@ instance Arbitrary Types.IPolicy where
     imax <- genBiggerISpec istd
     num_tmpl <- choose (0, length allDiskTemplates)
     dts  <- genUniquesList num_tmpl
-    vcpu_ratio <- arbitrary
+    vcpu_ratio <- choose (1.0, maxVcpuRatio)
+    spindle_ratio <- choose (1.0, maxSpindleRatio)
     return Types.IPolicy { Types.iPolicyMinSpec = imin
                          , Types.iPolicyStdSpec = istd
                          , Types.iPolicyMaxSpec = imax
                          , Types.iPolicyDiskTemplates = dts
                          , Types.iPolicyVcpuRatio = vcpu_ratio
+                         , Types.iPolicySpindleRatio = spindle_ratio
                          }
 
 -- * Actual tests
diff --git a/htools/Ganeti/HTools/Text.hs b/htools/Ganeti/HTools/Text.hs
index 3334d20..6aeb44a 100644
--- a/htools/Ganeti/HTools/Text.hs
+++ b/htools/Ganeti/HTools/Text.hs
@@ -128,13 +128,14 @@ serializeDiskTemplates = intercalate "," . map diskTemplateToRaw
 -- | Generate policy data from a given policy object.
 serializeIPolicy :: String -> IPolicy -> String
 serializeIPolicy owner ipol =
-  let IPolicy stdspec minspec maxspec dts vcpu_ratio = ipol
+  let IPolicy stdspec minspec maxspec dts vcpu_ratio spindle_ratio = ipol
       strings = [ owner
                 , serializeISpec stdspec
                 , serializeISpec minspec
                 , serializeISpec maxspec
                 , serializeDiskTemplates dts
                 , show vcpu_ratio
+                , show spindle_ratio
                 ]
   in intercalate "|" strings
 
@@ -236,13 +237,16 @@ loadISpec owner s = fail $ "Invalid ispec data for " ++ owner ++ ": " ++ show s
 
 -- | Loads an ipolicy from a field list.
 loadIPolicy :: [String] -> Result (String, IPolicy)
-loadIPolicy [owner, stdspec, minspec, maxspec, dtemplates, vcpu_ratio] = do
+loadIPolicy [owner, stdspec, minspec, maxspec, dtemplates,
+             vcpu_ratio, spindle_ratio] = do
   xstdspec <- loadISpec (owner ++ "/stdspec") (commaSplit stdspec)
   xminspec <- loadISpec (owner ++ "/minspec") (commaSplit minspec)
   xmaxspec <- loadISpec (owner ++ "/maxspec") (commaSplit maxspec)
   xdts <- mapM diskTemplateFromRaw $ commaSplit dtemplates
   xvcpu_ratio <- tryRead (owner ++ "/vcpu_ratio") vcpu_ratio
-  return $ (owner, IPolicy xstdspec xminspec xmaxspec xdts xvcpu_ratio)
+  xspindle_ratio <- tryRead (owner ++ "/spindle_ratio") spindle_ratio
+  return $ (owner, IPolicy xstdspec xminspec xmaxspec xdts
+            xvcpu_ratio xspindle_ratio)
 loadIPolicy s = fail $ "Invalid ipolicy data: '" ++ show s ++ "'"
 
 loadOnePolicy :: (IPolicy, Group.List) -> String
diff --git a/htools/Ganeti/HTools/Types.hs b/htools/Ganeti/HTools/Types.hs
index 9bd6ca3..216b011 100644
--- a/htools/Ganeti/HTools/Types.hs
+++ b/htools/Ganeti/HTools/Types.hs
@@ -217,6 +217,8 @@ $(THH.buildObject "IPolicy" "iPolicy"
       THH.simpleField C.ipolicyDts [t| [DiskTemplate] |]
   , THH.renameField "VcpuRatio" $
       THH.simpleField C.ipolicyVcpuRatio [t| Double |]
+  , THH.renameField "SpindleRatio" $
+      THH.simpleField C.ipolicySpindleRatio [t| Double |]
   ])
 
 -- | Converts an ISpec type to a RSpec one.
@@ -236,6 +238,7 @@ defIPolicy = IPolicy { iPolicyStdSpec = defStdISpec
                      -- htools, we are mostly looking at DRBD
                      , iPolicyDiskTemplates = [DTDrbd8, DTPlain]
                      , iPolicyVcpuRatio = C.ipolicyDefaultsVcpuRatio
+                     , iPolicySpindleRatio = C.ipolicyDefaultsSpindleRatio
                      }
 
 -- | The dynamic resource specs of a machine (i.e. load or load
